LUA:Demote Upon Death

From Official DarkRP Wiki
Jump to: navigation, search
Lua: Demote Upon Death
Page white text.png Description:Demote upon death
File:User.png Original Author:Pawsative
16px Created:August 17, 2013
File:Table edit.png Updated:April 5, 2014
This page is available in the following languages:
Данная версия страницы доступна на следующих языках:
Jarvis-flag 8010.png English | France-flag.png Français


Introduction

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

Setting up the files

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 <name>  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.