i have it working if the mayor gets demoted or killed but it don't have it working if the mayor decides to switch his/hers job
i try to do this
[lua]
function killmayorguard (ply)
for k, ply in pairs(player.GetAll()) do
if(ply:Team() != TEAM_MAYOR) then
if(ply:Team() == TEAM_MAYORSGUARD) then
ply:ChangeTeam(TEAM_CITIZEN, true)
else return
end
end
end
concommand.Add( "killmg", killmayorguard )
[/lua]
it worked somewhat but it don't check if the mayor is there of not
also i have this function in the autorun server folder. i didn't know where else to put it
any help please :)
You really shouldn't use a console command for it.
[lua]function DemoteGuards()
local Mayor = team.NumPlayers( TEAM_MAYOR )
if Mayor == 0 then
for k,v in pairs(player.GetAll()) do
if v:Team() == TEAM_MAYORSGUARD then
v:ChangeTeam(TEAM_CITIZEN, true)
Notify(v, 1, 5, "You have been demoted because there is no Mayor!")
end
end
end
end
hook.Add("Think", "GuardDemoter", DemoteGuards)[/lua]
Why not just run that function, when the mayor is killed, and make it so you can't go Mayor's Guard, if there isn't a mayor?
Just run that function in the meta function ChangeTeam in player.lua, instead of doing that.
Optimization and efficiency aren't my specialties, but I know there's a much better way to run that, if the one I suggested isn't good enough.
Yes, running k,v in pairs every frame is very unoptimised
Sorry, you need to Log In to post a reply to this thread.