HTOTM: FUSION
Original Post
I need LUA help (cos i suck)
Ok, this is supposed to draw 3 boxes containing text on the person selected, and some server information (if no person is selected, then it wont show). But it just wont show, and there is no error message.

local function DrawStuff()
    worldstate = get_world_state()
    player = worldstate.selected_player
    Game_Rules = get_game_rules()
    Mod_Name = Game_Rules.mod
    Player_Info[0] = get_player_info(0)
    Player_Info[1] = get_player_info(1)
    Player_Name = Player_Info[player].name
    if (player == 0) then
        player2 = 1
        Colourr, Colourg, Colourb = 1,0,0
    else
        player2 = 0
        Colourr, Colourg, Colourb = 0,0,1
    end
    WinLoose = Player_Info[player].score - Player_Info[player2].score
    if (WinLoose < 0) then
        Winning = "No"
    else
        Winning = "Yes"
    end
    grip_info1 = get_grip_info(player, 11)
    grip_info2 = get_grip_info(player, 12)
    set_color(Colourr, Colourg, Colourb, 0.5)
    draw_quad(45, 95, 160, 200)
    set_color(0, 0, 0, 0.4)
    draw_quad(50, 100, 150, 50)
    set_color(0, 0, 0, 0.4)
    draw_quad(50, 155, 150, 135)
    set_color(1, 1, 1, 1)
    draw_text("Hands:", 100, 105)
    draw_text("Left: " .. grip_info2 .. " Right: " .. grip_info1, 75, 125)
    draw_text(Mod_Name , 55, 155)
    draw_text("Fracture: " .. Game_Rules.fracture, 55, 175)
    draw_text("Dismember: " .. Game_Rules.dismemberment, 55, 195)
    draw_text("DM Thresh: " .. Game_Rules.dismemberthreshold, 55, 215)
    draw_text("DQ: " .. Game_Rules.disqualification, 55, 235)
    draw_text("Dis:" .. Game_Rules.engagedistance .. " Height:" .. Game_Rules.engageheight, 55, 255)
    draw_text("Winning:" .. Winning, 55, 255)
    draw_text("Dis:" .. Game_Rules.engagedistance .. " Height:" .. Game_Rules.engageheight, 55, 255)
end

add_hook("draw2d", "griptest", DrawStuff)
Oh and i am aware the last 3 texts will draw on top of each other.
:D
I'll look at it for ya man.

EDIT: Ok, done. It was all fine except for one thing. You needed to define the Player_Info table before you used it. Here's the functional thing below.

local function DrawStuff()
    worldstate = get_world_state()
    player = worldstate.selected_player
    if player == nil then player = 0 end
	Game_Rules = get_game_rules()
    Mod_Name = Game_Rules.mod
    Player_Info = { }
	Player_Info[0] = get_player_info(0)
    Player_Info[1] = get_player_info(1)
    Player_Name = Player_Info[player].name
    if (player == 0) then
        player2 = 1
        Colourr, Colourg, Colourb = 1,0,0
    else
        player2 = 0
        Colourr, Colourg, Colourb = 0,0,1
    end
    WinLoose = Player_Info[player].score - Player_Info[player2].score
    if (WinLoose < 0) then
        Winning = "No"
    else
        Winning = "Yes"
    end
    grip_info1 = get_grip_info(player, 11)
    grip_info2 = get_grip_info(player, 12)
    set_color(Colourr, Colourg, Colourb, 0.5)
    draw_quad(45, 95, 160, 200)
    set_color(0, 0, 0, 0.4)
    draw_quad(50, 100, 150, 50)
    set_color(0, 0, 0, 0.4)
    draw_quad(50, 155, 150, 135)
    set_color(1, 1, 1, 1)
    draw_text("Hands:", 100, 105)
    draw_text("Left: " .. grip_info2 .. " Right: " .. grip_info1, 75, 125)
    draw_text(Mod_Name , 55, 155)
    draw_text("Fracture: " .. Game_Rules.fracture, 55, 175)
    draw_text("Dismember: " .. Game_Rules.dismemberment, 55, 195)
    draw_text("DM Thresh: " .. Game_Rules.dismemberthreshold, 55, 215)
    draw_text("DQ: " .. Game_Rules.disqualification, 55, 235)
    draw_text("Dis:" .. Game_Rules.engagedistance .. " Height:" .. Game_Rules.engageheight, 55, 255)
    draw_text("Winning:" .. Winning, 55, 255)
    draw_text("Dis:" .. Game_Rules.engagedistance .. " Height:" .. Game_Rules.engageheight, 55, 255)
end

add_hook("draw2d", "griptest", DrawStuff)
Nice script, btw.

Also, if something doesn't seem to be working, and tb doesn't say error loading, then look in the stderr.txt file in toribash root directory. Sometimes a lua file will load and appear to run, even if an error is happening. Usually this happens if the error is in a function and not syntax related. The error it was throwing was:

Lua script error: data/script/blamsthing.lua:6: attempt to index global 'Player_Info' (a nil value)

That usually means that Player_Info has not been initalized, and to be able to index a variable, it can't be nil. I usually define it as a table first by using [variablename] = { } just to be sure there won't be any problems.
Last edited by NewbLuck; Nov 11, 2007 at 04:03 AM.
 ____  _____  __  __  _  _  ___  _  _ 
(  _ \(  _  )(  )(  )( \( )/ __)( \/ )
 ) _ < )(_)(  )(__)(  )  (( (__  \  / 
(____/(_____)(______)(_)\_)\___) (__)