• Print

Author Topic: Mute + Gag Time And Reason  (Read 7300 times)

0 Members and 1 Guest are viewing this topic.

Offline BlizzardyFire

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Mute + Gag Time And Reason
« on: December 12, 2017, 07:37:26 pm »
Hello, whenever I try doing this I somehow mess up or it doesn't work at all. I've looked all around on google but cannot find a solution. I've managed to get it to work with jailing (a reason) but i cant get a time or reason mutes + gags without it breaking, any help would be appreciated!

Code: [Select]
function ulx.gag( calling_ply, target_plys, time, reason, should_ungag )
local players = player.GetAll()
for i=1, #target_plys do
local v = target_plys[ i ]
v.ulx_gagged = not should_ungag
v:SetNWBool("ulx_gagged", v.ulx_gagged)
if not v.ulx_gagged then
timer.Create(v:SteamID64().."ulxgag", time, 1, function()
if not IsValid(v) then return end
v.ulx_gagged = not v.ulx_gagged
v:SetNWBool("ulx_gagged", v.ulx_gagged)
end)
else
timer.Destroy(v:SteamID64().."ulxgag")
v.ulx_gagged = not v.ulx_gagged
v:SetNWBool("ulx_gagged", v.ulx_gagged)
end
end

if not should_ungag then
local str = "#A gagged #T"
if seconds > 0 then
str = str .. " for #i seconds"
end
if reason and reason ~= "" then str = str .. " (#s)" end
ulx.fancyLogAdmin( calling_ply, str, target_plys, seconds, reason )
else
ulx.fancyLogAdmin( calling_ply, "#A ungagged #T", target_plys, reason )
end
end

local gag = ulx.command( CATEGORY_NAME, "ulx gag", ulx.gag, "!gag" )
gag:addParam{ type=ULib.cmds.PlayersArg }
gag:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="seconds, 0 is forever", ULib.cmds.round, ULib.cmds.optional }
gag:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
gag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
gag:defaultAccess( ULib.ACCESS_ADMIN )
gag:help( "Gag target(s), disables microphone." )
gag:setOpposite( "ulx ungag", {_, _, true}, "!ungag" )

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Mute + Gag Time And Reason
« Reply #1 on: December 12, 2017, 08:24:19 pm »
One thing to always include when asking for help: What is the expected result (if not clear by the question) and what is the actual result (what actually happens).

You say it's "breaking". What exactly do you mean by that? If you mean it errors, what are the errors being given?

If it's not working as in it's not doing anything, one thing I notice right off the bat is the setOpposite, it should be { _, _, _, _, true } not { _, _, true }, but that shouldn't prevent the command itself from not working.

Also, you use "seconds > 0" when your parameter is "time".

From what I understand from the code (not the intended behaviour, but the behaviour I read from the code), you're checking if the player is not gagged, and if they aren't you create a timer that makes them gagged after a certain time. However if they are gagged, you destroy the timer you created before (if it exists) then make the player ungagged. I don't think you want to check if they player is already gagged/not gagged but instead check for whether or not you should be trying to gag them or not (using if ( should_ungag )) and then handling it from there. This is how I would tackle it:

Code: Lua
  1. function ulx.gag( calling_ply, target_plys, time, reason, should_ungag )
  2.     if ( not time ) then time = 0 end
  3.     if ( not reason ) then reason = "" end
  4.     for ( i = 1, #target_plys ) do
  5.         local ply = target_plys[ i ]
  6.         local str = ""
  7.         if ( should_ungag ) then
  8.                 v.ulx_gagged = false
  9.                 v:SetNWBool( "ulx_gagged", v.ulx_gagged )
  10.                 if ( timer.Exists( v:SteamID64() .. "ulxgag" ) ) then
  11.                         timer.Destroy( v:SteamID64() .. "ulxgag" )
  12.                 end
  13.                 str = str .. "#A ungagged #T"
  14.                 ulx.fancyLogAdmin( calling_ply, str, target_plys, reason )
  15.         else
  16.                 v.ulx_gagged = true
  17.                 v:SetNWBool( "ulx_gagged", v.ulx_gagged )
  18.                 if ( time > 0 )
  19.                         timer.Create( v:SteamID64() .. "ulxgag", time, 1, function()
  20.                                 v.ulx_gagged = false
  21.                                 v:SetNWBool( "ulx_gagged", false )
  22.                         end )
  23.                 end
  24.                 str = str .. "#A gagged #T"
  25.                 if ( time > 0 ) then
  26.                         str = str .. " for #i seconds"
  27.                 end
  28.                 if ( reason and reason ~= "" ) then
  29.                         str = str .. " (#s)"
  30.                 end
  31.                 ulx.fancyLogAdmin( calling_ply, str, target_plys, reason )
  32.         end
  33.     end
  34. end
  35. local gag = ulx.command( CATEGORY_NAME, "ulx gag", ulx.gag, "!gag" )
  36. gag:addParam{ type=ULib.cmds.PlayersArg }
  37. gag:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="seconds, 0 is forever", ULib.cmds.round, ULib.cmds.optional }
  38. gag:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
  39. gag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  40. gag:defaultAccess( ULib.ACCESS_ADMIN )
  41. gag:help( "Gag target(s), disables microphone." )
  42. gag:setOpposite( "ulx ungag", { _, _, _, _, true }, "!ungag" )
  43.  

