Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local PLUGIN = {}
- PLUGIN.Title = "Advanced Sbox Limits";
- PLUGIN.Description = "";
- PLUGIN.ChatCommand = "!setlimit"
- PLUGIN.Usage = '<rank> <limit>'
- PLUGIN.Author = "Frankess";
- EV_AP_LIMITS = (util.JSONToTable(file.Read("ev_limits.txt","DATA") or "") or {})
- local function GetClass(str)
- if str == "prop_physics" then return "prop" end
- 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
- if str == "acf_gun" then return "_acf_gun" end
- if str == "acf_ammo" then return "_acf_ammo" end
- if str == "acf_gearbox" then return "_acf_Gearbox" end
- if str == "acf_engine" then return "_acf_engine" end
- return str
- end
- function PLUGIN:Call( ply, args )
- RunConsoleCommand("ev_setlimit", args)
- end
- function PLUGIN:CanTool(ply, tr, mode)
- if (mode == "adv_duplicator" or mode == "duplicator" or mode == "advdupe2") then
- if ply:KeyDown(IN_ATTACK) then
- if mode == "adv_duplicator" and ply:GetActiveWeapon():GetToolObject().Entities then
- local limits = {}
- for k,v in pairs(ply:GetActiveWeapon():GetToolObject().Entities) do
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()][Class] then
- if not limits[v.Class] then limits[v.Class] = 1 else
- limits[v.Class] = limits[v.Class] + 1
- end
- if (ply:GetCount(v.Class.."s") + limits[v.Class]) > EV_AP_LIMITS[ply:EV_GetRank()][v.Class] then
- evolve:Notify( ply, evolve.colors.red, "With this dupe you will reach "..v.Class.." limit!" )
- return false
- end
- end
- end
- end
- if mode == "advdupe2" and ply.AdvDupe2 and ply.AdvDupe2.Entities then
- local limits = {}
- for k,v in pairs(ply.AdvDupe2.Entities) do
- local Class = GetClass(v.Class)
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()][Class] then
- if not limits[Class] then
- limits[Class] = 1
- else
- limits[Class] = limits[Class] + 1
- end
- if (ply:GetCount(Class.."s") + limits[Class]) > EV_AP_LIMITS[ply:EV_GetRank()][Class] then
- evolve:Notify( ply, evolve.colors.red, "With this dupe you will reach "..Class.." limit!" )
- return false
- end
- end
- end
- end
- end
- end
- end
- /*-------------------------------------------------------------------------------------------------------------------------
- Limits Handling
- --------------------------------------------------------------------------------------------------------------------------*/
- function PLUGIN:PlayerSpawnProp(ply, model)
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].prop then
- local Count = ply:GetCount("props")
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()].prop
- if Count >= Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached prop limit!" )
- return false
- end
- end
- end
- function PLUGIN:PlayerSpawnSENT(ply, class)
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].sent then
- local Count = ply:GetCount( "sents" )
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()].sent
- if Count>=Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached SENT limit!" )
- return false
- end
- end
- end
- function PLUGIN:PlayerSpawnNPC(ply, npc)
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].npc then
- local Count = ply:GetCount( "npcs" )
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()].npc
- if Count>=Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached NPC limit!" )
- return false
- end
- end
- end
- function PLUGIN:PlayerSpawnVehicle(ply, class)
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].vehicle then
- local Count = ply:GetCount( "vehicles" )
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()].vehicle
- if Count>=Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached vehicle limit!" )
- return false
- end
- end
- end
- function PLUGIN:PlayerSpawnEffect(ply, model)
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].effect then
- local Count = ply:GetCount( "effects" )
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()].effect
- if Count>=Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached effect limit!" )
- return false
- end
- end
- end
- function PLUGIN:PlayerSpawnRagdoll(ply, model)
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].ragdoll then
- local Count = ply:GetCount( "ragdolls" )
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()].ragdoll
- if Count>=Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached ragdoll limit!" )
- return false
- end
- end
- end
- if(EV_func_Player.AddCount) then
- local backupAddCount = EV_func_Player.AddCount
- function EV_func_Player:AddCount(enttype, ent)
- local function Return()
- backupAddCount(self, enttype, ent)
- return
- end
- local ply = self
- if enttype == "_acf_gun" then
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].acfgun then
- local Count = ply:GetCount("_acf_gun")
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()].acfgun
- if Count>=Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached acf gun limit!" )
- ent:Remove()
- Return()
- end
- end
- elseif enttype == "_acf_ammo" then
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].acfammo then
- local Count = ply:GetCount("_acf_ammo")
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()].acfammo
- if Count>=Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached acf ammo limit!" )
- ent:Remove()
- Return()
- end
- end
- elseif enttype == "_acf_engine" then
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].acfengine then
- local Count = ply:GetCount("_acf_engine")
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()].acfengine
- if Count>=Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached acf engine limit!" )
- ent:Remove()
- Return()
- end
- end
- elseif enttype == "_acf_Gearbox" then
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()].acfgearbox then
- local Count = ply:GetCount("_acf_Gearbox")
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()].acfgearbox
- if Count>=Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached acf gearbox limit!" )
- ent:Remove()
- Return()
- end
- end
- elseif not (enttype == "props" or enttype == "sents" or enttype == "npcs" or enttype == "vehicles" or enttype == "effects" or enttype == "ragdolls") then
- if EV_AP_LIMITS[ply:EV_GetRank()] and EV_AP_LIMITS[ply:EV_GetRank()][enttype] then
- local Count = ply:GetCount(enttype)
- local Limit = EV_AP_LIMITS[ply:EV_GetRank()][enttype]
- if Count>=Limit then
- evolve:Notify( ply, evolve.colors.red, "You have reached "..enttype.." limit!" )
- ent:Remove()
- Return()
- end
- end
- end
- ent.EV_Owner = ply:UniqueID()
- Return()
- end
- end
- /*-------------------------------------------------------------------------------------------------------------------------
- Commands
- -------------------------------------------------------------------------------------------------------------------------*/
- concommand.Add("ev_setlimit",function(ply, cmd, args)
- if ply:EV_HasPrivilege( "Set limits" ) then
- local Rank = args[1]
- local Limit = args[2]
- local Amount = args[3]
- if not evolve.ranks[ Rank ] then
- evolve:Notify( ply, evolve.colors.red, "There is no such rank!" )
- return
- end
- if not Limit then
- evolve:Notify( ply, evolve.colors.red, "You need to specify what to limit!" )
- return
- end
- if not Amount then
- evolve:Notify( ply, evolve.colors.red, "You need to limit amount!" )
- return
- end
- if not EV_AP_LIMITS[Rank] then EV_AP_LIMITS[Rank] = {} end
- EV_AP_LIMITS[Rank][Limit] = tonumber(Amount)
- 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 )
- file.Write("ev_limits.txt", util.TableToJSON(EV_AP_LIMITS))
- else
- evolve:Notify( ply, evolve.colors.red, evolve.constants.notallowed )
- end
- end, function( commandName, args )
- return {"ev_setlimit <rank> <what> <limit>"}
- end)
- evolve:RegisterPlugin( PLUGIN )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement