mayor demote on death

Is their a way that you can make it so when the mayor dies he gets demoted to citizen

Yes, there is a way to do it. Many gamemodes such as perp have it.

How, I don’t know.

i know it is most likely a simple code i am just so retarded with this kind of stuff though lol

if you wanna be fancy and do it in one line:
[lua]hook.Add(“PlayerDeath”, “DemoteMayor”, function(ply) if ply:Team()==TEAM_MAYOR then ply:ChangeTeam(TEAM_CITIZEN, true) end end)[/lua]

If you use DarkRP

Or if you want to do it on multiple lines but also classes then…



local demoteclasses = {TEAM,MAYOR, TEAM_MOBBOSS, TEAM_CHIEF}

function demotePlayer( ply )
	for k, v in pairs(demoteclasses) do
		if ply:Team() == v then
			ply:ChangeTeam(TEAM_CITIZEN, true)
		end
	end
end
hook.Add("PlayerDeath", "demotePlayer", demotePlayer)


Should work.

ITS REVOLUTIONARY! And yeah I am following you… :glomp: …that emote is kinda gay

then again…so are these :gay::sissies:

[editline]07:17AM[/editline]

Hey so what would happen if I did slay to the entire server while I had this on there, wouldn’t it lag it?

probably asking for too much but is there a way that it displays text like when you are demoted that says you have died and will change to citizen or some shit like that



local demoteclasses = {TEAM,MAYOR, TEAM_MOBBOSS, TEAM_CHIEF}

function demotePlayer( ply )
	for k, v in pairs(demoteclasses) do
		if ply:Team() == v then
			ply:ChangeTeam(TEAM_CITIZEN, true)
			ply:PrintMessage(HUD_PRINTTALK, "You have been demoted because somebody has killed you!")
		end
	end
end
hook.Add("PlayerDeath", "demotePlayer", demotePlayer)


and if you want it to show a message to everyone…



local demoteclasses = {TEAM,MAYOR, TEAM_MOBBOSS, TEAM_CHIEF}

function demotePlayer( ply )
	for k, v in pairs(demoteclasses) do
		if ply:Team() == v then
			ply:ChangeTeam(TEAM_CITIZEN, true)
			ply:PrintMessage(HUD_PRINTTALK, "You have been demoted because somebody has killed you!")
			for a, b in pairs(player.GetAll()) do
				b:PrintMessage(HUD_PRINTTALK, v:Name() .. " has been demoted, he was murdered!")
			end
		end
	end
end
hook.Add("PlayerDeath", "demotePlayer", demotePlayer)


Change the messages if you like :stuck_out_tongue_winking_eye:

thank you very much i knew it wasn’t impossible lol

[editline]09:26PM[/editline]

lol one question what could be making the entities menu be appearing in the top left corner?

do not want to sound like a pain in the ass even though i probably am whenever i put your script in for some reason it will only demote citizens lol which doesn’t make sense to me at all

yeah where would u put something like this at? the code.

The code didnt work, because NonExistent made a comma, instead of an underscore. Here’s the correct code :] :



local demoteclasses = {TEAM_MAYOR, TEAM_MOBBOSS, TEAM_CHIEF}

function demotePlayer( ply )
for k, v in pairs(demoteclasses) do
if ply:Team() == v then
	ply:ChangeTeam(TEAM_CITIZEN, true)
	ply:PrintMessage(HUD_PRINTTALK, "You have been demoted because somebody has killed you!")
end
end
end
hook.Add("PlayerDeath", "demotePlayer", demotePlayer)


and if you want it to show a message to everyone…



local demoteclasses = {TEAM_MAYOR, TEAM_MOBBOSS, TEAM_CHIEF}

function demotePlayer( ply )
for k, v in pairs(demoteclasses) do
if ply:Team() == v then
	ply:ChangeTeam(TEAM_CITIZEN, true)
	ply:PrintMessage(HUD_PRINTTALK, "You have been demoted because somebody has killed you!")
	for a, b in pairs(player.GetAll()) do
	b:PrintMessage(HUD_PRINTTALK, v:Name() .. " has been demoted, he was murdered!")
end
end
end
end
hook.Add("PlayerDeath", "demotePlayer", demotePlayer)


thank you so much again. Weird question why is it when you get demoted once it completely stops you from being demoted for being killed again

Then theres probbably an error

That’s a… That’s strange… Also silly me with the comma, how the FUCK did I manage that? :stuck_out_tongue:

Anyway… If it doesn’t work again then… Hmm… Does it work for OTHER people after it’s been done on one person?

dont know havent tried it yet with multiple people i will test it and reply back here

Where do i put it though? Right under the mayor job? Or is it in a differnt LUA document?

Main.lua

Are you sure demotePlayer isn’t already in DarkRP for voting demotions…

yeah for some reason it doesn’t work after you die once very weird

[editline]10:58PM[/editline]

ok i found it in main.lua how would i incorporate your script into this

local function Demote(ply, args)
if ply:IsSuperAdmin() or ply:IsAdmin() then
Notify(ply, 1, 4, string.format(LANGUAGE.unable, “/demote”, “You cannot demote an admin.”))
return “”
else
local tableargs = string.Explode(" ", args)
if #tableargs == 1 then
Notify(ply, 1, 4, LANGUAGE.vote_specify_reason)
return “”
end
local reason = “”
for i = 2, #tableargs, 1 do
reason = reason … " " … tableargs*
end
reason = string.sub(reason, 2)
if string.len(reason) > 22 then
Notify(ply, 1, 4, string.format(LANGUAGE.unable, “/demote”, “<23”))
return “”
end
local p = FindPlayer(tableargs[1])
if p then
if CurTime() - ply:GetTable().LastVoteCop < 80 then
Notify(ply, 1, 4, string.format(LANGUAGE.have_to_wait, math.ceil(80 - (CurTime() - ply:GetTable().LastVoteCop)), “/demote”))
return “”
end
if p:Team() == TEAM_CITIZEN then
Notify(ply, 1, 4, string.format(LANGUAGE.unable, “/demote”, “”))
else
NotifyAll(1, 4, string.format(LANGUAGE.demote_vote_started, ply:Nick(), p:Nick()))
vote:Create(p:Nick() … ":
"…string.format(LANGUAGE.demote_vote_text, reason), p:EntIndex() … “votecop”…ply:EntIndex(), p, 20, FinishDemote, true)
ply:GetTable().LastVoteCop = CurTime()
end
return “”
else
Notify(ply, 1, 4, string.format(LANGUAGE.could_not_find, “player: “…tostring(args)))
return “”
end
end
end
AddChatCommand(”/demote”, Demote)