So I changed a couple things. Notably I made it a bit more efficient; the string is now declared at the beginning of the function, and then edited to specific needs based on whether or not we're trying to gag/ungag them. I also fixed your setOpposite to it will now properly ungag someone (you were using the wrong variable in the wrong place). I also fixed your timers. If we want to gag them, it will properly gag them and create a timer that then ungags them after a specific time.

Keep in mind I have not tested this code. It should work based on logic, but I can't guarantee that it will.
« Last Edit: December 13, 2017, 11:54:45 am by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline BlizzardyFire

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Mute + Gag Time And Reason
« Reply #2 on: December 13, 2017, 11:47:54 am »
Whenever trying to gag it says: You ungagged Yourself

Offline BlizzardyFire

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Mute + Gag Time And Reason
« Reply #3 on: December 13, 2017, 11:50:31 am »
it also says theres an error at the     for ( i = 1, #target_plys ) do line

Offline BlizzardyFire

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Mute + Gag Time And Reason
« Reply #4 on: December 13, 2017, 11:52:46 am »
seemed to fix it but now it says:
Code: [Select]
addons/ulx-master/lua/ulx/log.lua:450: attempt to index local 'format' (a nil value)
  1. fancyLogAdmin - addons/ulx-master/lua/ulx/log.lua:450
   2. call - addons/ulx-master/lua/ulx/modules/sh/chat.lua:253
    3. __fn - addons/ulib-master/lua/ulib/shared/commands.lua:943
     4. unknown - addons/ulib-master/lua/ulib/shared/commands.lua:1296
      5. Run - lua/includes/modules/concommand.lua:54
       6. unknown - addons/ulib-master/lua/ulib/shared/commands.lua:1311
        7. unknown - lua/includes/modules/concommand.lua:54



Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Mute + Gag Time And Reason
« Reply #5 on: December 13, 2017, 11:59:49 am »
Okay I edited it. Remember I said I didn't test this, I was expecting you to figure out what was wrong with it.

I'm guessing chat.lua:253 is the ulx.fancyLogAdmin() call? If so, it was my fault, I put the call outside of the loop so "str" couldn't be found outside of the loop. I edited my first post, and it should work. Remember again, I haven't tested it.


As a side note, you can edit a post instead of making 3 separate posts.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline BlizzardyFire

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Mute + Gag Time And Reason
« Reply #6 on: December 13, 2017, 12:04:03 pm »
Getting this now when i try using a time: ex: ulx gag ^ 500 test

Code: [Select]
addons/ulx-master/lua/ulx/log.lua:479: bad argument #2 to 'format' (number expected, got string)
  1. format - [C]:-1
   2. unknown - addons/ulx-master/lua/ulx/log.lua:479
    3. gsub - [C]:-1
     4. fancyLogAdmin - addons/ulx-master/lua/ulx/log.lua:450
      5. call - addons/ulx-master/lua/ulx/modules/sh/chat.lua:254
       6. __fn - addons/ulib-master/lua/ulib/shared/commands.lua:943
        7. unknown - addons/ulib-master/lua/ulib/shared/commands.lua:1296
         8. Run - lua/includes/modules/concommand.lua:54
          9. unknown - addons/ulib-master/lua/ulib/shared/commands.lua:1311
           10. unknown - lua/includes/modules/concommand.lua:54

Offline BlizzardyFire

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Mute + Gag Time And Reason
« Reply #7 on: December 13, 2017, 12:06:42 pm »
Got it to work by adding time after target

Offline BlizzardyFire

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: Mute + Gag Time And Reason
« Reply #8 on: December 13, 2017, 12:11:21 pm »
thanks so much for the help

  • Print