Hey guys! I have made a darkrp server and I need a LUA script that demotes the Mayor when he dies. Thanks in advance!
Old Mayor Script:
[CODE]
function MayorDemote( victim, weapon, killer )
if victim:Team() == (TEAM_MAYOR) && killer:IsPlayer( ) then
victim:SetTeam() == (TEAM_CITIZEN)
victim:ChatPrint("You died and you are now a regular citizen")
for k, v in pairs (player.GetAll()) do
v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" )
end
end
end
hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )
[/CODE]
EDIT: This is the old code I had the one im looking for has to work
victim:ConCommand("say /job Citizen")
--Simple Mayor Death Code
--All that I ask is that you don't say you made it
--Untested but should work
--To all the noobs that didn't know LUA or were just too lazy fuckwits to compile themselves ;)
local gamemodeget = GetConVarString("gamemode")
if string.find(gamemodeget, "darkrp") then
function PlayerDied(victim, attacker)
if victim:Team() == TEAM_MAYOR then
victim:SetTeam(TEAM_CITIZEN)
victim:ConCommand("say /job Citizen")
for k,v in pairs(player.GetAll()) do
v:ChatPrint(victim:Nick().." has been assassinated by "..attacker:Nick())
end
end
end
end
hook.Add("PlayerDeath", "mayordied", PlayerDied)
[QUOTE=fbto4;40912098]victim:ConCommand("say /job Citizen")
--Simple Mayor Death Code
--All that I ask is that you don't say you made it
--Untested but should work
--To all the noobs that didn't know LUA or were just too lazy fuckwits to compile themselves ;)
local gamemodeget = GetConVarString("gamemode")
if string.find(gamemodeget, "darkrp") then
function PlayerDied(victim, attacker)
if victim:Team() == TEAM_MAYOR then
victim:SetTeam(TEAM_CITIZEN)
victim:ConCommand("say /job Citizen")
for k,v in pairs(player.GetAll()) do
v:ChatPrint(victim:Nick().." has been assassinated by "..attacker:Nick())
end
end
end
end
hook.Add("PlayerDeath", "mayordied", PlayerDied)[/QUOTE]
That is a terrible way to do it.
Waitttt I found one
[CODE]
function MayorDemote( victim, weapon, killer )
if victim:Team() == TEAM_MAYOR then
victim:ChangeTeam(TEAM_CITIZEN, true)
victim:ChatPrint("You died and you are now a regular citizen.")
for k, v in pairs (player.GetAll()) do
if v != victim then
v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" )
end
end
end
end
hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )
[/CODE]
[editline]5th June 2013[/editline]
[QUOTE=KnownUser;40912139]Waitttt I found one
[CODE]
function MayorDemote( victim, weapon, killer )
if victim:Team() == TEAM_MAYOR then
victim:ChangeTeam(TEAM_CITIZEN, true)
victim:ChatPrint("You died and you are now a regular citizen.")
for k, v in pairs (player.GetAll()) do
if v != victim then
v:PrintMessage( HUD_PRINTCENTER, "The mayor has died!" )
end
end
end
end
hook.Add( "PlayerDeath", "mayorDemote", MayorDemote )
[/CODE][/QUOTE]
Yup, that's how you do it. It was your "victim:SetTeam() == (TEAM_CITIZEN)" which screwed things up.
[QUOTE=Bo98;40912141]-snip-[/QUOTE]
Actually no it would be [CODE] victim:ChangeTeam [/CODE]
[QUOTE=KnownUser;40912163]Actually no it would be [CODE] victim:ChangeTeam [/CODE][/QUOTE]
Yeah it was a small typo.
[QUOTE=Bo98;40912177]Yeah it was a small typo.[/QUOTE]
Typos can cause tons of errors!
[CODE]local function MayorDeath(Player, Attacker)
if Player:Team() == TEAM_MAYOR then
Player:TeamBan() -- Don't let the player become the mayor for a while.
Player:ChangeTeam(TEAM_CITIZEN, true) -- Change to whatever team you want them set to.
GAMEMODE:NotifyAll(0,4, "our mayor, " .. Player:Nick() .. ", died!")
end
end
hook.Add("PlayerDeath", "DRP_Mayor", MayorDeath)[/CODE]
[lua]
local function PlayerDeath(ply, attacker, dmginfo)
if(ply:Team() == TEAM_MAYOR)then
ply:ChangeTeam(TEAM_CITIZEN, true)
ply.MayorCooldown = CurTime() + ( 5 * 60 )
end
end
hook.Add("DoPlayerDeath", "PlayerDeath_DemoteMayor", PlayerDeath)
[/lua]
I used this on my server a few months ago but since everyone started using this why not give it to you.
Simple way using PlayerDeath in shared.lua
[lua]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 = {},
command = "mayor",
max = 1,
salary = 85,
admin = 0,
vote = true,
hasLicense = false,
help = LANGUAGE.mayorhelp,
PlayerDeath = ply:ChangeTeam(TEAM_CITIZEN, true); GAMEMODE:Notify( player.GetAll(), 1, 4, "The Mayor has been killed; there's no one in power!")
})[/lua]
Sorry, you need to Log In to post a reply to this thread.