local function voteGagDone2( t, target, time, ply, reason ) local shouldGag = false if t.results[ 1 ] and t.results[ 1 ] > 0 then ulx.logUserAct( ply, target, "#A approved the votegag against #T (" .. time .. " minutes)" ) shouldGag = true else ulx.logUserAct( ply, target, "#A denied the votegag against #T" ) end if shouldGag then target:SetPData( "votegagged", time ) end end local function voteGagDone( t, target, time, ply, reason ) local results = t.results local winner local winnernum = 0 for id, numvotes in pairs( results ) do if numvotes > winnernum then winner = id winnernum = numvotes end end local ratioNeeded = GetConVarNumber( "ulx_votegagSuccessratio" ) local minVotes = GetConVarNumber( "ulx_votegagMinvotes" ) local str if winner ~= 1 or winnernum < minVotes or winnernum / t.voters < ratioNeeded then str = "Vote results: User will not be gagged. (" .. (results[ 1 ] or "0") .. "/" .. t.voters .. ")" else str = "Vote results: User will now be gagged for " .. time .. " minutes, pending approval. (" .. winnernum .. "/" .. t.voters .. ")" ulx.doVote( "Accept result and gag " .. target:Nick() .. "?", { "Yes", "No" }, voteGagDone2, 30000, { ply }, true, target, time, ply ) end ULib.tsay( _, str ) ulx.logString( str ) Msg( str .. "\n" ) end function ulx.votegag( calling_ply, target_ply, minutes ) if voteInProgress then ULib.tsayError( calling_ply, "There is already a vote in progress. Please wait for the current one to end.", true ) return end local msg = "Gag " .. target_ply:Nick() .. " for " .. minutes .. " minutes?" ulx.doVote( msg, { "Yes", "No" }, voteGagDone, _, _, _, target_ply, minutes, calling_ply ) ulx.fancyLogAdmin( calling_ply, "#A started a votegag of #i minute(s) against #T", minutes, target_ply ) end local votegag = ulx.command( "Voting", "ulx votegag", ulx.votegag, "!votegag" ) votegag:addParam{ type=ULib.cmds.PlayerArg } votegag:addParam{ type=ULib.cmds.NumArg, min=0, default=3, hint="minutes", ULib.cmds.allowTimeString, ULib.cmds.optional } votegag:defaultAccess( ULib.ACCESS_ALL ) votegag:help( "Starts a public vote gag against target." ) if SERVER then ulx.convar( "votegagSuccessratio", "0.7", _, ULib.ACCESS_ADMIN ) end if SERVER then ulx.convar( "votegagMinvotes", "3", _, ULib.ACCESS_ADMIN ) end timer.Create( "votegagtimer", 60, 0, function() for k,v in pairs( player.GetAll() ) do if ( v:GetPData( "votegagged" ) and v:GetPData( "votegagged" ) ~= 0 and v:GetPData( "votegagged" ) ~= "0" ) then if ( tonumber( v:GetPData( "votegagged" ) ) - 1 == 0 ) then ulx.fancyLogAdmin( v, "#T was auto-ungagged" ) end v:SetPData( "votegagged", tonumber( v:GetPData( "votegagged" ) ) - 1 ) end end end ) function ulx.unvotegag( calling_ply, target_plys ) for k,v in pairs( target_plys ) do if ( v:GetPData( "votegagged" ) and v:GetPData( "votegagged" ) ~= 0 and v:GetPData( "votegagged" ) ~= "0" ) then v:RemovePData( "votegagged" ) ulx.fancyLogAdmin( calling_ply, "#A ungagged #T", target_plys ) else ULib.tsayError( calling_ply, v:Nick() .. " is not gagged." ) end end end local unvotegag = ulx.command( "Voting", "ulx unvotegag", ulx.unvotegag, "!unvotegag" ) unvotegag:addParam{ type=ULib.cmds.PlayersArg } unvotegag:defaultAccess( ULib.ACCESS_ADMIN ) unvotegag:help( "Ungag the player" ) local function ulxvotegaghook( listener, talker ) if ( talker:GetPData( "votegagged" ) and talker:GetPData( "votegagged" ) == "true" ) then return false end end hook.Add("PlayerCanHearPlayersVoice", "ulxvotegaghooks", ulxvotegaghook )