How to execute command on player death?

I want this command to be executed on player death “gm_rp_dropcash 1” How would I add that to my gangster roleplay I’m working on? :downs:

  1. You already have a thread on something similar, why make another one? Someone would have replied to the other one later.

  2. http://wiki.garrysmod.com/?title=Player.ConCommand

  3. http://wiki.garrysmod.com/?title=Gamemode.DoPlayerDeath

If you struggled to search the wiki then try this made by Overv: http://luasearch.overvprojects.nl/ it is basically an improved search so it is easier to find stuff if you’re struggling.
But I suggest you start learning how to use the Wiki. It seems in your other thread you want spoon feeding and that won’t help you in the long run.

Ok is this what the code should look like then?


function GM:DoPlayerDeath( p, attacker, dmginfo )

	p:RedNotify( "You got knocked the fuck out and lost "..CUR..Configuration["knockouttax"].."." )
	p:TakeMoney( Configuration["knockouttax"] )

	p:CreateRagdoll()

	v:ConCommand("gm_rp_dropcash 1")
	
end

Yes but I would advise you not to use GM:DoPlayerDeath and just add a hook.

[lua]
function DoLoseMoneyOnDeath( p, attacker, dmginfo )

p:RedNotify( "You got knocked out and lost "..CUR..Configuration["knockouttax"].."." )
p:TakeMoney( Configuration["knockouttax"] )

p:CreateRagdoll()

v:ConCommand("gm_rp_dropcash 1")

end
hook.Add(“DoPlayerDeath”,“DoLoseMoneyOnDeath”,DoLoseMoneyOnDeath)
[/lua]

Also, don’t use profanity in gamemodes, it just doesn’t look good :ninja:

Ok I got It working by just doing this.




function GM:DoPlayerDeath( p, attacker, dmginfo )

	p:RedNotify( "You got knocked the fuck out and lost "..CUR..Configuration["knockouttax"].."." )
	p:TakeMoney( Configuration["knockouttax"] )

	p:CreateRagdoll()

	p:ConCommand("gm_rp_dropcash 1")
	
end


Now how would I make it So when the player dies it drops a random amount $1-$25?

If the 1 in that is the value of the cash drop, then instead make a variable and then concatenate the value.

Local value = math.random(25)

p:ConCommand( "gm_rp_dropcash " … value )

Oh nvm I already got it. Now I’m having a problem with ranks… -.- but I already asked the question in GmodRP official release thread.