• Print

Author Topic: Help with permamute?  (Read 8618 times)

0 Members and 1 Guest are viewing this topic.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Help with permamute?
« on: May 14, 2016, 06:06:31 pm »
So I'm trying to make this command that on use will disable a person's chat permanently until it is removed. Right now I have this:
Code: Lua
  1. function ulx.pmute( calling_ply, target_plys, should_unpmute )
  2.  
  3.         if should_unpmute then
  4.  
  5.                 for k,v in pairs( target_plys ) do
  6.  
  7.                         v:RemovePData( "permmuted" )
  8.  
  9.                 end
  10.  
  11.                 ulx.fancyLogAdmin( calling_ply, "#A un-permamuted #T ", target_plys)
  12.  
  13.         elseif ( not should_unpmute ) then
  14.  
  15.                 for k,v in pairs( target_plys ) do
  16.  
  17.                         v:SetPData( "permmuted", "true" )
  18.  
  19.                 end
  20.  
  21.                 ulx.fancyLogAdmin( calling_ply, "#A permanently muted #T", target_plys )
  22.  
  23.         end
  24.  
  25. end
  26. local pmute = ulx.command( "Chat", "ulx pmute", ulx.pmute, "!pmute" )
  27. pmute:addParam{ type=ULib.cmds.PlayersArg }
  28. pmute:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  29. pmute:defaultAccess( ULib.ACCESS_ADMIN )
  30. pmute:help( "Mute target(s), disables chat using pdata." )
  31. pmute:setOpposite( "ulx unpmute", { _, _, true }, "!unpmute" )
  32.  
  33. local function pmuteHook( text, team, listener, talker )
  34.  
  35.         if talker:GetPData( "permmuted" ) == "true" then
  36.  
  37.                 return false
  38.  
  39.         end
  40.  
  41. end
  42. hook.Add( "PlayerCanSeePlayersChat", "pdatamute", pmuteHook )

and I don't know what it is I'm doing wrong.

I used this as a basis (an already working permanent gag):
Code: Lua
  1. function ulx.pgag( calling_ply, target_plys, should_unpgag )
  2.  
  3.         if should_unpgag then
  4.        
  5.                 for k,v in pairs( target_plys ) do
  6.        
  7.                         v:RemovePData( "permgagged" )
  8.                
  9.                 end
  10.                
  11.                 ulx.fancyLogAdmin( calling_ply, "#A un-permagagged #T ", target_plys )
  12.                
  13.         elseif ( not should_unpgag ) then
  14.                
  15.                 for k,v in pairs( target_plys ) do
  16.        
  17.                         v:SetPData( "permgagged", "true" )
  18.                
  19.                 end
  20.        
  21.                 ulx.fancyLogAdmin( calling_ply, "#A permanently gagged #T", target_plys )
  22.                
  23.         end
  24.        
  25.  
  26.        
  27. end
  28. local pgag = ulx.command( "Chat", "ulx pgag", ulx.pgag, "!pgag" )
  29. pgag:addParam{ type=ULib.cmds.PlayersArg }
  30. pgag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  31. pgag:defaultAccess( ULib.ACCESS_ADMIN )
  32. pgag:help( "Gag target(s), disables microphone using pdata." )
  33. pgag:setOpposite( "ulx unpgag", { _, _, true }, "!unpgag" )
  34.  
  35. local function pgagHook( listener, talker )
  36.  
  37.         if talker:GetPData( "permgagged" ) == "true" then
  38.        
  39.                 return false
  40.                
  41.         end
  42.        
  43. end
  44. hook.Add( "PlayerCanHearPlayersVoice", "pdatagag", pgagHook )
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with permamute?
« Reply #1 on: May 14, 2016, 08:07:40 pm »
Without knowing any console errors, it's difficult to determine what all may be wrong.
However, first glance, you're missing 2 variables in your pgagHook.
 GM:PlayerCanSeePlayersChat hook gets passed 4 variables.
chattext, team-only boolean, listener, then speaker, in that order.
You've have your pgagHook function set up as though you're only looking for the chattext and team-only boolean.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with permamute?
« Reply #2 on: May 14, 2016, 08:56:00 pm »
Yes I understand that it's hard to tell the error. However in the pgagHook it's running GM:PlayerCanHearPlayersVoice which only requires two variables. In the pmuteHook it has GM:PlayerCanSeePlayersChat which I have 4 variables set up for.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with permamute?
« Reply #3 on: May 15, 2016, 06:46:02 am »
Sorry, I got the two examples switched when reviewing. (It was late).
Are you getting any errors in console when this run or starts?
Do you have this running on the server only?
How are you testing?

