• Print

Author Topic: Prophunt Custom Made Commands Error  (Read 8193 times)

0 Members and 1 Guest are viewing this topic.

Offline James Aitchison

  • Newbie
  • *
  • Posts: 4
  • Karma: 1
Prophunt Custom Made Commands Error
« on: October 29, 2016, 11:21:41 am »
My ULib/ULX versions (run "ulx version" in console):
ULib v2.61d (10/27/16)
ULX v3.70d (02/28/16)

Game mode(s) I am having this problem on: PropHunt

Lua errors shown in console, if any:
Code: [Select]
[ERROR] addons/ulx-master/lua/ulx/modules/sh/owencommands.lua:138: attempt to index local 'target_plys' (a nil value)

  1. afk - addons/ulx-master/lua/ulx/modules/sh/owencommands.lua:138

   2. unknown - addons/ulx-master/lua/ulx/modules/sh/owencommands.lua:147

    3. include - [C]:-1

     4. unknown - addons/ulx-master/lua/ulx/init.lua:34

      5. include - [C]:-1

       6. unknown - addons/ulx-master/lua/ulib/modules/ulx_init.lua:2

        7. include - [C]:-1

         8. unknown - addons/ulib-master/lua/ulib/init.lua:74

          9. include - [C]:-1

           10. unknown - addons/ulib-master/lua/autorun/ulib_init.lua:3

The file it's refering too:
http://pastebin.com/vzK8JiFS


Please help as i have been spending hours trying to get this to work. I have googled the error as well as used a previous code released on facepunch, but that was back in january 2014 so the code doesnt want to work with the gmod updates since then.

Thank you in advance to anyone who can help me solve this,

James
« Last Edit: October 29, 2016, 11:23:41 am by James Aitchison »

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Prophunt Custom Made Commands Error
« Reply #1 on: October 29, 2016, 11:39:17 am »
First of all, your ulx and ulib are slightly outdated, you can get the latest here.

As far as I know, the "Team()" function can only be called on one person (I could be wrong). Also, SetTeam() can only be called on the client, so you'd need a check for that.

So, really, I don't think this can be a multi target thing, just try it with one, it would probably be easier anyways.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline James Aitchison

  • Newbie
  • *
  • Posts: 4
  • Karma: 1
Re: Prophunt Custom Made Commands Error
« Reply #2 on: October 29, 2016, 11:59:30 am »
First of all, your ulx and ulib are slightly outdated, you can get the latest here.

As far as I know, the "Team()" function can only be called on one person (I could be wrong). Also, SetTeam() can only be called on the client, so you'd need a check for that.

So, really, I don't think this can be a multi target thing, just try it with one, it would probably be easier anyways.

Ah I see, that you for the update.

My LUA skills are next to none, so when you say the "Team()" function, would that be in replacement of "target_ply:Team()"? And the same goes for the "SetTeam()" function?

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Prophunt Custom Made Commands Error
« Reply #3 on: October 29, 2016, 08:02:58 pm »
Ah I see, that you for the update.

My LUA skills are next to none, so when you say the "Team()" function, would that be in replacement of "target_ply:Team()"? And the same goes for the "SetTeam()" function?
Your code takes in a ULib.cmds.PlayersArg, which matches multiple players. But your code is built around one player, so you would want to change PlayersAarg to PlayerArg. Optionally, you could also replace target_plys with target_ply to make your code more readable.
Those two adaptations to ulx.afk (lines 136-151) should get you running.

Also, in contrast to what iViscosity said, SetTeam is serverside, so you should surround target_ply:SetTeam(TEAM_SPECTATORS) with:
Code: Lua
  1. if SERVER then
  2.     -- your code here
  3. end

Finally, your code is redundant—you check to see if the targeted player is TEAM_HUNTERS or TEAM_PROPS, but perform the same actions on both. Likely you were trying to exclude TEAM_SPECTATORS, in which case you could use:
Code: Lua
  1. if target_ply:Team() == TEAM_HUNTERS or target_ply:Team() == TEAM_PROPS then
  2.     -- your code here
  3. end
bw81@ulysses-forums ~ % whoami
Homepage

Offline James Aitchison

  • Newbie
  • *
  • Posts: 4
  • Karma: 1
Re: Prophunt Custom Made Commands Error
« Reply #4 on: October 30, 2016, 09:46:11 am »
Your code takes in a ULib.cmds.PlayersArg, which matches multiple players. But your code is built around one player, so you would want to change PlayersAarg to PlayerArg. Optionally, you could also replace target_plys with target_ply to make your code more readable.
Those two adaptations to ulx.afk (lines 136-151) should get you running.

