--[[-------------------------------------------------------------------------------------------------------------------------
-- ULX Cleanup for ULX SVN/ULib SVN by LuaTenshi
------------------------------------------------------------------------------------------------------------------------]]--
local function FindOwner( ent )
local owner = owner or nil
local cppi,_ = ent:CPPIGetOwner()
owner = cppi or ent.FPPOwner or ent.Owner
return owner
end
local ignoreList =
{
"player", -- Not our territory to mess with.
"worldspawn", -- The world. Leave it be.
"gmod_anchor", -- Used for sliders connected to the world. Could be used for other stuff too, should be safe to ignore.
"npc_grenade_frag", -- Grenades, no reason we should muck around with these.
"prop_combine_ball", -- Energy balls, ditto as above.
"npc_satchel", -- Ditto.
"prop_door_rotating"
}
local fuzzyIgnoreList =
{
"env_",
"trigger_",
"info_",
"func_",
"predicted_",
"shadow_",
"point_",
"spawn",
"player"
}
local function IsItFuzzy( ent )
local entClass = ent:GetClass()
for _,v in pairs(fuzzyIgnoreList) do
if( string.find( string.lower(entClass), string.lower(v) ) ) then
return true
end
end
return false
end
local clnupflags = {"r","c","cf","g","f","m"}
function ulx.clnup( calling_ply, string_arg, command )
if string_arg == "r" then
if command == "1" or command == "true" or command == "t" then
for _,v in pairs(ents.GetAll()) do
if (v and IsValid(v)) and not table.HasValue( ignoreList, v:GetClass() ) then
if FindOwner(v) and IsValid(FindOwner(v)) then
SafeRemoveEntity( v )
end
end
end
else
game.CleanUpMap()
end
elseif string_arg == "c" then
for _,v in pairs(ents.FindByClass( command ))
if v and IsValid(v) then
if not table.HasValue( ignoreList, v:GetClass() ) then
if not IsItFuzzy(v) then SafeRemoveEntity( v ) end
end
end
end
elseif string_arg == "cf" then
for _,v in pairs(ents.GetAll()) do
if (v and IsValid(v)) and (string.find( string.lower(v:GetClass()), command)) then
if not table.HasValue( ignoreList, v:GetClass() ) then
if not IsItFuzzy(v) then SafeRemoveEntity( v ) end
end
end
end
elseif string_arg == "g" then
local scanner = {}
for _,v in pairs(ents.GetAll()) do
if (v and IsValid(v)) and not table.HasValue( ignoreList, v:GetClass() ) then
if FindOwner(v) and IsValid(FindOwner(v)) then
scanner[FindOwner(v)] = (0 or scanner[FindOwner(v)]) + 1
end
end
end
local target = table.GetWinningKey( scanner )
target:ConCommand("gmod_cleanup")
elseif string_arg == "f" then
for _,v in pairs(ents.GetAll()) do
if v:GetPhysicsObject():IsMotionEnabled() and not table.HasValue( ignoreList, v:GetClass() ) then
if command == "1" or command == "true" or command == "t" then
if not IsItFuzzy(v) then SafeRemoveEntity( v ) end
else
if FindOwner(v) and IsValid(FindOwner(v)) then
SafeRemoveEntity( v )
end
end
end
end
elseif string_arg == "m" then
for _,v in pairs(ents.FindByModel( ulx.standardizeModel(command) ))
if v and IsValid(v) then
if not table.HasValue( ignoreList, v:GetClass() ) then
if not IsItFuzzy(v) then SafeRemoveEntity( v ) end
end
end
end
else
game.CleanUpMap()
end
end
local clnup = ulx.command( "Extra Utility", "ulx clnup", ulx.clnup, {"!cleanup","!clnup"} )
clnup:addParam{ type=ULib.cmds.StringArg, completes=clnupflags, default="r", hint="flag", error="Invalid flag \"%s\" specified", ULib.cmds.optional }
clnup:addParam{ type=ULib.cmds.StringArg, hint="command", ULib.cmds.takeRestOfLine }
clnup:defaultAccess( ULib.ACCESS_SUPERADMIN )
clnup:help([[ Cleanup the server with style.
r - Reset the map, or remove all player owned entities.
c - Cleanup all entities with the specified class.
cf - Cleanup all entities with the class name that contains the specified string.
g - Cleanup the player with the most props spawned.
f - Cleanup all un-frozen props.
m - Cleanup all entities that have the specified model.
]])