Ulysses
General => Developers Corner => Topic started by: StaTiiKxKALEB on April 19, 2016, 10:22:13 PM
-
I was messing around because I want to learn lua, I want it so if the target_plys is greater than 1 it prints something else than if it was 1. I know why the fancylog is ran multiple times. It runs multiple times because it runs once for each consecutive player. How would I make it where it only prints it once?
function ulx.test( calling_ply, target_plys, amount )
local prevhp2 = target_plys[1]:Health()
for i=1, #target_plys do
target_plys[ i ]:SetHealth(amount)
if #target_plys > 1 then
ulx.fancyLogAdmin( calling_ply, "#A set the HP of #T to #s", target_plys, amount )
else
ulx.fancyLogAdmin( calling_ply, "#A set the HP of #T to #s (it was previously #s)", target_plys, amount, prevhp2)
end
end
end
local test = ulx.command( CATEGORY_NAME, "ulx test", ulx.test, "!test", true )
test:addParam{ type=ULib.cmds.PlayersArg }
test:addParam{ type=ULib.cmds.NumArg }
test:defaultAccess( ULib.ACCESS_ADMIN )
test:help( "Test." )
-
You place the fancylog after the loop.
-
If I place it after the loop, prevhp2 returns nil.
-
function ulx.test( calling_ply, target_plys, amount )
local prevhp2 = target_plys[1]:Health()
for i=1, #target_plys do
target_plys[ i ]:SetHealth(amount)
end
if #target_plys > 1 then
ulx.fancyLogAdmin( calling_ply, "#A set the HP of #T to #s", target_plys, amount )
else
ulx.fancyLogAdmin( calling_ply, "#A set the HP of #T to #s (it was previously #s)", target_plys, amount, prevhp2)
end
end
local test = ulx.command( CATEGORY_NAME, "ulx test", ulx.test, "!test", true )
test:addParam{ type=ULib.cmds.PlayersArg }
You're saying the above shows nil for prevhp2?
-
It showed nil when I tried that before, I fixed it I forgot to reply since I was not home for the past few days. Not sure why it would be nil in the first place. I might have misspelled something on accident.