Ulysses
General => Developers Corner => Topic started by: Jerpy on February 08, 2015, 04:21:38 PM
-
I found an old thread on here regarding a script for pgag which I have been searching for. I'm unable to find anything besides this one thread. It's about a year old and I did not want to bump it, so I have copied the script here. The last post on it was regarding something about how you should not have the script call the pdata that often, as it can have bad outcomes. He then said configure it so that it only is called when the player spawns. How would I go about doing that in this script?
local CATEGORY_NAME = "GAG"
function ulx.pgag( calling_ply, target_ply )
local t = target_ply
local PGagBool = tobool(t:GetPData("PGag")) or false
if PGagBool then
ULib.tsayError( calling_ply, t:Nick() .. " is already gagged!", true )
return
end
t:SetPData("PGag", true)
ulx.fancyLogAdmin( calling_ply, "#A has permanently gagged #T", t )
end
local pgag = ulx.command( CATEGORY_NAME, "ulx pgag", ulx.pgag, "!pgag" )
pgag:addParam{ type=ULib.cmds.PlayerArg }
pgag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
pgag:defaultAccess( ULib.ACCESS_ADMIN )
pgag:help( "Permanently Gags target(s), disables microphone." )
function ulx.pungag( calling_ply, target_ply )
local t = target_ply
local PGagBool = tobool(t:GetPData("PGag")) or false
if not PGagBool then
ULib.tsayError( calling_ply, t:Nick() .. " is not gagged!", true )
return
end
t:SetPData("PGag", false)
ulx.fancyLogAdmin( calling_ply, "#A has permanently ungagged #T", t )
end
local pungag = ulx.command( CATEGORY_NAME, "ulx pungag", ulx.pungag, "!pungag" )
pungag:addParam{ type=ULib.cmds.PlayerArg }
pungag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
pungag:defaultAccess( ULib.ACCESS_ADMIN )
pungag:help( "Permanently ungags target(s), enables microphone." )
local function doGag( listener, talker )
local PGagBool = tobool(talker:GetPData("PGag")) or false
if PGagBool then
return false
end
end
hook.Add( "PlayerCanHearPlayersVoice", "PGag", doGag )
Thanks in advance
-
This is an up to date version i think.
function ulx.pgag( calling_ply, target_plys, should_unpgag )
if should_unpgag then
for k,v in pairs( target_plys ) do
v:RemovePData( "permgagged" )
end
ulx.fancyLogAdmin( calling_ply, "#A un-permagagged #T ", target_plys )
elseif ( not should_unpgag ) then
for k,v in pairs( target_plys ) do
v:SetPData( "permgagged", "true" )
end
ulx.fancyLogAdmin( calling_ply, "#A permanently gagged #T", target_plys )
end
end
local pgag = ulx.command( "Custom", "ulx pgag", ulx.pgag, "!pgag" )
pgag:addParam{ type=ULib.cmds.PlayersArg }
pgag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
pgag:defaultAccess( ULib.ACCESS_ADMIN )
pgag:help( "Gag target(s), disables microphone using pdata." )
pgag:setOpposite( "ulx unpgag", { _, _, true }, "!unpgag" )
local function pgagHook( listener, talker )
if talker:GetPData( "permgagged" ) == "true" then
return false
end
end
hook.Add( "PlayerCanHearPlayersVoice", "pdatagag", pgagHook )
---- functions to check if players are gagged upon them leaving and joining ----
function pgagPlayerDisconnect( ply )
if ply:GetPData( "permgagged" ) == "true" then
for k,v in pairs( player.GetAll() ) do
if v:IsAdmin() then
ULib.tsayError( v, ply:Nick() .. " has left the server and is permanently gagged." )
end
end
end
end
hook.Add( "PlayerDisconnected", "pgagdisconnect", pgagPlayerDisconnect )
function pgaguserAuthed( ply )
if ply:GetPData( "permgagged" ) == "true" then
for k,v in pairs( player.GetAll() ) do
if v:IsAdmin() then
ULib.tsayError( v, ply:Nick() .. " has joined and is permanently gagged." )
end
end
end
end
hook.Add( "PlayerAuthed", "pgagauthed", pgaguserAuthed )
---- function to list players who are pgagged ----
function ulx.printpgags( calling_ply )
pgagged = {}
for k,v in pairs( player.GetAll() ) do
if v:GetPData( "permgagged" ) == "true" then -- find all players who have "gagged" set to true
table.insert( pgagged, v:Nick() )
end
end
local pgags = table.concat( pgagged, ", " ) -- concatenate each player in the table with a comma
ulx.fancyLog( {calling_ply}, "PGagged: #s ", pgags ) -- only prints this to the player who called the function
end
local printpgags = ulx.command( "Custom", "ulx printpgags", ulx.printpgags, "!printpgags", true )
printpgags:defaultAccess( ULib.ACCESS_ADMIN )
printpgags:help( "Prints players who are pgagged." )