• Print

Author Topic: Command is not allowing targeting of anyone.  (Read 5176 times)

0 Members and 1 Guest are viewing this topic.

Offline AKTS

  • Newbie
  • *
  • Posts: 5
  • Karma: 1
Command is not allowing targeting of anyone.
« on: January 24, 2015, 02:33:46 pm »
I've been trying to get a guardban command to work for my server, but I've run into a wall as of now. First off, I'm running the latest stable releases of both ULX (3.61) and ULib (2.51) on my own computer, not a remote server. It will be uploaded to a server later, but for now I am just testing it out (I have it portforwarded so that others may join to help test). I'm trying to get this command to work using playerdata, and it's a simple toggle, not a timed ban. Whenever someone tries to enter the swaplist, if they have their gbanstate set to 1 it will prohibit them from joining. It will also prohibit them from being balanced into the guard team automatically. I have three commands: guardban, unguardban, and printguardban. The first two are self-explanatory, and the third one just prints whether they are banned or not.

Now, for the issue. Whenever I go to the ULX menu, I cannot target anyone. There are no syntax errors, either. All I see is one button (like the who command), not a list of all active players. As such, when the button is clicked on, it returns a nil value, creating a script error. It happens with each command, and I have listed the errors for each line below as well. I don't know what I did wrong to break this in such a way, but I thought those who are more proficient in using ULX might see what I missed. Here is the code, and a pastebin link to those who want it:

http://pastebin.com/2FdaE7Nh

Code: Lua
  1. CATEGORY_NAME = "Jailbreak"
  2.  
  3. //Ban Guard
  4. /*
  5.  
  6. [ERROR] addons/ulx/lua/ulx/modules/sh/jailbreak2.lua:13: attempt to index local 'target' (a nil value)
  7.   1. call - addons/ulx/lua/ulx/modules/sh/jailbreak2.lua:13
  8.    2. __fn - addons/ulib/lua/ulib/shared/commands.lua:943
  9.     3. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
  10.      4. unknown - lua/includes/modules/concommand.lua:69
  11. */
  12.  
  13. function ulx.guardban( calling_ply, target )
  14.         local gban = tonumber(target:GetPData("gbanstate")) or 0
  15.         if ulx.getExclusive(calling_ply, target) then
  16.             ULib.tsayError( calling_ply, ulx.getExclusive( target, calling_ply ), true )
  17.         elseif gban == 1 then
  18.                 ULib.tsayError( calling_ply, "Your target is already banned from the guard team!", true)
  19.         elseif gban == 0 then
  20.                 forcechangeteam(calling_ply, target)
  21.                 target:SetPData("gbanstate", 1)
  22.                 GAMEMODE:Notify("You have been banned from the guard team", target)
  23.         end
  24. end
  25.  
  26. local guardban = ulx.command( CATEGORY_NAME, "ulx guardban", ulx.guardban, "!guardban" )
  27. guardban:defaultAccess( ULib.ACCESS_ADMIN )
  28. guardban:help("Bans the targeted player from being on the guard team.")
  29. //Unban Guard
  30. /*
  31. [ERROR] addons/ulx/lua/ulx/modules/sh/jailbreak2.lua:39: attempt to index local 'target' (a nil value)
  32.   1. call - addons/ulx/lua/ulx/modules/sh/jailbreak2.lua:39
  33.    2. __fn - addons/ulib/lua/ulib/shared/commands.lua:943
  34.     3. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
  35.      4. unknown - lua/includes/modules/concommand.lua:69
  36. */
  37.          
  38. function ulx.unguardban( calling_ply, target )
  39.         local gban = tonumber(target:GetPData("gbanstate")) or 0
  40.         if ulx.getExclusive(calling_ply, target) then
  41.             ULib.tsayError( calling_ply, ulx.getExclusive( target, calling_ply ), true )
  42.         elseif gban == 0 then
  43.                 ULib.tsayError( calling_ply, "Your target is not banned from the guard team!", true)
  44.         elseif gban == 1 then
  45.                 target:RemovePData("gbanstate")
  46.                 GAMEMODE:Notify("You have been unbanned from the guard team", target)
  47.                 ulx.fancyLogAdmin( calling_ply, "#A has banned #T from the guard team.", target)
  48.         end
  49. end
  50. local unguardban = ulx.command( CATEGORY_NAME, "ulx unguardban", ulx.unguardban, "!unguardban" )
  51. unguardban:defaultAccess( ULib.ACCESS_ADMIN )
  52. unguardban:help( "Unbans the selected target from the guard team." )
  53.  
  54.  
  55. // PrintGuardBan
  56. /*
  57. [ERROR] addons/ulx/lua/ulx/modules/sh/jailbreak2.lua:65: attempt to index local 'target' (a nil value)
  58.   1. call - addons/ulx/lua/ulx/modules/sh/jailbreak2.lua:65
  59.    2. __fn - addons/ulib/lua/ulib/shared/commands.lua:943
  60.     3. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
  61.      4. unknown - lua/includes/modules/concommand.lua:69
  62.  
  63. */
  64. function ulx.printguardban( calling_ply, target )
  65.         local gban = tonumber(target:GetPData("gbanstate")) or 0
  66.         if gban == 0 then
  67.                 calling_ply:ChatPrint( target:Nick() .. " is not banned" )
  68.         elseif gban == 1 then
  69.                 calling_ply:ChatPrint( target:Nick() .. " is banned." )
  70.         end
  71. end
  72. local printguardban = ulx.command( CATEGORY_NAME, "ulx printguardban", ulx.printguardban, "!printguardban" )
  73. printguardban:defaultAccess( ULib.ACCESS_ADMIN )
  74. printguardban:help( "Prints whether the target is banned from the guard team." )
  75.  
  76.  
  77. // Change Team
  78.  
  79. function forcechangeteam( calling_ply, target_ply )
  80.         if ulx.getExclusive( target_ply, calling_ply ) then
  81.                 ULib.tsayError( calling_ply, ulx.getExclusive( target_ply, calling_ply ), true );
  82.         else                   
  83.                 if (target_ply:Team() == TEAM_PRISONER) then
  84.                         result = TEAM_GUARD;
  85.                 elseif (target_ply:Team() == TEAM_PRISONER_DEAD) then
  86.                         result = TEAM_GUARD_DEAD;
  87.                 elseif (target_ply:Team() == TEAM_GUARD) then
  88.                         result = TEAM_PRISONER;
  89.                 elseif (target_ply:Team() == TEAM_GUARD_DEAD) then
  90.                         result = TEAM_PRISONER_DEAD;
  91.                 end
  92.  
  93.                 if (result) then
  94.                         if (result == TEAM_GUARD or result == TEAM_PRISONER) then
  95.                                 target_ply.jb_ForceAlive = true;
  96.                         end
  97.  
  98.                         target_ply:SetTeam(result);
  99.                         target_ply:Spawn();
  100.  
  101.                         GAMEMODE:Notify(calling_ply:Name().." has force-swapped "..target_ply:Name()..".");
  102.                 else
  103.                         GAMEMODE:Notify("Couldn't find a team for "..target_ply:Name()..".", target_ply);
  104.                 end
  105.         end
  106. end
  107.  

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Command is not allowing targeting of anyone.
« Reply #1 on: January 24, 2015, 02:51:23 pm »
You've never actually added a parameter to your command. You're asking for a target when there is no target command parameter to take.
bw81@ulysses-forums ~ % whoami
Homepage

