ULX

Author Topic: ulx.fancyLogAdmin ran multiple times  (Read 1811 times)

0 Members and 1 Guest are viewing this topic.

Offline StaTiiKxKALEB

  • Newbie
  • *
  • Posts: 17
  • Karma: 2
ulx.fancyLogAdmin ran multiple times
« 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?
 
Code: [Select]
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." )

Offline Caustic Soda-Senpai

  • Sr. Member
  • ****
  • Posts: 469
  • Karma: 54
  • <Insert something clever here>
    • Steam Page
Re: ulx.fancyLogAdmin ran multiple times
« Reply #1 on: April 20, 2016, 12:13:57 AM »
You place the fancylog after the loop.
Once you get to know me, you'll find you'll have never met me at all.

Offline StaTiiKxKALEB

  • Newbie
  • *
  • Posts: 17
  • Karma: 2
Re: ulx.fancyLogAdmin ran multiple times
« Reply #2 on: April 20, 2016, 12:37:18 AM »
If I place it after the loop, prevhp2 returns nil.
« Last Edit: April 20, 2016, 01:39:08 AM by StaTiiKxKALEB »

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Re: ulx.fancyLogAdmin ran multiple times
« Reply #3 on: April 20, 2016, 05:45:22 AM »
Code: [Select]
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?

Offline StaTiiKxKALEB

  • Newbie
  • *
  • Posts: 17
  • Karma: 2
Re: ulx.fancyLogAdmin ran multiple times
« Reply #4 on: April 21, 2016, 01:50:23 PM »
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.