Advertisement
Frankess

sh_advsboxlimits

Jan 14th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.39 KB | None | 0 0
  1. local PLUGIN = {}
  2. PLUGIN.Title = "Advanced Sbox Limits";
  3. PLUGIN.Description = "";
  4. PLUGIN.ChatCommand = "!setlimit"
  5. PLUGIN.Usage = '<rank> <limit>'
  6. PLUGIN.Author = "Frankess";
  7. EV_AP_LIMITS = (util.JSONToTable(file.Read("ev_limits.txt","DATA") or "") or {})
  8.  
  9. local function GetClass(str)
  10.         if str == "prop_physics" then return "prop" end
  11.         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
  12.         if str == "acf_gun" then return "_acf_gun" end
  13.         if str == "acf_ammo" then return "_acf_ammo" end
  14.         if str == "acf_gearbox" then return "_acf_Gearbox" end
  15.         if str == "acf_engine" then return "_acf_engine" end
  16.         return str
  17. end
  18.  
  19. function PLUGIN:Call( ply, args )
  20.     RunConsoleCommand("ev_setlimit", args)
  21. end
  22.  
  23. function PLUGIN:CanTool(ply, tr, mode)
  24.     if (mode == "adv_duplicator" or mode == "duplicator" or mode == "advdupe2") then
  25.         if ply:KeyDown(IN_ATTACK) then
  26.             if mode == "adv_duplicator" and ply:GetActiveWeapon():GetToolObject().Entities then
  27.                 local limits = {}
  28.                 for k,v in pairs(ply:GetActiveWeapon():GetToolObject().Entities) do
  29.                     if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()][Class] then
  30.                         if not limits[v.Class] then limits[v.Class] = 1 else
  31.                             limits[v.Class] = limits[v.Class] + 1
  32.                         end
  33.                         if (ply:GetCount(v.Class.."s") + limits[v.Class]) > EV_AP_LIMITS[ply:EV_GetRank()][v.Class] then
  34.                             evolve:Notify( ply, evolve.colors.red, "With this dupe you will reach "..v.Class.." limit!" )
  35.                             return false
  36.                         end
  37.                     end
  38.                 end
  39.             end
  40.  
  41.             if mode == "advdupe2" and ply.AdvDupe2 and ply.AdvDupe2.Entities then
  42.                 local limits = {}
  43.                 for k,v in pairs(ply.AdvDupe2.Entities) do
  44.                     local Class = GetClass(v.Class)
  45.                     if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()][Class] then
  46.                         if not limits[Class] then
  47.                             limits[Class] = 1
  48.                         else
  49.                             limits[Class] = limits[Class] + 1
  50.                         end
  51.                         if (ply:GetCount(Class.."s") + limits[Class]) > EV_AP_LIMITS[ply:EV_GetRank()][Class] then
  52.                             evolve:Notify( ply, evolve.colors.red, "With this dupe you will reach "..Class.." limit!" )
  53.                             return false
  54.                         end
  55.                     end
  56.                 end
  57.             end
  58.         end
  59.     end
  60. end
  61.    
  62.  
  63. /*-------------------------------------------------------------------------------------------------------------------------
  64.         Limits Handling
  65. --------------------------------------------------------------------------------------------------------------------------*/
  66.  
  67. function PLUGIN:PlayerSpawnProp(ply, model)
  68.     if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].prop then
  69.         local Count = ply:GetCount("props")
  70.         local Limit = EV_AP_LIMITS[ply:EV_GetRank()].prop
  71.         if Count >= Limit then
  72.             evolve:Notify( ply, evolve.colors.red, "You have reached prop limit!" )
  73.             return false
  74.         end
  75.     end
  76. end
  77.  
  78. function PLUGIN:PlayerSpawnSENT(ply, class)
  79.     if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].sent then
  80.         local Count = ply:GetCount( "sents" )
  81.         local Limit = EV_AP_LIMITS[ply:EV_GetRank()].sent
  82.        
  83.         if Count>=Limit then
  84.             evolve:Notify( ply, evolve.colors.red, "You have reached SENT limit!" )
  85.             return false
  86.         end
  87.     end
  88. end
  89.  
  90. function PLUGIN:PlayerSpawnNPC(ply, npc)
  91.     if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].npc then
  92.         local Count = ply:GetCount( "npcs" )
  93.         local Limit = EV_AP_LIMITS[ply:EV_GetRank()].npc
  94.        
  95.         if Count>=Limit then
  96.             evolve:Notify( ply, evolve.colors.red, "You have reached NPC limit!" )
  97.             return false
  98.         end
  99.     end
  100. end
  101.  
  102. function PLUGIN:PlayerSpawnVehicle(ply, class)
  103.     if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].vehicle then
  104.         local Count = ply:GetCount( "vehicles" )
  105.         local Limit = EV_AP_LIMITS[ply:EV_GetRank()].vehicle
  106.        
  107.         if Count>=Limit then
  108.             evolve:Notify( ply, evolve.colors.red, "You have reached vehicle limit!" )
  109.             return false
  110.         end
  111.     end
  112. end
  113.  
  114. function PLUGIN:PlayerSpawnEffect(ply, model)
  115.     if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].effect then
  116.         local Count = ply:GetCount( "effects" )
  117.         local Limit = EV_AP_LIMITS[ply:EV_GetRank()].effect
  118.        
  119.         if Count>=Limit then
  120.             evolve:Notify( ply, evolve.colors.red, "You have reached effect limit!" )
  121.             return false
  122.         end
  123.     end
  124. end
  125.  
  126. function PLUGIN:PlayerSpawnRagdoll(ply, model)
  127.     if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].ragdoll then
  128.         local Count = ply:GetCount( "ragdolls" )
  129.         local Limit = EV_AP_LIMITS[ply:EV_GetRank()].ragdoll
  130.        
  131.         if Count>=Limit then
  132.             evolve:Notify( ply, evolve.colors.red, "You have reached ragdoll limit!" )
  133.             return false
  134.         end
  135.     end
  136. end
  137.  
  138. if(EV_func_Player.AddCount) then
  139.     local backupAddCount = EV_func_Player.AddCount
  140.        
  141.     function EV_func_Player:AddCount(enttype, ent)
  142.         local function Return()
  143.             backupAddCount(self, enttype, ent)
  144.             return
  145.         end
  146.            
  147.         local ply = self
  148.         if enttype == "_acf_gun" then
  149.             if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].acfgun  then
  150.                 local Count = ply:GetCount("_acf_gun")
  151.                 local Limit = EV_AP_LIMITS[ply:EV_GetRank()].acfgun
  152.                
  153.                 if Count>=Limit then
  154.                     evolve:Notify( ply, evolve.colors.red, "You have reached acf gun limit!" )
  155.                     ent:Remove()
  156.                     Return()
  157.                 end
  158.             end
  159.         elseif enttype == "_acf_ammo" then
  160.             if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].acfammo then
  161.                 local Count = ply:GetCount("_acf_ammo")
  162.                 local Limit = EV_AP_LIMITS[ply:EV_GetRank()].acfammo
  163.                
  164.                 if Count>=Limit then
  165.                     evolve:Notify( ply, evolve.colors.red, "You have reached acf ammo limit!" )
  166.                     ent:Remove()
  167.                     Return()
  168.                 end
  169.             end
  170.         elseif enttype == "_acf_engine" then
  171.             if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].acfengine then
  172.                 local Count = ply:GetCount("_acf_engine")
  173.                 local Limit = EV_AP_LIMITS[ply:EV_GetRank()].acfengine
  174.                    
  175.                 if Count>=Limit then
  176.                     evolve:Notify( ply, evolve.colors.red, "You have reached acf engine limit!" )
  177.                     ent:Remove()
  178.                     Return()
  179.                 end
  180.             end
  181.         elseif enttype == "_acf_Gearbox" then
  182.             if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].acfgearbox then
  183.                 local Count = ply:GetCount("_acf_Gearbox")
  184.                 local Limit = EV_AP_LIMITS[ply:EV_GetRank()].acfgearbox
  185.                 if Count>=Limit then
  186.                     evolve:Notify( ply, evolve.colors.red, "You have reached acf gearbox limit!" )
  187.                     ent:Remove()
  188.                     Return()
  189.                 end
  190.             end
  191.         elseif not (enttype == "props" or enttype == "sents" or enttype == "npcs" or enttype == "vehicles" or enttype == "effects" or enttype == "ragdolls") then
  192.             if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()][enttype] then
  193.                 local Count = ply:GetCount(enttype)
  194.                 local Limit = EV_AP_LIMITS[ply:EV_GetRank()][enttype]
  195.                    
  196.                 if Count>=Limit then
  197.                     evolve:Notify( ply, evolve.colors.red, "You have reached "..enttype.."  limit!" )
  198.                     ent:Remove()
  199.                     Return()
  200.                 end
  201.             end
  202.         end
  203.         ent.EV_Owner = ply:UniqueID()
  204.         Return()
  205.     end
  206. end
  207.  
  208. /*-------------------------------------------------------------------------------------------------------------------------
  209.     Commands
  210. -------------------------------------------------------------------------------------------------------------------------*/
  211. concommand.Add("ev_setlimit",function(ply, cmd, args)
  212.     if ply:EV_HasPrivilege( "Set limits" ) then
  213.         local Rank = args[1]
  214.         local Limit = args[2]
  215.         local Amount = args[3]
  216.         if not evolve.ranks[ Rank ] then
  217.             evolve:Notify( ply, evolve.colors.red, "There is no such rank!" )
  218.             return
  219.         end
  220.         if not Limit then
  221.             evolve:Notify( ply, evolve.colors.red, "You need to specify what to limit!" )
  222.             return
  223.         end
  224.         if not Amount then
  225.             evolve:Notify( ply, evolve.colors.red, "You need to limit amount!" )
  226.             return
  227.         end
  228.                
  229.         if not EV_AP_LIMITS[Rank] then EV_AP_LIMITS[Rank] = {} end
  230.             EV_AP_LIMITS[Rank][Limit] = tonumber(Amount)
  231.                
  232.             evolve:Notify( evolve.colors.blue, evolve.ranks[ Rank ].Title, evolve.colors.white, " limit of ", evolve.colors.blue , Limit.."s", evolve.colors.white, " has been changed to ", evolve.colors.red, Amount )
  233.             file.Write("ev_limits.txt", util.TableToJSON(EV_AP_LIMITS))
  234.         else
  235.             evolve:Notify( ply, evolve.colors.red, evolve.constants.notallowed )
  236.         end
  237.     end, function( commandName, args )
  238.         return {"ev_setlimit <rank> <what> <limit>"}
  239. end)
  240.  
  241. evolve:RegisterPlugin( PLUGIN )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement