Automatic cleanup?

I was wondering if it’s possible to make a script that automatically cleans up all the ragdolls on the server.

I know it would need a timer and some sort of hook or function for cleaning up the ragdolls, I just dont know how to do it right.

any help is much appreciated

game.CleanUpMap() resets the map.
Or you could
[lua]for k, v in pairs( ents.FindByClass( “prop_ragdoll” ) ) do
v:Remove()
end[/lua]

Then you could encase either of the two in an endless timer:
[lua]timer.Create( “CleanRagdolls”, 5, 0, function() end )[/lua]

You could also create a simple timer after creating a ragdoll that removes it.

does ragdoll cleanups remove dead npc bodys?

They do not.

Does it if Keep Ragdolls for NPCs is set to true?

This is a script which I use on my server, I found it somewhere here on the forum.
Put it in a client file.
[LUA]
function RemoveDeadRag( ent )

if (ent == NULL) or (ent == nil) then return end
if (ent:GetClass() == "class C_ClientRagdoll") then 
	if ent:IsValid() and !(ent == NULL) then
		SafeRemoveEntityDelayed(ent,180) 
	end
end 

end
hook.Add( “OnEntityCreated”, “RemoveDeadRag”, RemoveDeadRag )
[/LUA]

This will remove NPC ragdolls(not other ragdolls).

Yes. Otherwise use Busan1s code.

Thank you all very much for you help, Much appreciated.

Edit
It seems to no collide the ragdolls, Is the code meant to completely remove them?
Edit
Nevermind, i just had to change the time from 180 down a little bit. Thanks :slight_smile:

when he says place it in a client file, where specifically if on a server?