I know how much Facepunch hates DarkRP for some reason so I'll keep this short for my knowledge on LUA is all but fabulous.
[CODE]hook.Add("PlayerDeath","1Mayor Auto demote",function(ply)
if ply:Team() == TEAM_MAYOR then
ply:changeTeam(TEAM_CITIZEN,true)
PrintMessage( HUD_PRINTCENTER, "The President has been assassinated!" )
else
end
end)[/CODE]
I have that, and I would wish to make it search all players for another "job" and demote them to citizen, any help is appreciated.
EDIT: Hm, this is all what I typed.
I didn't realize that I typed my request wrong, I'm actually incredibly sorry about that; I was looking for when the mayor dies I want another job to be demoted as well, again, sorry, it was a late night when I posted this...
Do you mean demote them from their job to citizen when they die?
replace "TEAM_MAYOR" with the name of a different job, whichever one you'd like.
No point putting the "else" there if you don't put anything after it.
[lua]
for key, ply in pairs(player.GetAll()) do
if ply:GetClass() == "MAYOR" then
return ply;
end
end
[/lua]
[QUOTE=Commander11;42946274][lua]
for key, ply in pairs(player.GetAll()) do
if ply:GetClass() == "MAYOR" then
return ply;
end
end
[/lua][/QUOTE]
GetClass returns the class of the entity, which is not going to be "MAYOR"
Hm, this is all what I typed.
I didn't realize that I typed my request wrong, I'm actually incredibly sorry about that; I was looking for when the mayor dies I want another job to be demoted as well, again, sorry, it was a late night when I posted this...
[QUOTE=Professorg;42948314]Hm, this is all what I typed.
I didn't realize that I typed my request wrong, I'm actually incredibly sorry about that; I was looking for when the mayor dies I want another job to be demoted as well, again, sorry, it was a late night when I posted this...[/QUOTE]
Try this:
[CODE]
local GroupsToDemote = { TEAM_MAYOR, TEAM_WHATEVER, TEAM_WHATEVER2 } --Put the groups you'd like to be demoted in here. You can add as many as you'd like.
hook.Add("PlayerDeath","1Mayor Auto demote",function(ply)
if ply:Team() == TEAM_MAYOR then
PrintMessage( HUD_PRINTCENTER, "The President has been assassinated!" )
for k, v in pairs(player.GetAll()) do
if table.HasValue( GroupsToDemote, v:Team() ) then
v:changeTeam(TEAM_CITIZEN,true)
v:ChatPrint( "You've lost your job due to the death of the President!" ) --This puts some text in each demoted players chat space to inform them of their demotion. You can change or remove it if you'd like.
end
end
end
end)
[/CODE]
[QUOTE=CallMePyro;42950484]Try this:
[CODE]
local GroupsToDemote = { TEAM_MAYOR, TEAM_WHATEVER, TEAM_WHATEVER2 } --Put the groups you'd like to be demoted in here. You can add as many as you'd like.
hook.Add("PlayerDeath","1Mayor Auto demote",function(ply)
if ply:Team() == TEAM_MAYOR then
PrintMessage( HUD_PRINTCENTER, "The President has been assassinated!" )
for k, v in pairs(player.GetAll()) do
if table.HasValue( GroupsToDemote, v:Team() ) then
v:changeTeam(TEAM_CITIZEN,true)
v:ChatPrint( "You've lost your job due to the death of the President!" ) --This puts some text in each demoted players chat space to inform them of their demotion. You can change or remove it if you'd like.
end
end
end
end)
[/CODE][/QUOTE]
It made the announcement however did not demote either class, thanks for trying to help though :)
[QUOTE=Professorg;42950687]It made the announcement however did not demote either class, thanks for trying to help though :)[/QUOTE]
according to the gmod wiki,
"v:changeTeam(TEAM_CITIZEN,true)"
should be
"v:ChangeTeam(TEAM_CITIZEN,true)"
[QUOTE=CallMePyro;42950762]according to the gmod wiki,
"v:changeTeam(TEAM_CITIZEN,true)"
should be
"v:ChangeTeam(TEAM_CITIZEN,true)"[/QUOTE]
I still didn't seem to change, not sure why.... It seems to be right...
[code]
hook.Add( "PlayerDeath", "MayorDemote", function( ply )
if ply:Team() == TEAM_MAYOR then
PrintMessage( HUD_PRINTCENTER, "The President has been assassinated!" )
ply:changeTeam(TEAM_CITIZEN,1)
DarkRP.Log(ply:SteamName() .. " was killed and therefore demoted from President.",nil, Color(0, 190, 255))
end
end)
[/code]
This should work
[editline]22nd November 2013[/editline]
Which, is basically the code you posted, actually.
Are you sure this is in the right file and/or is being loaded by the server?
[QUOTE=Mors Quaedam;42951346][code]
hook.Add( "PlayerDeath", "MayorDemote", function( ply )
if ply:Team() == TEAM_MAYOR then
PrintMessage( HUD_PRINTCENTER, "The President has been assassinated!" )
ply:changeTeam(TEAM_CITIZEN,1)
DarkRP.Log(ply:SteamName() .. " was killed and therefore demoted from President.",nil, Color(0, 190, 255))
end
end)
[/code]
This should work
[editline]22nd November 2013[/editline]
Which, is basically the code you posted, actually.
Are you sure this is in the right file and/or is being loaded by the server?[/QUOTE]
I'm very sorry, I forgot to edit above, I was looking for on the mayors death the TEAM_SECRETSERVICE would get demoted as well, again, sorry :/
[QUOTE=Professorg;42951533]I'm very sorry, I forgot to edit above, I was looking for on the mayors death the TEAM_SECRETSERVICE would get demoted as well, again, sorry :/[/QUOTE]
[code]hook.Add( "PlayerDeath", "MayorDemote", function( ply )
if ply:Team() == TEAM_MAYOR then
PrintMessage( HUD_PRINTCENTER, "The President has been assassinated!" )
ply:changeTeam(TEAM_CITIZEN,1)
DarkRP.Log(ply:SteamName() .. " was killed and therefore demoted from President.",nil, Color(0, 190, 255))
for k,v in pairs(player.GetAll()) do
if v:Team() == TEAM_SECRETSERVICE then
v:changeTeam(TEAM_CITIZEN,1)
v:ChatPrint( "You've lost your job due to the death of the President!" )
end
end
end
end)[/code]
How about this?
[CODE]hook.Add("PlayerDeath","DemoteMayor",function(v,k)
if (v:Team() == TEAM_MAYOR) then
v:ChangeTeam(TEAM_CITIZEN,true);
for k, v in ipairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTCENTER,"The mayor has died!");
end;
end;
end);[/CODE]
Add this to the bottom of your main.lua
[QUOTE=Mors Quaedam;42951895][code]hook.Add( "PlayerDeath", "MayorDemote", function( ply )
if ply:Team() == TEAM_MAYOR then
PrintMessage( HUD_PRINTCENTER, "The President has been assassinated!" )
ply:changeTeam(TEAM_CITIZEN,1)
DarkRP.Log(ply:SteamName() .. " was killed and therefore demoted from President.",nil, Color(0, 190, 255))
for k,v in pairs(player.GetAll()) do
if v:Team() == TEAM_SECRETSERVICE then
v:changeTeam(TEAM_CITIZEN,1)
v:ChatPrint( "You've lost your job due to the death of the President!" )
end
end
end
end)[/code]
How about this?[/QUOTE]
It demoted me however kept my SS as SS.
[QUOTE=Professorg;42952372]It demoted me however kept my SS as SS.[/QUOTE]
So you would like to demote more than just the mayor?
I just got Rocket Mania to make me one, here it is :)
[code] hook.Add("PlayerDeath","1Mayor Auto demote",function(ply)
if ply:Team() == TEAM_MAYOR then
ply:changeTeam(TEAM_CITIZEN,true)
PrintMessage( HUD_PRINTCENTER, "The President has been assassinated!" )
for k,v in pairs(player.GetAll()) do
if v:Team() == TEAM_SECRETSERVICE then
v:changeTeam(TEAM_CITIZEN,true)
end
end
else
end
end)
[/code]
I don't know why the ones you guys sent didn't work, maybe because
v:changeTeam(TEAM_CITIZEN,1)
should be
v:changeTeam(TEAM_CITIZEN,true)
??????
I have no idea :/
Sorry, you need to Log In to post a reply to this thread.