While starting out this evening in researching and improving our current gag commands using the Gmod functions or hooks
previously discussed, I realized that the client side SetMuted command would require some major engineering (at least it seemed to me) to make sure that any NEW person connecting to the server would also get GaggedPlayer:SetMuted() ...
Rather than spend major re-inventing the wheel time, I decided to go with the serverside GM hook "PlayerCanHearPlayersVoice"
So far testing has shown promising results.
ULX chat.lua
------------------------------ Gag ------------------------------
function ulx.gagcheck( lstn, talk )
if talk.gagged then
return not talk.gagged
end
end
hook.Add("PlayerCanHearPlayersVoice", "GagCheck", ulx.gagcheck, 15 )
function ulx.gag( calling_ply, target_plys, should_ungag )
for _, v in ipairs( target_plys ) do
v.gagged = not should_ungag
umsg.Start( "ulx_gag", v )
umsg.Bool( not should_ungag )
umsg.End()
end
return true
end
local gag = ulx.command( CATEGORY_NAME, "ulx gag", ulx.gag, "!gag" )
gag:addParam{ type=ULib.cmds.PlayersArg }
gag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
gag:defaultAccess( ULib.ACCESS_ADMIN )
gag:help( "Gag target(s), disables you hearing them speak." )
gag:logString( "#1s gagged #2s" )
gag:setOpposite( "ulx ungag", {_, _, true}, "!ungag" )
gag:oppositeLogString( "#1s ungagged #2s" )
ulx.addToMenu( ulx.ID_MCLIENT, "Gag", "ulx gag" )
ulx.addToMenu( ulx.ID_MCLIENT, "Ungag", "ulx ungag" )ULX cl_lib.lua
function ulx.gagUser( bool )
if bool then
local function gagForce( ply, bind )
if string.find( bind, "+voicerecord" ) then
ULib.tsay ( nil, "[ULX] *** You're gagged. No one else can hear you." )
return true
end
end
hook.Add( "PlayerBindPress", "ULXGagForce", gagForce )
RunConsoleCommand( "-voicerecord" )
else
hook.Remove( "PlayerBindPress", "ULXGagForce" )
end
end
local function rcvGag( um )
local bool = um:ReadBool()
ulx.gagUser( bool )
end
usermessage.Hook( "ulx_gag", rcvGag )
Now, I had a stroke of genius (if I do say so myself)
Though currently using the hook to return false anytime a gagged player speaks... why not create a command for admins to continue listening to the gagged player if they choose?
ulx listen <gagged.player>
-Checks if player.gagged - error if not
-set admin.listening.<gaggedplayer>
Within the PlayerCanHearPlayersVoice hook function, add additional check for admin.listening.<gaggedplayer> and continue on its merry way if listening.
Little adjustment would need to be done to cl_lib too of course.
What do you all think?