Difference between revisions of "LUA:Demote Upon Death"

From Official DarkRP Wiki
Jump to navigation Jump to search
(Coding it: and more)
Line 27: Line 27:
 
<div style="background-color:#F7F7F7;">
 
<div style="background-color:#F7F7F7;">
 
{{Code|1=
 
{{Code|1=
PlayerDeath = function(ply, weapon, killer)  
+
        PlayerDeath = function(ply, weapon, killer)
if( ply:Team() == TEAM_MAYOR ) then
+
                if( ply:Team() == TEAM_MAYOR ) then
ply:changeTeam( GAMEMODE.DefaultTeam, true )
+
                        ply:ChangeTeam( GAMEMODE.DefaultTeam, true )
for k,v in pairs( player.GetAll() ) do
+
                        for k,v in pairs( player.GetAll() ) do
v:PrintMessage( HUD_PRINTCENTER, "The mayor has been killed!" )
+
                                v:PrintMessage( HUD_PRINTCENTER, "The mayor has been killed!" )
end
+
                        end
end
+
                end
end
+
        end
}}
+
})
 
</div>
 
</div>
 
----
 
----
Line 73: Line 73:
 
"Type /addlaw and /removelaw to edit the laws."
 
"Type /addlaw and /removelaw to edit the laws."
 
},
 
},
PlayerDeath = function(ply, weapon, killer)  
+
        PlayerDeath = function(ply, weapon, killer)
if( ply:Team() == TEAM_MAYOR ) then
+
                if( ply:Team() == TEAM_MAYOR ) then
ply:changeTeam( GAMEMODE.DefaultTeam, true )
+
                        ply:ChangeTeam( GAMEMODE.DefaultTeam, true )
for k,v in pairs( player.GetAll() ) do
+
                        for k,v in pairs( player.GetAll() ) do
v:PrintMessage( HUD_PRINTCENTER, "The mayor has been killed!" )
+
                                v:PrintMessage( HUD_PRINTCENTER, "The mayor has been killed!" )
end
+
                        end
end
+
                end
end
+
        end
})
 
 
}}
 
}}
 
</div>
 
</div>

Revision as of 17:43, 23 August 2013

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 jobrelated.lua in garrysmod/garrysmod/gamemodes/darkrp/gamemode/config

Coding it

When your in jobrelated.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/