Advertisement
Guest User

cl_printColorAll.lua

a guest
Jul 17th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.04 KB | None | 0 0
  1. local BlockedPlayers = {}
  2.  
  3. local function filterList(list, criterion)
  4.     local index = 1
  5.  
  6.     while index <= #list do
  7.         if not criterion(list[index]) then
  8.             list[index] = list[#list]
  9.             table.remove(list)
  10.         else
  11.             index = index + 1
  12.         end
  13.     end
  14.  
  15.     return list
  16. end
  17.  
  18. local function block ( ply, com, args )
  19.     if not args[1] then
  20.         MsgN( ply, "Command requires a player's name (or part of their name)" )
  21.         MsgN( ply, "Usage: wire_expression2_printColorAll_block [name]" )
  22.         return
  23.     end
  24.  
  25.     local name = args[1]:lower()
  26.     local players = filterList(player.GetAll(), function(ent) return ent:GetName():lower():match(name) end)
  27.    
  28.     if #players == 1 then
  29.         local v = players[1]
  30.         if v == LocalPlayer() then
  31.             MsgN( ply, " You cant block yourself!" )
  32.         elseif BlockedPlayers[v:SteamID()] == true then
  33.             MsgN( ply, v:GetName() .. " is already in the blocklist!" )
  34.         else
  35.             BlockedPlayers[v:SteamID()] = true
  36.         end
  37.     elseif #players > 1 then
  38.         MsgN( ply, "More than one player matches that name!" )
  39.     else
  40.         MsgN( ply, "No player names found with " .. args[1] )
  41.     end
  42. end
  43.  
  44. local function autocomplete_block()
  45.     local list = {}
  46.         for _,ply in ipairs(player.GetAll()) do
  47.             if not BlockedPlayers[ply:SteamID()] and ply ~= LocalPlayer() then
  48.                 table.insert(list, "wire_expression2_printColorAll_block \""..ply:Name().."\"")
  49.             end
  50.         end
  51.         table.sort(list)
  52.     return list
  53. end
  54.  
  55. local function unblock ( ply, com, args )
  56.     if not args[1] then
  57.         MsgN( ply, "Command requires a player's name (or part of their name)" )
  58.         MsgN( ply, "Usage: wire_expression2_printColorAll_unblock [name]" )
  59.         return
  60.     end
  61.  
  62.     local name = args[1]:lower()
  63.     local players = filterList(player.GetAll(), function(ent) return ent:GetName():lower():match(name) end)
  64.  
  65.     if #players == 1 then
  66.         local v = players[1]
  67.         if v == LocalPlayer() then
  68.             MsgN( ply, " You cant even block yourself!" )
  69.         elseif BlockedPlayers[v:SteamID()] == true then
  70.             BlockedPlayers[v:SteamID()] = nil
  71.         else
  72.             MsgN( ply, v:GetName() .. " is not in the blocklist!" )
  73.         end
  74.     elseif #players > 1 then
  75.         MsgN( ply, "More than one player matches that name!" )
  76.     else
  77.         MsgN( ply, "No player names found with " .. args[1] )
  78.     end
  79. end
  80.  
  81. local function autocomplete_unblock()
  82.     local list = {}
  83.         for _,ply in ipairs(player.GetAll()) do
  84.             if BlockedPlayers[ply:SteamID()] and ply ~= LocalPlayer() then
  85.                 table.insert(list, "wire_expression2_printColorAll_unblock \""..ply:Name().."\"")
  86.             end
  87.         end
  88.         table.sort(list)
  89.     return list
  90. end
  91.  
  92. local function block_id ( ply, com, args )
  93.     if not args[1] then
  94.         MsgN( ply, "Command requires a player's userID or SteamID" )
  95.         MsgN( ply, "Usage: wire_expression2_printColorAll_block_id [UserID or SteamID]" )
  96.         return
  97.     end
  98.  
  99.     local id = tonumber(args[1])
  100.     local players = filterList(player.GetAll(), function(ent) return ent:UserID() == id end)
  101.     if #players == 0 then
  102.         id = table.concat(args) id = string.Replace(table.concat(args)," ","")
  103.         players = filterList(player.GetAll(), function(ent) return ent:SteamID() == id end)
  104.     end
  105.    
  106.     if #players == 1 then
  107.         local v = players[1]
  108.         if v == LocalPlayer() then
  109.             MsgN( ply, " You cant block yourself!" )
  110.         elseif BlockedPlayers[v:SteamID()] == true then
  111.             MsgN( ply, v:GetName() .. " is already in the blocklist!" )
  112.         else
  113.             BlockedPlayers[v:SteamID()] = true
  114.         end
  115.     else
  116.         MsgN( ply, "No player found with userID or SteamID: " .. args[1] )
  117.     end
  118. end
  119.  
  120. local function unblock_id ( ply, com, args )
  121.     if not args[1] then
  122.         MsgN( ply, "Command requires a player's userID or SteamID" )
  123.         MsgN( ply, "Usage: wire_expression2_printColorAll_unblock_id [UserID or SteamID]" )
  124.         return
  125.     end
  126.  
  127.     local id = tonumber(args[1])
  128.     local players = filterList(player.GetAll(), function(ent) return ent:UserID() == id end)
  129.     if #players == 0 then
  130.         id = table.concat(args)
  131.         players = filterList(player.GetAll(), function(ent) return ent:SteamID() == id end)
  132.     end
  133.  
  134.     if #players == 1 then
  135.         local v = players[1]
  136.         if v == LocalPlayer() then
  137.             MsgN( ply, " You cant even block yourself!" )
  138.         elseif BlockedPlayers[v:SteamID()] == true then
  139.             BlockedPlayers[v:SteamID()] = nil
  140.         else
  141.             MsgN( ply, v:GetName() .. " is not in the blocklist!" )
  142.         end
  143.     else
  144.         MsgN( ply, "No player found with userID or SteamID: " .. args[1] )
  145.     end
  146. end
  147.  
  148. concommand.Add( "wire_expression2_printColorAll_block" ,block ,autocomplete_block)
  149. concommand.Add( "wire_expression2_printColorAll_unblock" ,unblock ,autocomplete_unblock)
  150. concommand.Add( "wire_expression2_printColorAll_block_id" ,block_id)
  151. concommand.Add( "wire_expression2_printColorAll_unblock_id" ,unblock_id)
  152.  
  153. local antispam = CreateClientConVar( "wire_expression2_printColorAll_antispam_enabled", 1, true ,false )
  154. local autoblock = CreateClientConVar( "wire_expression2_printColorAll_antispam_autoblock", 0, true ,false )
  155. local interval = CreateClientConVar( "wire_expression2_printColorAll_antispam_checkinterval", 1, true ,false )
  156. local maxmessages = CreateClientConVar( "wire_expression2_printColorAll_antispam_max_messages", 6, true ,false )
  157.  
  158. net.Receive("wire_expression2_printColorAll", function( len, ply )
  159.     local Chip = net.ReadEntity()
  160.     printinfo = net.ReadTable()
  161.     Sender = printinfo.sender
  162.    
  163.     if BlockedPlayers[Sender:SteamID()] == true then return end
  164.    
  165.     local LName = Sender:GetName()
  166.     if string.len(LName) > 13 then
  167.         LName = string.sub(Sender:GetName(),1,10).."..."
  168.     end
  169.    
  170.     if antispam:GetInt() == 1 and maxmessages:GetInt() > 0 then
  171.         local lastsend = Sender.lastsend or 0
  172.         local sends = Sender.sends or 1
  173.         local wasignored = Sender.igno or 0
  174.         local max = maxmessages:GetInt()
  175.         if (CurTime()-lastsend) < interval:GetInt() then
  176.             Sender.sends = sends + 1
  177.         else
  178.             Sender.lastsend = CurTime()
  179.             if wasignored == 0 or (CurTime()-lastsend) > (interval:GetInt()+(interval:GetInt()/max)) then
  180.                 Sender.igno = 0
  181.                 Sender.sends = 1
  182.             elseif wasignored == 1 then
  183.                 Sender.igno = 0
  184.                 Sender.sends = max
  185.             end
  186.         end
  187.         if Sender.sends > max then -- Sender ~=
  188.             if autoblock:GetInt() == 1 and max > 0 and Sender != LocalPlayer() then
  189.                 BlockedPlayers[Sender:SteamID()] = true
  190.                 chat.AddText(Color(255,0,0),"[Antispam] Blocked: ",Color(255,150,0),Sender:GetName())
  191.                 MsgN(" -unblock him/her by using 'wire_expression2_printColorAll_unblock "..Sender:GetName().."'")
  192.             end
  193.             Sender.igno = 1        
  194.         else
  195.             Msg("## E2["..tostring(Chip:EntIndex()).."] from Player "..tostring(Sender:UserID()).." '"..LName.."' "..tostring(Sender:SteamID()).."  --> ")
  196.             chat.AddText(unpack(printinfo))
  197.         end
  198.     else
  199.         Msg("## E2["..tostring(Chip:EntIndex()).."] from Player "..tostring(Sender:UserID()).." '"..LName.."' "..tostring(Sender:SteamID()).."  --> ")
  200.         chat.AddText(unpack(printinfo))
  201.     end
  202. end)
  203.  
  204. E2Helper.Descriptions["printColorAll"] = "Prints a message to all players. (to prevent fakemessages from players you can see in the console who made it)"
  205. E2Helper.Descriptions["printColorAllReady"] = "Returns whether or not you can use printColorAll(r)."
  206. 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