Toribash
Original Post
Get your Lua questions answered here!
Stuck on a piece of code that won't work no matter how you try to run it?

Post the relevant bits here and me (and any other person that knows the answer) will try and help you.

Also include what you're trying to do with the script. We may know Lua, but we're not mind-readers.
I tried to modify the dismember script, to show the name of the joint you have dismembered/fractured, and whether you have dismembered/fractured it.
It worked up until i added IF/THEN/ELSE and "ctype" things, before it always said the joint with dismembered or fractured by it depending on what you clicked.

(note: this is my first attempt at lua so be kind please :] )

 
-- dm.lua

function set_joint(player, joint)
	if (joint ~= -1) then
		cjointinfo = get_joint_info(player, joint)
		cjoint = joint
		cplayer = player
	end
end

function keydown(key)
	if ((key == string.byte("q")) and ((cplayer ~= -1) and (cjoint ~= -1))) then
	dismember_joint(cplayer,cjoint)
	ctype = "dismember"
	elseif ((key == string.byte("o")) and ((cplayer ~= -1) and (cjoint ~= -1))) then
	fracture_joint(cplayer,cjoint)
	ctype = "fracture"
	end
end

function keyup()
	ctype = ""
end

cplayer = -1
cjoint = -1

local function draw_centered_text_example()
      if ((ctype == "fracture")) then
	set_color(0, 0, 1, 1)
      draw_centered_text(cjointinfo.name.. "  " ..ctype, 100, 2)
	elseif ((ctype == "dismember"}} then
	set_color(1, 0, 0, 1)
      draw_centered_text(cjointinfo.name.. "  " ..ctype, 100, 2)
	elseif ((ctype == "")) then
	set_color(0, 0, 0, 1)
      draw_centered_text(cjointinfo.name, 100, 2)
	end
end

add_hook("draw2d", "draw_centered_text_example", draw_centered_text_example)
add_hook("joint_select", "dm", set_joint)
add_hook("key_down", "dm", keydown)
add_hook("key_up", "dm", keydup)
Now it doesn't do anything. Help please :].
Originally Posted by Blam View Post
elseif ((ctype == "dismember"}} then

Supposed to be:

elseif ((ctype == "dismember")) then
Squad Squad Squad lead?
The standardization of Toribash Squad roles may have gone too far!
ack, i can't believe i missed that, thanks. =]

But now ctype doesnt want to go back to "" when the key is released :[
Last edited by Blam; Aug 5, 2007 at 08:34 PM.
Originally Posted by Blam View Post
function keyup()
...
add_hook("key_up", "dm", keydup)

Perhaps this is the problem...
Squad Squad Squad lead?
The standardization of Toribash Squad roles may have gone too far!
god damn typos.

Thanks again.
I got to check my scripts more carefully.
Last edited by Blam; Aug 5, 2007 at 11:44 PM.
:D
Damn, i dont think i have the time to look this up, but where do you save teh .lua scripts to play them
?
collect snots from the nose
DRIVE NAME (usually C)\Program Files\Toribash 2.75 (or other version)\data\scripts\My script.lua
^for windows^

thats all i know about lua scriptin! =D
How do you draw lines?

Also, when you draw text, it takes the colour of any other text made (for example if you echo something it will go red). Any way to change this?
There's no simple way of drawing lines at the moment, so far as I know. You can write a line algorithm yourself with some periods or rectangles if you really need them.

You can set the text color explicitly prior to drawing it. Use set_color(<red>, <green>, <blue>, <alpha>). All values between 0 and 1.
Radioactive torso's description should be, "You have cancer like wow."