Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local BlockedPlayers = {}
- local function filterList(list, criterion)
- local index = 1
- while index <= #list do
- if not criterion(list[index]) then
- list[index] = list[#list]
- table.remove(list)
- else
- index = index + 1
- end
- end
- return list
- end
- local function block ( ply, com, args )
- if not args[1] then
- MsgN( ply, "Command requires a player's name (or part of their name)" )
- MsgN( ply, "Usage: wire_expression2_printColorAll_block [name]" )
- return
- end
- local name = args[1]:lower()
- local players = filterList(player.GetAll(), function(ent) return ent:GetName():lower():match(name) end)
- if #players == 1 then
- local v = players[1]
- if v == LocalPlayer() then
- MsgN( ply, " You cant block yourself!" )
- elseif BlockedPlayers[v:SteamID()] == true then
- MsgN( ply, v:GetName() .. " is already in the blocklist!" )
- else
- BlockedPlayers[v:SteamID()] = true
- end
- elseif #players > 1 then
- MsgN( ply, "More than one player matches that name!" )
- else
- MsgN( ply, "No player names found with " .. args[1] )
- end
- end
- local function autocomplete_block()
- local list = {}
- for _,ply in ipairs(player.GetAll()) do
- if not BlockedPlayers[ply:SteamID()] and ply ~= LocalPlayer() then
- table.insert(list, "wire_expression2_printColorAll_block \""..ply:Name().."\"")
- end
- end
- table.sort(list)
- return list
- end
- local function unblock ( ply, com, args )
- if not args[1] then
- MsgN( ply, "Command requires a player's name (or part of their name)" )
- MsgN( ply, "Usage: wire_expression2_printColorAll_unblock [name]" )
- return
- end
- local name = args[1]:lower()
- local players = filterList(player.GetAll(), function(ent) return ent:GetName():lower():match(name) end)
- if #players == 1 then
- local v = players[1]
- if v == LocalPlayer() then
- MsgN( ply, " You cant even block yourself!" )
- elseif BlockedPlayers[v:SteamID()] == true then
- BlockedPlayers[v:SteamID()] = nil
- else
- MsgN( ply, v:GetName() .. " is not in the blocklist!" )
- end
- elseif #players > 1 then
- MsgN( ply, "More than one player matches that name!" )
- else
- MsgN( ply, "No player names found with " .. args[1] )
- end
- end
- local function autocomplete_unblock()
- local list = {}
- for _,ply in ipairs(player.GetAll()) do
- if BlockedPlayers[ply:SteamID()] and ply ~= LocalPlayer() then
- table.insert(list, "wire_expression2_printColorAll_unblock \""..ply:Name().."\"")
- end
- end
- table.sort(list)
- return list
- end
- local function block_id ( ply, com, args )
- if not args[1] then
- MsgN( ply, "Command requires a player's userID or SteamID" )
- MsgN( ply, "Usage: wire_expression2_printColorAll_block_id [UserID or SteamID]" )
- return
- end
- local id = tonumber(args[1])
- local players = filterList(player.GetAll(), function(ent) return ent:UserID() == id end)
- if #players == 0 then
- id = table.concat(args) id = string.Replace(table.concat(args)," ","")
- players = filterList(player.GetAll(), function(ent) return ent:SteamID() == id end)
- end
- if #players == 1 then
- local v = players[1]
- if v == LocalPlayer() then
- MsgN( ply, " You cant block yourself!" )
- elseif BlockedPlayers[v:SteamID()] == true then
- MsgN( ply, v:GetName() .. " is already in the blocklist!" )
- else
- BlockedPlayers[v:SteamID()] = true
- end
- else
- MsgN( ply, "No player found with userID or SteamID: " .. args[1] )
- end
- end
- local function unblock_id ( ply, com, args )
- if not args[1] then
- MsgN( ply, "Command requires a player's userID or SteamID" )
- MsgN( ply, "Usage: wire_expression2_printColorAll_unblock_id [UserID or SteamID]" )
- return
- end
- local id = tonumber(args[1])
- local players = filterList(player.GetAll(), function(ent) return ent:UserID() == id end)
- if #players == 0 then
- id = table.concat(args)
- players = filterList(player.GetAll(), function(ent) return ent:SteamID() == id end)
- end
- if #players == 1 then
- local v = players[1]
- if v == LocalPlayer() then
- MsgN( ply, " You cant even block yourself!" )
- elseif BlockedPlayers[v:SteamID()] == true then
- BlockedPlayers[v:SteamID()] = nil
- else
- MsgN( ply, v:GetName() .. " is not in the blocklist!" )
- end
- else
- MsgN( ply, "No player found with userID or SteamID: " .. args[1] )
- end
- end
- concommand.Add( "wire_expression2_printColorAll_block" ,block ,autocomplete_block)
- concommand.Add( "wire_expression2_printColorAll_unblock" ,unblock ,autocomplete_unblock)
- concommand.Add( "wire_expression2_printColorAll_block_id" ,block_id)
- concommand.Add( "wire_expression2_printColorAll_unblock_id" ,unblock_id)
- local antispam = CreateClientConVar( "wire_expression2_printColorAll_antispam_enabled", 1, true ,false )
- local autoblock = CreateClientConVar( "wire_expression2_printColorAll_antispam_autoblock", 0, true ,false )
- local interval = CreateClientConVar( "wire_expression2_printColorAll_antispam_checkinterval", 1, true ,false )
- local maxmessages = CreateClientConVar( "wire_expression2_printColorAll_antispam_max_messages", 6, true ,false )
- net.Receive("wire_expression2_printColorAll", function( len, ply )
- local Chip = net.ReadEntity()
- printinfo = net.ReadTable()
- Sender = printinfo.sender
- if BlockedPlayers[Sender:SteamID()] == true then return end
- local LName = Sender:GetName()
- if string.len(LName) > 13 then
- LName = string.sub(Sender:GetName(),1,10).."..."
- end
- if antispam:GetInt() == 1 and maxmessages:GetInt() > 0 then
- local lastsend = Sender.lastsend or 0
- local sends = Sender.sends or 1
- local wasignored = Sender.igno or 0
- local max = maxmessages:GetInt()
- if (CurTime()-lastsend) < interval:GetInt() then
- Sender.sends = sends + 1
- else
- Sender.lastsend = CurTime()
- if wasignored == 0 or (CurTime()-lastsend) > (interval:GetInt()+(interval:GetInt()/max)) then
- Sender.igno = 0
- Sender.sends = 1
- elseif wasignored == 1 then
- Sender.igno = 0
- Sender.sends = max
- end
- end
- if Sender.sends > max then -- Sender ~=
- if autoblock:GetInt() == 1 and max > 0 and Sender != LocalPlayer() then
- BlockedPlayers[Sender:SteamID()] = true
- chat.AddText(Color(255,0,0),"[Antispam] Blocked: ",Color(255,150,0),Sender:GetName())
- MsgN(" -unblock him/her by using 'wire_expression2_printColorAll_unblock "..Sender:GetName().."'")
- end
- Sender.igno = 1
- else
- Msg("## E2["..tostring(Chip:EntIndex()).."] from Player "..tostring(Sender:UserID()).." '"..LName.."' "..tostring(Sender:SteamID()).." --> ")
- chat.AddText(unpack(printinfo))
- end
- else
- Msg("## E2["..tostring(Chip:EntIndex()).."] from Player "..tostring(Sender:UserID()).." '"..LName.."' "..tostring(Sender:SteamID()).." --> ")
- chat.AddText(unpack(printinfo))
- end
- end)
- E2Helper.Descriptions["printColorAll"] = "Prints a message to all players. (to prevent fakemessages from players you can see in the console who made it)"
- E2Helper.Descriptions["printColorAllReady"] = "Returns whether or not you can use printColorAll(r)."
- E2Helper.Descriptions["printColorAllDelay"] = "Returns the period of time that must be between two printColorAll(r) functions."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement