mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 21:53:46 +03:00
Upload
This commit is contained in:
93
gamemodes/darkrp/plugins/simple_garbage_cleaner.lua
Normal file
93
gamemodes/darkrp/plugins/simple_garbage_cleaner.lua
Normal file
@@ -0,0 +1,93 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
PLUGIN.name = "Simple item cleaner"
|
||||
PLUGIN.description = "Automatically removes unwanted items"
|
||||
PLUGIN.author = "DrodA"
|
||||
PLUGIN.version = 2.0
|
||||
|
||||
ix.config.Add("EnableItemCleaner", true, "Enables or disables item cleaner.", function(oldVal, newVal)
|
||||
if (SERVER) then
|
||||
PLUGIN:CreateTimer()
|
||||
end
|
||||
end, {
|
||||
category = "Other"
|
||||
})
|
||||
|
||||
if (!SERVER) then return end
|
||||
|
||||
PLUGIN.itemCategories = {
|
||||
["Junk"] = 300
|
||||
}
|
||||
|
||||
PLUGIN.entityTypes = {
|
||||
["ix_drop"] = 300,
|
||||
["ix_workerk_water"] = 300,
|
||||
["ix_workerk_gas"] = 300,
|
||||
["ix_workerk_electric"] = 300
|
||||
}
|
||||
|
||||
PLUGIN.markedEntities = PLUGIN.markedEntities or {}
|
||||
|
||||
function PLUGIN:OnSavedItemLoaded(items, entities)
|
||||
for _, v in ipairs(entities) do
|
||||
self:OnItemSpawned(v)
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:OnItemSpawned(entity)
|
||||
local item = ix.item.instances[entity.ixItemID]
|
||||
if (item) then
|
||||
if (item.junkCleanTime) then
|
||||
self.markedEntities[entity] = os.time() + item.junkCleanTime * 60
|
||||
elseif (self.itemCategories[item.category]) then
|
||||
self.markedEntities[entity] = os.time() + self.itemCategories[item.category] * 60
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:OnEntityCreated(entity)
|
||||
local class = entity:GetClass()
|
||||
if (self.entityTypes[class]) then
|
||||
self.markedEntities[entity] = os.time() + self.entityTypes[class]
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:EntityRemoved(entity)
|
||||
if (self.markedEntities[entity]) then
|
||||
self.markedEntities[entity] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:CreateTimer()
|
||||
if (!ix.config.Get("EnableItemCleaner")) then
|
||||
timer.Remove("ixItemCleanerTimer")
|
||||
return
|
||||
end
|
||||
|
||||
local pairs, IsValid = pairs, IsValid
|
||||
timer.Create("ixItemCleanerTimer", 61, 0, function()
|
||||
local time = os.time()
|
||||
for k, v in pairs(self.markedEntities) do
|
||||
if (v < time) then
|
||||
self.markedEntities[k] = nil
|
||||
if (IsValid(k)) then
|
||||
k:Remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function PLUGIN:InitializedConfig()
|
||||
self:CreateTimer()
|
||||
end
|
||||
Reference in New Issue
Block a user