Advertisement
Frankess

sh_countstuff

Jan 14th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.03 KB | None | 0 0
  1. local PLUGIN = {}
  2. PLUGIN.Title = "Count Stuff"
  3. PLUGIN.Description = "Counts stuff on map."
  4. PLUGIN.Author = "Frankess"
  5. PLUGIN.ChatCommand = "count"
  6. PLUGIN.Usage = '<player> / nothing to show your props'
  7. PLUGIN.Privileges = { "Count" }
  8.  
  9. if SERVER then
  10.     util.AddNetworkString( "EV_countstream" )
  11. end
  12.  
  13. local function GetClass(str)
  14.         if str == "prop_physics" then return "prop" end
  15.         if str == "prop_vehicle_prisoner_pod" or str == "prop_vehicle_jeep" or str == "prop_vehicle_jeep_old" or str == "prop_vehicle_airboat" then return "vehicle" end
  16.         if str == "acf_gun" then return "_acf_gun" end
  17.         if str == "acf_ammo" then return "_acf_ammo" end
  18.         if str == "acf_gearbox" then return "_acf_Gearbox" end
  19.         if str == "acf_engine" then return "_acf_engine" end
  20.         return str
  21. end
  22.  
  23. function PLUGIN:BuildTable()
  24.     local Table = {}
  25.     for _,v in pairs (ents.GetAll()) do
  26.         if v.Owner and IsValid(v.Owner)then
  27.             local ply = v.Owner
  28.             local SteamID = ply:UserID()
  29.             if not Table[SteamID] then Table[SteamID] = {} end
  30.             if not Table[SteamID][v:GetClass()] then
  31.                 Table[SteamID][v:GetClass()] = 1
  32.             else
  33.                 Table[SteamID][v:GetClass()] = Table[SteamID][v:GetClass()] + 1
  34.             end
  35.         end
  36.     end
  37.     return Table
  38. end
  39.  
  40. function PLUGIN:BuildDupeTable( Tbl )
  41.     local Table = {}
  42.     for _,v in pairs ( Tbl ) do
  43.         if not Table[v.Class] then
  44.             Table[v.Class] = 1
  45.         else
  46.             Table[v.Class] = Table[v.Class] + 1
  47.         end
  48.     end
  49.     return Table
  50. end
  51.  
  52.  
  53. function PLUGIN:BuildString(ply, Table )
  54.     local str = "#############################\n"..ply:Nick()..":\n#class: count / limit (-1 or 0 = unlimited) \n#"
  55.     for name,count in pairs(Table) do
  56.         if EV_AP_LIMITS[ply:EV_GetRank()] then
  57.             local Class = GetClass(name)
  58.             if  EV_AP_LIMITS[ply:EV_GetRank()][Class] then
  59.                 str = str..name..": "..tostring(count).." / "..EV_AP_LIMITS[ply:EV_GetRank()][Class].."\n#"
  60.             else
  61.                 local Limit = GetConVarNumber("sbox_max"..Class.."s")
  62.                 if string.Left(Class,9)=="gmod_wire" then Limit = GetConVarNumber("sbox_maxwire"..string.sub(Class,10,9999999).."s") end
  63.                 str = str..name..": "..tostring(count).." / "..Limit.."\n#"
  64.             end
  65.         else
  66.             str = str..name..": "..tostring(count).."\n#"
  67.         end
  68.     end
  69.     str = str.."############################\n"
  70.     return str
  71. end
  72.  
  73. function PLUGIN:Call( ply, args )
  74.     if #args>0 then
  75.         local target = evolve:FindPlayer( args[1], nil, false, false )[1]
  76.        
  77.         if not target then
  78.             evolve:Notify( ply, evolve.colors.red, evolve.constants.noplayersnoimmunity )
  79.             return
  80.         end
  81.        
  82.         local Table = self:BuildTable()
  83.         local Str = self:BuildString(target, Table[target:UserID()] )
  84.        
  85.         if IsValid(ply) then
  86.             net.Start ("EV_countstream")
  87.                 net.WriteString(Str)
  88.             net.Send( ply )
  89.             evolve:Notify( ply, evolve.colors.white, "list was send to your console")
  90.         else
  91.             Msg(Str)
  92.         end
  93.     else
  94.         if ply and IsValid(ply) and ply:GetActiveWeapon().Mode and ply:GetActiveWeapon():GetMode() == "advdupe2" and ply.AdvDupe2.Entities then
  95.             local Table = self:BuildDupeTable( ply.AdvDupe2.Entities )
  96.             local Str = self:BuildString(ply, Table )
  97.             net.Start ("EV_countstream")
  98.                 net.WriteString(Str)
  99.             net.Send( ply )
  100.             evolve:Notify( ply, evolve.colors.white, "list was send to your console")
  101.             return
  102.         end
  103.         if ( ply:EV_HasPrivilege( "Count" ) ) then
  104.             Table = self:BuildTable()
  105.             local Str = ""
  106.             for _,v in pairs (player.GetAll()) do
  107.                 local Str = self:BuildString(v, Table[v:UserID()] )
  108.                 if IsValid(ply) then
  109.                     net.Start ("EV_countstream")
  110.                         net.WriteString(Str)
  111.                     net.Send( ply )
  112.                 else
  113.                     Msg(Str)
  114.                 end
  115.             end
  116.             evolve:Notify( ply, evolve.colors.white, "list was send to your console")
  117.            
  118.         else
  119.             local Table = self:BuildTable()
  120.             local Str = self:BuildString(ply, Table[ply:UserID()] )
  121.            
  122.             net.Start ("EV_countstream")
  123.                 net.WriteString(Str)
  124.             net.Send( ply )
  125.             evolve:Notify( ply, evolve.colors.white, "list was send to your console")
  126.         end
  127.     end
  128. end
  129.  
  130. if CLIENT then
  131.     net.Receive( "EV_countstream", function()
  132.         print(net:ReadString())
  133.     end)
  134. end
  135.  
  136. evolve:RegisterPlugin( PLUGIN )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement