How to clear ragdolls?

In the GoFish 2 gamemode, the NPCs corpses never fade nor clear. I would like to know why, and how to make them fade/clear?

Keep Corpses in the Q menu’s npc menu to keep ragdolls as colliding, and just remove them.

Init.lua

[lua]
hook.Add(“Think”,“RemoveDeadNpcs”, function()
for k,v in pairs(ents.GetAll()) do
if v:IsNPC() and !v:Alive() and v:GetRagdollEntity() then
timer.Simple(3, function() v:Remove() end) – Remove them after 3 seconds
end
end
end)[/lua]

Hey, cubar, do you mind if I use that in a script(its for a private server, not releasing it or anything), because dead NPCs annoy me sometimes…

Nope i don’t mind it’s free, feel free to edit ect i will make it fade soon. :slight_smile:

Hey Cubar, add me on steam, leecreations. Thanks, also, Saint Devil, just click the keep bodies or whatever button if you don’t know, or not the best at coding.

Wow, I didn’t even know GetRagdollEntity() was a function. Thanks.

Okay, thanks Cubar.

You guys have no fucking idea what you’re talking about. First of all, very few servers have serverside ragdolls on (= Keep Corpses), because it’s usually unneeded and lagtastic. So the issue is NOT serverside.

Secondly, Cubar, your code makes no sense at all and will never work, stop pretending it works.
GetRagdollEntity is only for players, there is no real way to find a NPC’s ragdoll and clear it. Plus, NPCs cease to exist after they are killed, they don’t stay there waiting for you to retrieve their ragdoll and do shit with it. How would you even detect zombies which have been cut in half with a sawblade?

Here’s a piece of code that should work. Paste that in Notepad, save it as “ragdollfade.lua”, and put it in garrysmod/lua/autorun/client.
I didn’t try it yet though, so I don’t guarantee anything, just tell me if you have any error.

[lua]local RagdollLifeTime = 5
local RagdollFadeTime = 1

local FadeList = {}

hook.Add(“OnEntityCreated”, “NPCRagdollStartFading”, function(ent)
if ValidEntity(ent) and ent:GetClass()==“class C_ClientRagdoll” then
ent.FadeNextDie = CurTime() + RagdollLifeTime
FadeList[ent] = true
end
end)

hook.Add(“Think”, “NPCRagdollFade”, function()
for ent,_ in pairs(FadeList) do
if not ValidEntity(ent) then
FadeList[ent] = nil
else
if not ent.FadeNextDie then
ent.FadeNextDie = CurTime() + RagdollLifeTime
end

		local diff = ent.FadeNextDie - CurTime()
		local r, g, b, a = ent:GetColor()
		a = Lerp(diff / RagdollFadeTime, 0, 255)
		ent:SetColor(r, g, b, a)
		
		if diff<=0 then
			FadeList[ent] = nil
			ent:Remove()
		end
	end
end

end)[/lua]

[editline]03:39PM[/editline]

Okay, it works. At least for me. Hope that’s what you’re looking for. :v:

Ops my bad. xD

Ragdoll Fade System

Yeah, that’s all you have to say.
Also, that fade system isn’t yours, and it’s horribly coded.

More like you stole the code.

[lua]hook.Add(“Think” , “RemoveNPCRagdolls” , function()
for k , v in ipairs(ents.GetAll()) do
if type(v) == “NPC” or string.find(v:GetClass() , “npc”) and v:GetMoveType() == 0 then
v:Remove()
end
end
end )[/lua]

Simple as that. Then just add code to fade out, which I can’t be bothered doing.

That is what i was trying to do but i was tired and failed. :frowning:

Just use NPCBattleCleanup. http://www.garrysmod.org/downloads/?a=view&id=29053

g_ragdoll_maxcount 0 ?

Haha, what.

Wait, wouldn’t that just remove NPCs as soon as they die? I don’t see the point, either it doesn’t work at all, or it removes the NPC before the ragdoll is created, which would look kinda ugly as well.

[editline]10:16AM[/editline]

That too, but it just instantly fades ragdoll out, might not be what OP is looking for.

Replace :Remove with a metafunction you write yourself to fade out.

Cubar = cube? Sounds just as retarded.

Heh, I still don’t get it, so either I’m really tired, or you are. Or it was sarcasm but I didn’t even notice it.
That doesn’t affect the clientside ragdolls whatsoever.