Ranking
Originally Posted by Blam View Post
.rot was new fixed 3.1, so it hasn't been added yet.
And set_body_rotation as you said probably is planned for the near future.

Thanks for clarifying this.

Originally Posted by Dafe View Post
.rot has actually been around since 2.7 or so, but it was broken between something like 3.04 and 3.06, but it's back to its old behavior.

It currently returns a rotation matrix with named fields r0, r1, r2 ... r15.

Here's some code from an API I'm developing that uses it. Maybe this will help.

http://toribash.mydistraction.net/sphericalRegion.lua
http://toribash.mydistraction.net/ukeFaceLaser.lua

Thanks for supplying this. This will be very useful to me.
Fixed. Thanks suo.
Last edited by Blam; Feb 9, 2008 at 06:24 PM.
:D
Your hooks are fucked up. Simple simple.
Squad Squad Squad lead?
The standardization of Toribash Squad roles may have gone too far!
--FForms
local FForms = { }
local NFForms = 0

function NewForm(x,y,w,h,title,text, id)
    --Setup Variables for future reference
    echo("Debug: Test ".. x .. y .. w .. h .. title .. text .. id)
    FForms[id].x = x
    FForms[id].y = y
    FForms[id].title = title
    FForms[id].text = text
    FForms[id].w = w
    FForms[id].h = h
    echo("Debug: Test")
end

local function drawFForms()
    for i=0,table.getn(FForms) do
    --echo("Drawing Form!")
    --Draw Body
        set_color(1,1,1,0.5)
        draw_quad(FForms[i].x,FForms[i].y,FForms[i].w,FForms[i].h)
        echo("Drew Body!")
    --Draw Title Area
        set_color(0,0,1,0.3)
        draw_quad(FForms[i].x,FForms[i].y,FForms[i].w,30)
        echo("Drew Title Area!")
    --Draw Title
        set_color(0,0,0,0.3)
        draw_text(FForms[i].title, FForms[i].x+7, FForms[i].y+2, 2)
        set_color(1,1,1,1)
        draw_text(FForms[i].title, FForms[i].x+5, FForms[i].y, 2)
        echo("Drew Title!")
    --Draw Text
        set_color(0,0,0,1)
        draw_text(FForms[i].text, FForms[i].x+5, FForms[i].y + 35, 1)
        echo("Drew Text!")
    end
end

local function keypress(key)
    if(key == 105) then
    echo("Making Form: 30,30,100,100")
    --NFForms = table.getn(FForms)
    NewForm(30,30,100,100,"Title","Text goes here!", NFForms+1)
    echo("New Form, ID = " .. NFForms+1)
    elseif(key == 111) then
    echo("Making Form: 400,400,100,100")
    NFForms = table.getn(FForms)
    NewForm(400,400,100,100,"Title2","Text goes here!!! UNCE", NFForms+1)
    echo("New Form, ID = " .. NFForms+1)
    end
end

add_hook("draw2d","FForms", drawFForms)
add_hook("key_down","FForms", keypress)
After pressing O or I it doesnt seem to want to get past the second "echo("Debug: Test)" i put in there... It echos the first one btw. Halp?
:D
--FForms
FForms = {x = 0, y = 0, title = 0, text = "", w = 0, h = 0 }
NFForms = 1

function NewForm(x,y,w,h,title,text,id)
    --Setup Variables for future reference
    echo("Debug: Test ".. x .. y .. w .. h .. title .. text .. "|" .. id)
    FForms[id] = {x = 0, y = 0, title = 0, text = "", w = 0, h = 0 }
	FForms[id].x = x
    FForms[id].y = y
    FForms[id].title = title
    FForms[id].text = text
    FForms[id].w = w
    FForms[id].h = h
    echo("Debug: Test")
end

local function drawFForms()
    for i=1,#FForms do
    echo("Drawing Form! " .. i)
    --Draw Body
        set_color(1,1,1,0.5)
        draw_quad(FForms[i].x,FForms[i].y,FForms[i].w,FForms[i].h)
        echo("Drew Body!")
    --Draw Title Area
        set_color(0,0,1,0.3)
        draw_quad(FForms[i].x,FForms[i].y,FForms[i].w,30)
        echo("Drew Title Area!")
    --Draw Title
        set_color(0,0,0,0.3)
        draw_text(FForms[i].title, FForms[i].x+7, FForms[i].y+2, 2)
        set_color(1,1,1,1)
        draw_text(FForms[i].title, FForms[i].x+5, FForms[i].y, 2)
        echo("Drew Title!")
    --Draw Text
        set_color(0,0,0,1)
        draw_text(FForms[i].text, FForms[i].x+5, FForms[i].y + 35, 1)
        echo("Drew Text!")
    end
