• Print

Author Topic: pgag error  (Read 4915 times)

0 Members and 1 Guest are viewing this topic.

Offline lamb201

  • Newbie
  • *
  • Posts: 15
  • Karma: -1
pgag error
« on: May 29, 2014, 10:22:39 am »
I keep getting a nil error at line 10 when I try to use PData

Code: Lua
  1. local CATEGORY_NAME = "TEST"
  2.  
  3. function ulx.pgag( calling_ply, target_ply, should_pungag )
  4.         local data = 0
  5.  
  6.         if should_pungag then
  7.                 data = 1
  8.         end
  9.  
  10.         target_ply:SetPData("pgag", data)
  11.         target_ply:SetNWBool("ulx_gagged", !should_ungag)
  12.  
  13.         if should_pungag then
  14.                 ulx.fancyLogAdmin( calling_ply, "#A has permanently ungagged #T", target_ply)
  15.         else
  16.                 ulx.fancyLogAdmin( calling_ply, "#A has permanently gagged #T", target_ply)
  17.         end
  18. end
  19. local pgag = ulx.command( CATEGORY_NAME, "ulx pgag", ulx.pgag, "!pgag" )
  20. pgag:addParam{ type=ULib.cmds.PlayersArg }
  21. pgag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  22. pgag:defaultAccess( ULib.ACCESS_ADMIN )
  23. pgag:help( "Permanently Gags target(s), disables microphone." )
  24. pgag:setOpposite( "ulx pungag", {_, _, true}, "!pungag" )
  25.  
  26. local function PERMGAG( ply )
  27.  
  28.         local data = tonumber(ply:GetPData("pgag")) or 1
  29.  
  30.         if data == 0 then
  31.                 ply:SetNWBool("ulx_gagged", true)
  32.         end
  33.  
  34.  
  35. end
  36. hook.Add("PlayerJoinTeam", "PERMGAG", PERMGAG)
  37.  

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: pgag error
« Reply #1 on: May 29, 2014, 11:24:58 am »
Line 20: change from "PlayersArg" to "PlayerArg".
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: pgag error
« Reply #2 on: May 29, 2014, 12:56:35 pm »
Or re-code your function at line 3 to loop through a table, which is what PlayersArg does (pass a table of one or more player objects, where PlayerArg passes single player object)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline lamb201

  • Newbie
  • *
  • Posts: 15
  • Karma: -1
Re: pgag error
« Reply #3 on: May 29, 2014, 01:38:29 pm »
That works, but it doesn't gag them?  :-\

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: pgag error
« Reply #4 on: May 29, 2014, 02:22:36 pm »
That's because you only set the PData for it. You don't have any code for disabling a player's voice chat.

Take a look at the PlayerCanHearPlayersVoice hook.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline lamb201

  • Newbie
  • *
  • Posts: 15
  • Karma: -1
Re: pgag error
« Reply #5 on: June 01, 2014, 02:08:58 pm »
Thanks guys! It works now, I ended up with this:

Code: Lua
  1. local CATEGORY_NAME = "GAG"
  2.  
  3. function ulx.pgag( calling_ply, target_ply )
  4.         local t = target_ply
  5.         local PGagBool = tobool(t:GetPData("PGag")) or false
  6.  
  7.         if PGagBool then
  8.                 ULib.tsayError( calling_ply, t:Nick() .. " is already gagged!", true )
  9.                 return
  10.         end
  11.  
  12.         t:SetPData("PGag", true)
  13.         ulx.fancyLogAdmin( calling_ply, "#A has permanently gagged #T", t )
  14. end
  15. local pgag = ulx.command( CATEGORY_NAME, "ulx pgag", ulx.pgag, "!pgag" )
  16. pgag:addParam{ type=ULib.cmds.PlayerArg }
  17. pgag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  18. pgag:defaultAccess( ULib.ACCESS_ADMIN )
  19. pgag:help( "Permanently Gags target(s), disables microphone." )
  20.  
  21. function ulx.pungag( calling_ply, target_ply )
  22.         local t = target_ply
  23.         local PGagBool = tobool(t:GetPData("PGag")) or false
  24.  
  25.         if not PGagBool then
  26.                 ULib.tsayError( calling_ply, t:Nick() .. " is not gagged!", true )
  27.                 return
  28.         end
  29.  
  30.         t:SetPData("PGag", false)
  31.         ulx.fancyLogAdmin( calling_ply, "#A has permanently ungagged #T", t )
  32. end
  33. local pungag = ulx.command( CATEGORY_NAME, "ulx pungag", ulx.pungag, "!pungag" )
  34. pungag:addParam{ type=ULib.cmds.PlayerArg }
  35. pungag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  36. pungag:defaultAccess( ULib.ACCESS_ADMIN )
  37. pungag:help( "Permanently ungags target(s), enables microphone." )
  38.  
  39. local function doGag( listener, talker )
  40.         local PGagBool = tobool(talker:GetPData("PGag")) or false
  41.  
  42.         if PGagBool then
  43.                 return false
  44.         end
  45. end
  46. hook.Add( "PlayerCanHearPlayersVoice", "PGag", doGag )

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: pgag error
« Reply #6 on: June 01, 2014, 02:31:54 pm »
Don't do that. Never check PData in a hook that calls as fast as that one. Instead hook PlayerSpawn or use a 30 second timer or something that doesn't call as frequently, check for pdata there and set a value on the player to check for in the playercanhearplayersvoice hook.
Also, instead of setting their pdata to false, just use RemovePData

  • Print