Offline AKTS

  • Newbie
  • *
  • Posts: 5
  • Karma: 1
Re: Command is not allowing targeting of anyone.
« Reply #2 on: January 24, 2015, 03:11:12 pm »
Thanks! I'm still kind of new to dealing with this, and I forgot to add the player argument parameter. The command now works fine after some testing.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Command is not allowing targeting of anyone.
« Reply #3 on: January 24, 2015, 04:57:35 pm »
AKTS, additionally, our 'stable' download from ulyssesmod.net/download page is actually quite old, and due to the number of updates of Gmod since we released, I dare say our 'non-stable' github repo code is probably more stable. :)
Confusing, I know, but, we're working on a new release soon (relatively speaking)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Livaco

  • Full Member
  • ***
  • Posts: 133
  • Karma: -37
    • Livaco
Re: Command is not allowing targeting of anyone.
« Reply #4 on: March 27, 2015, 11:28:52 am »
Quote
Code: Lua
  1. function ulx.guardban( calling_ply, target )
Target is Ment To Be "target_ply"
That's If I Am Correct
Here To Help And Be Happy And Help :)

My Website
My Addons
PermaBanV1.0

Quote from:  Livaco on April 12 at 9:10:20 PM
I May Be Dum But Am Still Better Then The Rest

Livaco Products©

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Command is not allowing targeting of anyone.
« Reply #5 on: March 27, 2015, 05:05:28 pm »
Target is Ment To Be "target_ply"
That's If I Am Correct
You're not. The original author isn't passing a target variable through the command setup, as Bytewave already stated.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print