• Print

Author Topic: Odd ULX error  (Read 4208 times)

0 Members and 1 Guest are viewing this topic.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Odd ULX error
« on: August 03, 2014, 12:25:22 pm »
So I was trying to use my respawn command that I created on my own (for learning purposes) and I was able to respawn fine, but it would print an odd error into console

Here's the code for the file
Code: Lua
  1. local CATEGORY_NAME = "MyULX"
  2.  
  3. function ulx.respawn( target_ply )
  4.         if not target_ply:Alive() then
  5.                 target_ply:Spawn()
  6.         end
  7. ulx.fancyLogAdmin( calling_ply, true, "#A respawned #T" )
  8. end
  9.  
  10. local respawn = ulx.command( CATEGORY_NAME, "ulx respawn", ulx.respawn, "!respawn", true )
  11. respawn:addParam{ type=ULib.cmds.PlayersArg }
  12. respawn:defaultAccess( ULib.ACCESS_ADMIN )
  13. respawn:help( "Respawns a player" )

and here's the error I'm getting


(PS: The file name is respawn.lua and it's referenced on line 5 in the error

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Odd ULX error
« Reply #1 on: August 03, 2014, 12:43:43 pm »
"calling_ply" is never defined (but in this case, you have defined "target_ply" as the calling player). You also never defined "#T" in the log, which would normally be "target_ply".

If you're planning to run this command on other players you will have to do some changes.
First change line 3 to this:
Code: [Select]
function ulx.respawn( calling_ply, target_ply )This will define the "calling_ply" or "calling player" and also having the target player.

Line 7 - Change it to this:
Code: [Select]
ulx.fancyLogAdmin( calling_ply, true, "#A respawned #T", target_ply )So the "#T" is set to the target_ply. Another thing you should do, is to also move the log into the "if" statement, so that it doesn't log every time someone tries to use the command, but they're actually alive and doesn't get respawned.

Line 11 - This can be done different ways, but for simplicity's sake, change "PlayersArg" to "PlayerArg" (notice the lack of "s"). Unless you'd like to do a loop through a player table and respawn more than one player in one go.

However, if you're planning on using this so the person using the command respawns themselves, it's advised to do some different changes.

Line 3 - Change "target_ply" to "calling_ply". Just for reference sake:
Code: [Select]
function ulx.respawn( calling_ply )
Line 4 and 5, change "target_ply" to "calling_ply" as well:
Code: [Select]
if not calling_ply:Alive() then
calling_ply:Spawn()

Line 7 - Change the logging to "#A respawned themself". "#T" wouldn't be defined at all in this case, and isn't necessary:
Code: [Select]
ulx.fancyLogAdmin( calling_ply, true, "#A respawned themself" )Also good idea to move it inside the "if" statement, as I said earlier.

Line 11 - Remove it completely. You don't need a "PlayerArg" as you're only using "calling player", so it's not needed at all.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Odd ULX error
« Reply #2 on: August 03, 2014, 12:58:51 pm »
My plan was for staff to use this on other players, not just respawn themself, so I changed it according to the first situation, thanks
(it works fine now)

Here's my final code for reference
Code: Lua
  1. local CATEGORY_NAME = "MyULX"
  2.  
  3. function ulx.respawn( calling_ply, target_ply )
  4.         if not target_ply:Alive() then
  5.                 target_ply:Spawn()
  6.                 ulx.fancyLogAdmin( calling_ply, true, "#A respawned #T", target_ply )
  7.         end
  8. end
  9.  
  10. local respawn = ulx.command( CATEGORY_NAME, "ulx respawn", ulx.respawn, "!respawn", true )
  11. respawn:addParam{ type=ULib.cmds.PlayerArg }
  12. respawn:defaultAccess( ULib.ACCESS_ADMIN )
  13. respawn:help( "Respawns a player" )

  • Print