Preventing players dead bodies disappearing?

Hey, i’m here to ask that could anyone do a Lua script which prevents dead players corpses disappearing. Normally when player dies, his dead body disappears when the player respawns.
I would want that this script would automatically remove the corpse after 2 minutes.
If there is a way to do this and someone could do this, i would be really grateful!

Something like this:

[lua]local ragdoll = ents.Create( “prop_ragdoll” );

ragdoll:SetPos( self:GetPos() );
ragdoll:SetAngles( self:GetAngles() );
ragdoll:SetModel( self:GetModel() );
ragdoll:SetOwner( self );

ragdoll:Spawn();

timer.Simple( 120, ragdoll.Remove, ragdoll );[/lua]

Untested. Put it in a meta function. Like
function meta:RagdollPlayer() or something

Thank you! I will try this, hopefully i can get it right.

Damn, it broke the gamemode (DarkRP)
I could make a new lua file for it.
EDIT: No luck.

If you did that on player death that would create an additional ragdoll.

I think you’re probably gonna have to hook or override the GM:PlayerDeath function, which has CreateRagdoll() in it.

Look through the base gamemode to see how they deal with it. PlayerSpawn probably removes the ragdoll though, so that might be where you have to change something.

Okay, i’m now tricking around with base gamemodes player.lua file but i have no idea how to make this to work. Damn, i’d wish that i had some time learning some lua scripting.


function GM:PlayerDeath( Victim, Inflictor, Attacker )

    // Don't spawn for at least 2 seconds
    Victim.NextSpawnTime = CurTime() + 2
    Victim.DeathTime = CurTime()

Should i add CreateRagdoll() in there?

Try that, yeah.

Okay, it didn’t work.
I heard that MetroRP:s corecode is preventing the client ragdolls staying.
I need a solution for this…

use ply:CreateRagdoll(), not just CreateRagdoll. Make sure its function whateveer( ply ), though.


function GM:DoPlayerDeath(ply, attacker, dmginfo, ...)
    if tobool(GetConVarNumber("dropweapondeath")) and ValidEntity(ply:GetActiveWeapon()) then
        ply:DropWeapon(ply:GetActiveWeapon())
    end
    ply:CreateRagdoll()
    ply:AddDeaths( 1 )
    if ValidEntity(attacker) and attacker:IsPlayer() then
        if attacker == ply then
            attacker:AddFrags( -1 )
        else
            attacker:AddFrags( 1 )
        end
    end
end

There is already ‘ply:CreateRagdoll()’. There also must be something that makes the body to disappear. You know any lua commands which do so? I could try to hunt them from lua files.

removing the ragdoll wouldn’t be on death, it would be on spawn, so find GM:PlayerSpawn

garrysmod.org has something similar to this called “Serverside Ragdolls” or something like that, basically it replaces the game’s ragdolls with serverside, full collision ragdolls.

I think.