Have you tried placing any print or msg commands to see what data is stored/recovered and steps are being run?
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with permamute?
« Reply #4 on: May 15, 2016, 09:30:49 am »
I'm getting no errors which is the strange part. I have it in the shared file where the working pgag is already. I have it on a single player game (well, start new game and it's 2 player) and I'm simply trying to use it on myself. Writing this now makes me feel like that's the issue.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with permamute?
« Reply #5 on: May 15, 2016, 09:43:12 am »
Writing this now makes me feel like that's the issue.
Likely.
I'm not sure a singleplayer/listenserver treats Pdata and chat hooks the same as on a ded server.
I may be wrong, but it's possible that since the hook is a server side hook, the speaker/talker will still see themselves talking, only the listeners won't be able to see them.
So, you'd be able to see yourself talking. I think.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with permamute?
« Reply #6 on: May 15, 2016, 09:44:25 am »
I think it might be working, just because it's on myself it doesn't work. I'll ask one of the server operators that I'm staff on if we could test it sometime when there is low popularity on the server.
« Last Edit: May 15, 2016, 10:24:25 am by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Help with permamute?
« Reply #7 on: May 15, 2016, 10:06:56 am »
Start a 2-3 player listen server, forward necessary ports. Have friend join.
Or install local dedicated server, forward ports, do same.
When I was doing more dev work, I had gmod ded installed locally because listen sometimes acts differently.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with permamute?
« Reply #8 on: May 16, 2016, 09:24:53 am »
Turns out that because I was the person being muted, I could see my own chat, but a server manager tested it and it works great, thanks anyways!
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with permamute?
« Reply #9 on: May 16, 2016, 10:41:24 am »
Ok so now I'm having a different problem. It's related to the script and also not. The person who runs the console on the server told me that now whenever he tries to run the "say" command (via the console), the console is flooded with this


« Last Edit: May 16, 2016, 12:17:40 pm by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Help with permamute?
« Reply #10 on: May 16, 2016, 12:30:55 pm »
Could you post the contents of cc_pgag.lua?
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with permamute?
« Reply #11 on: May 16, 2016, 12:34:09 pm »
I asked the operator to send it to me, but he's not available right now, I have the same code except it's in a bit of a different order. Would that still help?
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Help with permamute?
« Reply #12 on: May 16, 2016, 02:42:36 pm »
Wait, what? Who's "the operator"?

The code in a different order would likely not be useful because the line numbers would be different, making it hard to find which line is causing the error.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Help with permamute?
« Reply #13 on: May 16, 2016, 02:45:24 pm »
The operator is the guy who runs the console of the server I'm staff on. His name is Jamie, I'll just refer to him by that from now on. Basically, he's the one that can add/remove things to and from the server, and basically he said that whenever he tries to do the "say" command in the console, he's flooded with those errors. He won't be back on until tomorrow, so I can ask him then to send me the exact code he has and I'll put it here. (I only gave him the code from the pmute, he must've added it to the pgag file, which is why they're different).
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Help with permamute?
« Reply #14 on: May 16, 2016, 08:37:10 pm »
What's happening is that console is always an invalid entity and GetPData can not be passed to it. Basically all you need to do is check if the "talker" is valid.

if IsValid(talker) and talker:GetPData( "permmuted" ) == "true" then ... end

Also not sure if you should add talker.GetPData to be extra safe but just so you can see both variations...

if IsValid(talker) and talker.GetPData and talker:GetPData( "permmuted" ) == "true" then ... end

Line 35 in your paste, line 147 in the console error.



Also to help you understand lua errors better, errors will usually look like this...

[ERROR] path/to/file.lua:line: Description
Everything underneath this line are other errors that happened because of the main error above.

This is the path to the file, aka. where the file is.
The files name, what it's called.
On what line of the file the error happened, this will help you find exactly what part of your code the error happens on. (You will see line numbers in editors like Notepad++, Sublime Text, etc.)
The description tells you what went wrong, "a nil value" means that a value was not found or returned nothing when your code was expecting something.
« Last Edit: May 16, 2016, 08:45:29 pm by LuaTenshi »
I cry every time I see that I am not a respected member of this community.

  • Print