Also, in contrast to what iViscosity said, SetTeam is serverside, so you should surround target_ply:SetTeam(TEAM_SPECTATORS) with:
Code: Lua
  1. if SERVER then
  2.     -- your code here
  3. end

Finally, your code is redundant—you check to see if the targeted player is TEAM_HUNTERS or TEAM_PROPS, but perform the same actions on both. Likely you were trying to exclude TEAM_SPECTATORS, in which case you could use:
Code: Lua
  1. if target_ply:Team() == TEAM_HUNTERS or target_ply:Team() == TEAM_PROPS then
  2.     -- your code here
  3. end
Thank you for your reply  Bytewave, I roughly understand what you have said and tried to implant what you have said into my code, but I am still coming up with the error of:
Code: Lua
  1. [ERROR] addons/ulx-master/lua/ulx/modules/sh/owencommands.lua:139: attempt to index local 'target_ply' (a nil value)
  2.  
  3.   1. afk - addons/ulx-master/lua/ulx/modules/sh/owencommands.lua:139
  4.  
  5.    2. unknown - addons/ulx-master/lua/ulx/modules/sh/owencommands.lua:146
  6.  
  7.     3. include - [C]:-1
  8.  
  9.      4. unknown - addons/ulx-master/lua/ulx/init.lua:34
  10.  
  11.       5. include - [C]:-1
  12.  
  13.        6. unknown - addons/ulx-master/lua/ulib/modules/ulx_init.lua:2
  14.  
  15.         7. include - [C]:-1
  16.  
  17.          8. unknown - addons/ulib-master/lua/ulib/init.lua:74
  18.  
  19.           9. include - [C]:-1
  20.  
  21.            10. unknown - addons/ulib-master/lua/autorun/ulib_init.lua:3
  22.  

In relation to my code:
Code: Lua
  1. --------------------Afk--------------------
  2.  if SERVER then
  3.  function ulx.afk( calling_ply, target_ply )
  4.     if target_ply:Team() == TEAM_HUNTERS or target_ply:Team() == TEAM_PROPS then
  5.         target_ply:Kill()
  6.         target_ply:SetTeam(TEAM_SPECTATORS)
  7.     end
  8.     ulx.fancyLogAdmin( calling_ply, "#A has moved #T to spectator.", target_ply )
  9.         end
  10. end    
  11. local afk = ulx.command(CATEGORY_NAME, "ulx afk", ulx.afk "!afk" )
  12. afk:addParam{ type=ULib.cmds.PlayerArg }
  13. afk:defaultAccess( ULib.ACCESS_ADMIN )
  14. afk:help ( "Moves A Player To Spectator" )
  15.  

Line 139 relates to line 4 in the code i have supplied above now.

I am unsure as of to what I have done wrong in this now as I believe i have put the code in that you supplied so any addiontial help would be greatly appreciated.

Thanks,
James

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Prophunt Custom Made Commands Error
« Reply #5 on: October 30, 2016, 11:46:48 am »
Thank you for your reply  Bytewave, I roughly understand what you have said and tried to implant what you have said into my code, but I am still coming up with the error of:
Code: Lua
  1. [ERROR] addons/ulx-master/lua/ulx/modules/sh/owencommands.lua:139: attempt to index local 'target_ply' (a nil value)
  2.   1. afk - addons/ulx-master/lua/ulx/modules/sh/owencommands.lua:139
snip

The issue here, I believe, is your placement of the if SERVER then statement. Instead of wrapping:
Code: Lua
  1. if SERVER then
  2.     -- code
  3. end
around your entire ulx.afk function, you should instead wrap it around the target_ply:SetTeam() line.

Though, it's interesting that that even works if ulx.afk isn't defined clientside... but hopefully that should fix it.

Oh, also, on line 11 of the snippet you posted, you should have a comma between ulx.afk and "!afk".
bw81@ulysses-forums ~ % whoami
Homepage

Offline James Aitchison

  • Newbie
  • *
  • Posts: 4
  • Karma: 1
Re: Prophunt Custom Made Commands Error
« Reply #6 on: October 31, 2016, 07:37:12 am »
The issue here, I believe, is your placement of the if SERVER then statement. Instead of wrapping:
Code: Lua
  1. if SERVER then
  2.     -- code
  3. end
around your entire ulx.afk function, you should instead wrap it around the target_ply:SetTeam() line.

Though, it's interesting that that even works if ulx.afk isn't defined clientside... but hopefully that should fix it.

Oh, also, on line 11 of the snippet you posted, you should have a comma between ulx.afk and "!afk".

Thats perfect! It works a treat now, thank ou very much ByteWave!

  • Print