Running a console command on death

I’m trying to make it so when you die it runs rp_citizen on the victim. The thing is when I die I spawn for a second and I can’t move, And I don’t have any weapons and the camera makes it look like I’m dead and when I click I re-spawn and I don’t have any weapons and my model changed for some reason.I had this problem before so I tried to force spawn him with victim:Spawn() and that didn’t work so I thought I was running the command to fast after there death or something so I made a timer.

function PlayerDies( victim, killer )
local rdoll = ents.Create( “prop_ragdoll” )
rdoll:SetModel( victim:GetModel( ) )
rdoll:SetPos( victim:GetPos( ) )
rdoll:Spawn( )
rdoll:Activate( )
timer.Create( “my_timer”, 300, 1, function()
end )

if victim:Team() == 1 then
timer.Create("timer3", 1, 1, victim.ConCommand, victim, "rp_citizen")


hook.Add( “PlayerDeath”, “playerDeathTest”, PlayerDies )

If someone could help me that would be great.


And then, couldn’t you just run the console command when the player spawns?

I think you’re better off just calling the function rp_citizen calls.

Exactly this, otherwise you would have to first send a usermessage to inform the client that you want a console command to be run :confused:

Call it on DoPlayerDeath so it happens before you finish dying.

I don’t know what you mean by that. can you explain a little more?

When he dies just do:


function GM:DoPlayerDeath( ply, attacker, dmginfo )

I tried doing that but It crashes my game. I also tried changing the Variables to victim, killer but that crashed it to. Any ideas?