end

local function keypress(key)
    if(key == 105) then
		echo("Making Form: 30,30,100,100")
		NFForms = #FForms + 1
		NewForm(30,30,100,100,"Title","Text goes here!", NFForms)
		echo("New Form, ID = " .. NFForms)
    end
	if(key == 111) then
		echo("Making Form: 400,400,100,100")
		NFForms = #FForms + 1
		NewForm(400,400,100,100,"Title2","Text goes here!!! UNCE", NFForms)
		echo("New Form, ID = " .. NFForms)
    end
end

add_hook("draw2d","FForms", drawFForms)
add_hook("key_down","FForms", keypress)
There was 2 newbluck errors and one newbluck warning.

Error 1: You need to declare the contents of the indexed table before you try to access members of that table element. Look at line 8; what I added there takes care of that issue.

Error 2: I'm pretty sure table indecies start at 1, so I fixed that issue in a few places.

Warning 1: table.getn(table table) is a depreciated function. The new method to get the number of items in a table is #[table_name]. It returns an int with the number of indecies, just like table.getn.
Last edited by NewbLuck; Feb 9, 2008 at 08:43 PM.
 ____  _____  __  __  _  _  ___  _  _ 
(  _ \(  _  )(  )(  )( \( )/ __)( \/ )
 ) _ < )(_)(  )(__)(  )  (( (__  \  / 
(____/(_____)(______)(_)\_)\___) (__) 
1. What are hooks?
2. What are all of the blood realated hooks/commands, and what are the syntax for them?
to see all the hooks open up startup.lua.
(list if your lazy)
"new_game",
"new_mp_game",
"enter_frame",
"end_game",
"leave_game",
"enter_freeze",
"exit_freeze",
"key_up",
"key_down",
"mouse_button_up",
"mouse_button_down",
"mouse_move",
"player_select",
"joint_select",
"draw2d",
"draw3d",
"play",
"camera"


anyway HALP.
Look at the bold section (_draw_buttons)
It gets to the echo(#Buttons) but doesnt go further... why?
dofile("Forms.lua")

BID = 0
Buttons = {x = 0, y = 0, w = 0, h = 0, label = "", formid = 0, bid = 0}

function hit_test(hitx,hity,x,y,w,h)
    X1 = x
    X2 = x+w
    Y1 = y
    Y2 = y+h
    if(hitx > X1 and hitx < X2) and (hity > Y1 and hity < Y2) then
        return 1
    else
        return 0
    end
end

function new_button(x,y,w,h,label,formid)
    BID = BID + 1
    Buttons[BID] = {x = 0, y = 0, w = 0, h = 0, label = "", formid = 0}
    Buttons[BID].x = x
    Buttons[BID].y = y
    Buttons[BID].w = w
    Buttons[BID].h = h
    Buttons[BID].label = label
    Buttons[BID].formid = formid
    Buttons[BID].bid = BID
    echo("Button ID:" .. BID)
    echo(Buttons[BID].x .. Buttons[BID].y .. Buttons[BID].w .. Buttons[BID].h .. Buttons[BID].label .. Buttons[BID].formid .. Buttons[BID].bid)
end

function setup()
    new_form(100,100,230,500,"Test Box 1","",1) -- ID = 1
    new_form(0,0,300,500,"Help","",0) -- ID = 2
    new_button(20,20,40,20,"Test",1)
    new_button(20,20,50,20,"Test 2",2)
end

setup()

[i]local function _drawbuttons()
    echo(#Buttons)
    for i=1,#Buttons do
    echo(FForms[Buttons[i].formid].show == 1)
        if(FForms[Buttons[i].formid].show == 1) then
        --Draw Body
        set_color(0.3,1,1,1)
        draw_quad(Buttons[i].x+FForms[Buttons[i]].x-2,FForms[Buttons[i]].y+Buttons[i].y-2,Buttons[i].w, Buttons[i].h)
        --Draw Bevel Shadow
        set_color(0,0,0,0.1)
        draw_quad(Buttons[i].x+FForms[Buttons[i]].x+2,FForms[Buttons[i]].y+Buttons[i].y+2,Buttons[i].w-2,Buttons[i].h-2)
        --Draw Bevel Highlight
        set_color(1,1,1,0.1)
        draw_quad(Buttons[i].x+FForms[Buttons[i]].x,FForms[Buttons[i]].y+Buttons[i].y,Buttons[i].w, Buttons.h)
    end
end
end

add_hook("draw2d","FFormsButtons", _drawbuttons)
if you need forms.lua its in the thread called "[lua] form system" or something like that.
Last edited by Blam; Feb 12, 2008 at 09:44 PM.
:D