I have looked in many places for a mod/addon/lua attachment that allows for npcs being automatically cleaned up, yet the only ones I find do not work in multiplayer.
Since I tend to host my own multiplayer games for friends, I was wondering if anyone knew where I could find one/ if someone could make one.
Yes I have tried the one on garrysmod.org.
When you tried the one on garrysmod.org did you get any lua errors? It would be more simple to fix the script if it isn't that outdated.
No apparent lua errors, the problem lies more within how in multiplayer (at least a multiplayer listen server), npc bodies are never registered as being actual things you can clean up. The only way to clean them up is full admin cleanup which essentially just resets the map.
[lua]
for k,v in pairs(ents.FindByClass("class C_ClientRagdoll")) do
if ValidEntity(v) then
v:Remove()
end
end
[/lua]
Here's a console command for it.
[lua]
function CleanRagdolls(ply,cmd,args)
if not ply:IsSuperAdmin() then return end
for k,v in pairs(ents.FindByClass("class C_ClientRagdoll")) do
if ValidEntity(v) then
v:Remove()
end
end
end
concommand.Add("clean_ragdolls",CleanRagdolls)
[/lua]
There's probably a gamemode hook somewhere that allows you to remove the ragdoll, but I don't know about it.
Thanks for that, Ill be sure to try it next time I host a listen server.
[QUOTE=skullorz;35083909][lua]
for k,v in pairs(ents.FindByClass("class C_ClientRagdoll")) do
if ValidEntity(v) then
v:Remove()
end
end
[/lua]
Here's a console command for it.
[lua]
function CleanRagdolls(ply,cmd,args)
if not ply:IsSuperAdmin() then return end
for k,v in pairs(ents.FindByClass("class C_ClientRagdoll")) do
if ValidEntity(v) then
v:Remove()
end
end
end
concommand.Add("clean_ragdolls",CleanRagdolls)
[/lua]
There's probably a gamemode hook somewhere that allows you to remove the ragdoll, but I don't know about it.[/QUOTE]
Erm... sorry for the double post, but at the risk of sounding like an idiot, where would I put the code?
Make a lua script in your server's lua directory, and call it once after loading (the console command version) or call it once every time you want to clear the map (the first version) or use something like this:
[lua]
timer.Create( "removal", 0.01, 0, function()
for k,v in ipairs(ents.FindByClass("class C_ClientRagdoll")) do
local r,g,b,a = v:GetColor()
if (a==0) then
v:Remove()
else
a=a-1
v:SetColor(r,g,b,a)
end
end
end)
[/lua]
as a clientside script for clearing dead bodies by making them fade out (and then removing them) anywhere you play :)
[QUOTE=meoiswa;35346097]Make a lua script in your server's lua directory, and call it once after loading (the console command version) or call it once every time you want to clear the map (the first version) or use something like this:
[lua]
timer.Create( "removal", 0.01, 0, function()
for k,v in ipairs(ents.FindByClass("class C_ClientRagdoll")) do
local r,g,b,a = v:GetColor()
if (a==0) then
v:Remove()
else
a=a-1
v:SetColor(r,g,b,a)
end
end
end)
[/lua]
as a clientside script for clearing dead bodies by making them fade out (and then removing them) anywhere you play :)[/QUOTE]
Sorry again, but I am not sure how to make the lua script (I know I'm stupid about this) but know I do know where to place it (for the most part.)
Or
game.RemoveRagdolls()
You copy the text into a .lua file which you place in lua/autorun. If that folder doesn't exist, create it.
Sorry, you need to Log In to post a reply to this thread.