LUA:Demote Upon Death

From Official DarkRP Wiki
Revision as of 17:45, 23 August 2013 by Pawsative (talk | contribs)
Jump to navigation Jump to search
Lua: Demote Upon Death
Page white text.png Description:Demote upon death
User.png Original Author:Pawsative
Calendar.png Created:August 17, 2013
Table edit.png Updated:August 19, 2013


Introduction

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

Setting up the files

Gamemode

Open shared.lua in garrysmod/garrysmod/gamemodes/darkrp/gamemode/

Coding it

When your in shared.lua, find the job you want the player to be demoted from when they're killed. Then add this:



{{Code|1=

       PlayerDeath = function(ply, weapon, killer)
               if( ply:Team() == TEAM_MAYOR ) then
                       ply:ChangeTeam( GAMEMODE.DefaultTeam, true )
                       for k,v in pairs( player.GetAll() ) do
                               v:PrintMessage( HUD_PRINTCENTER, "The mayor has been killed!" )
                       end
               end
       end

})


So full team should look something like this:


TEAM_MAYOR = AddExtraTeam("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 = {"weapon_fists"},
	command = "mayor",
	max = 1,
	salary = 100,
	admin = 0,
	vote = true,
	hasLicense = false,
	mayor = true,
	help = {
		"Type /warrant [Nick/SteamID/Status ID] to set a search warrant for a player.",
		"Type /wanted [Nick/SteamID/Status ID] to alert everyone to a wanted suspect.",
		"Type /unwanted [Nick/SteamID/Status ID] to clear the suspect.",
		"Type /lockdown to initiate a lockdown",
		"Type /unlockdown to end a lockdown",
		"Type /placelaws to place a screen containing the laws.",
		"Type /addlaw and /removelaw to edit the laws."
	},
        PlayerDeath = function(ply, weapon, killer)
                if( ply:Team() == TEAM_MAYOR ) then
                        ply:ChangeTeam( GAMEMODE.DefaultTeam, true )
                        for k,v in pairs( player.GetAll() ) do
                                v:PrintMessage( HUD_PRINTCENTER, "The mayor has been killed!" )
                        end
                end
        end

When the mayor dies, he will be demoted.

Need anymore additional help? Add me. http://steamcommunity.com/id/Impositive/