General > Developers Corner

ulx.fancyLogAdmin ran multiple times

(1/1)

StaTiiKxKALEB:
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?
 

--- Code: ---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." )
--- End code ---

Caustic Soda-Senpai:
You place the fancylog after the loop.

StaTiiKxKALEB:
If I place it after the loop, prevhp2 returns nil.

Buzzkill:

--- Code: ---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 }
--- End code ---


You're saying the above shows nil for prevhp2?

StaTiiKxKALEB:
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.

Navigation

[0] Message Index

Go to full version