Toribash
Originally Posted by HoboJoey View Post
test = run_cmd("list")

why that doesnt work?

Well you should be going:
function test()
   run_cmd("list")
end
test()
or simply:
run_cmd("list")
:D
thats not the problem. i want to save the return of run_cmd("list") in a variable so that i can write it in a file...
so that i have all servers in a file.
We have discussed this in IRC.
but yeah:
run_cmd() does not return a value, and the servers that are listed do not appear to call the console hook, therefore can not be read by lua.
:D
I was working on a script after seeing a lot of tutorials, and it actually worked! Then, I tried combining it into a new, better script. The purpose of the original is to echo the difference of scores at every freeze. The purpose of the other is to do that, and when the player is winning to put a transparent box in the lower right corner, a blue box when Uke is winning, and a white box when it's a draw. Here is the original:

function winscore()
Player1_Score = get_player_info(1).injury
Player2_Score = get_player_info(0).injury
if(Player1_Score > Player2_Score) then
echo("Player 1 is winning by" .. " " .. (Player1_Score - Player2_Score))
elseif(Player2_Score > Player1_Score) then
echo("Player 2 is winning by" .. " " .. (Player2_Score - Player1_Score))
else
echo("It's a draw!")
end
end

add_hook("enter_freeze","echowinner",winscore)




And here is the new one:

function winscorehit()
Player1_Score = get_player_info(1).injury
Player2_Score = get_player_info(0).injury
if(Player1_Score > Player2_Score) then
function draw2dfunc1()
set_color(1,1,0,0.2)
draw_quad(10,300,100,200)
end
end
elseif(Player2_Score > Player1_Score) then
function draw2dfunc2()
set_color(0,1,1,0.2)
draw_quad(10,300,100,200)
end
end
else
function draw2dfunc3()
set_color(1,1,1,0.2)
draw_quad(10,300,100,200)
end
end

function winscore()
Player1_Score = get_player_info(1).injury
Player2_Score = get_player_info(0).injury
if(Player1_Score > Player2_Score) then
echo("Player 1 is winning by" .. " " .. (Player1_Score - Player2_Score))
elseif(Player2_Score > Player1_Score) then
echo("Player 2 is winning by" .. " " .. (Player2_Score - Player1_Score))
else
echo("It's a draw!")
end

add_hook("draw2d","draw",draw2dfunc1)
add_hook("enter_freeze","echowinner",winscorehit)
add_hook("draw2d","draw",draw2dfunc2)
add_hook("draw2d","draw",draw2dfunc3)
add_hook("enter_freeze","echowinner",winscore)




I am posting here for 2 reasons: 1: How do I fix the second script? 2: Would you suggest any rounding function that would get rid of the .365127344 after the score? Thanks, and yes the spacing is there.
Proud iCoF Leiutenant.You strike first. I strike last.
winning = 0

function winscore()
    Player1_Score = get_player_info(1).injury
    Player2_Score = get_player_info(0).injury
    if(Player1_Score > Player2_Score) then
        echo("Player 1 is winning by" .. " " .. math.floor(Player1_Score - Player2_Score))
        winning = 1
    elseif(Player2_Score > Player1_Score) then
        echo("Player 2 is winning by" .. " " .. math.floor(Player2_Score - Player1_Score))
        winning = 2
    else
        echo("It's a draw!")
        winning = 0
    end
end

function draw()
    if(winning == 1) then
        set_color(1,0,0,0.2)
    elseif(winning == 2) then
        set_color(0,0,1,0.2)
    else
        set_color(1,1,1,0.2)
    end
    draw_quad(10,300,100,200)
end

add_hook("draw2d","draw",draw)
add_hook("enter_freeze","echowinner",winscore)
If you don't understand any of it, just say
:D
Wow, thanks! I hadn't thought of using a variable to link the functions! The rounding function is cool too! Thanks!
Proud iCoF Leiutenant.You strike first. I strike last.