LUA:Demote Upon Death

Introduction
Welcome to the tutorial, in this tutorial, I will show you how to demote a player as soon as they die.

Gamemode
Open jobs.lua in lua/darkrp_customthings in your DarkRP modification addon (see here).

Coding it
When you're in jobs.lua, find the job you want the player to be demoted from when they're killed. If it is a default job then copy the job from DarkRP's default jobrelated.lua and disable the default job in lua/darkrp_config/disabled_defaults.lua. Then add this:

PlayerDeath = function(ply, weapon, killer) ply:teamBan ply:changeTeam(GAMEMODE.DefaultTeam, true) if killer:IsPlayer then DarkRP.notifyAll(0, 4, "The mayor has been killed and is therefor demoted.") else DarkRP.notifyAll(0, 4, "The mayor has died and is therefor demoted.") end end

So full team should look something like this:

TEAM_MAYOR = DarkRP.createJob("Mayor", {	color = Color(150, 20, 20, 255),	model = "models/player/breen.mdl",	description = The Mayor of the city creates laws to serve the greater good	of the people.	If you are the mayor you may create and accept warrants.	Type /wanted to warrant a player	Type /jailpos to set the Jail Position	Type /lockdown initiate a lockdown of the city.	Everyone must be inside during a lockdown.	The cops patrol the area	/unlockdown to end a lockdown,	weapons = {},	command = "mayor",	max = 1,	salary = GAMEMODE.Config.normalsalary * 1.89,	admin = 0,	vote = true,	hasLicense = false,	mayor = true,	PlayerDeath = function(ply, weapon, killer)		ply:teamBan		ply:changeTeam(GAMEMODE.DefaultTeam, true)		if killer:IsPlayer then			DarkRP.notifyAll(0, 4, "The mayor has been killed and is therefor demoted.")		else			DarkRP.notifyAll(0, 4, "The mayor has died and is therefor demoted.") end end })

When the mayor dies, he will be demoted.