Hey there, need help with this, so far i have this
when the mayor dies, he gets changed to civilian, and so do the people in the job mayor's protectors
but, how do i make it so if there is no mayor, no one can join the job mayor's protectors?
I got this so far
[lua]
hook.Add("PlayerDeath","DemoteMayor",function(ply, victim, attacker)
if (ply:Team() == TEAM_MAYOR) then
ply:ChangeTeam(TEAM_CITIZEN,true);
for k, v in ipairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTCENTER,"The current Mayor of the city has been Assassinated!");
if v:Team() == TEAM_SECRET then
v:ChangeTeam(TEAM_CITIZEN,true);
end;
end;
end;
end);
function secretandmayor( ply )
if table.Count( team.GetPlayers(TEAM_MAYOR) ) > 0 then
--this is where i assume i need to make it so secret cannot join mayor, help please <3
end
[/lua]
[code]
customCheck = function(ply) for k,v in pairs(player.GetAll()) do if (IsValid(v) and (v:Team() == TEAM_MAYOR) and v != ply) then return true end end return CLIENT end,
CustomCheckFailMsg = "You need a leader!" -- The message it sends to the client
[/code]
[QUOTE=MuteTM;42117746][code]
customCheck = function(ply) for k,v in pairs(player.GetAll()) do if (IsValid(v) and (v:Team() == TEAM_MAYOR) and v != ply) then return true end end return CLIENT end,
CustomCheckFailMsg = "You need a leader!" -- The message it sends to the client
[/code][/QUOTE]
[URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexac55.html"]team.GetPlayers(Integer TeamIndex)[/URL]
[lua]
return #team.GetPlayers(TEAM_MAYOR) >= 1
[/lua]
[QUOTE=MuteTM;42117746][code]
customCheck = function(ply) for k,v in pairs(player.GetAll()) do if (IsValid(v) and (v:Team() == TEAM_MAYOR) and v != ply) then return true end end return CLIENT end,
CustomCheckFailMsg = "You need a leader!" -- The message it sends to the client
[/code][/QUOTE]
Wait, I'm confused,
1st of all, where would i put this code
second of all, where does it define that if your trying to join team_secret it denies you, all i see is just team_mayor?
It goes in the TEAM_SECRET job in shared.lua.
[QUOTE=Bo98;42118114]It goes in the TEAM_SECRET job in shared.lua.[/QUOTE]
Okay, but what did brandon quote? why did he wriite
[lua]
return #team.GetPlayers(TEAM_MAYOR) >= 1
[/lua]
EDIT: MuteTM explains his advantages below this post.
[LUA]
customCheck = function(ply) for k,v in pairs(player.GetAll()) do if (IsValid(v) and (v:Team() == TEAM_MAYOR) and v != ply) then return true end end return CLIENT end,
CustomCheckFailMsg = "You need a leader!", -- The message it sends to the client
[/LUA]
[QUOTE=Bo98;42118181]It's just a shorter way of righting what MuteTM wrote in the customCheck. It's a bit slower though as it's collecting all the players on the team while MuteTM's solution stops when it finds the first one. But it doesn't really matter too much, it's up to you which one you use.
[LUA]
customCheck = function(ply) for k,v in pairs(player.GetAll()) do if (IsValid(v) and (v:Team() == TEAM_MAYOR) and v != ply) then return true end end return CLIENT end,
CustomCheckFailMsg = "You need a leader!", -- The message it sends to the client
[/LUA]
[LUA]
customCheck = function(ply) return #team.GetPlayers(TEAM_MAYOR) >= 1 end,
CustomCheckFailMsg = "You need a leader!", -- The message it sends to the client
[/LUA][/QUOTE]
Might want to also note checking if the player switching is the mayor or not. But yeah, at the end of the day it's two paths to the same place. Both work fine.
[QUOTE=MuteTM;42118192]Might want to also note checking if the player switching is the mayor or not. But yeah, at the end of the day it's two paths to the same place. Both work fine.[/QUOTE]
Completely missed that, sorry. That's quite an important factor.
To put this all in one post.
In jobs.lua(refactor) or shared.lua(master)
[code]
TEAM_X = AddExtraTeam("Generic", {
color = Color(255, 255, 255, 255),
model = "models/player/whatever.mdl",
description = [[Example class.]],
weapons = {"example"},
command = "example",
max = 1,
salary = 80,
admin = 0,
vote = false,
hasLicense = false,
INSERT CODE FROM BELOW HERE
})
[/code]
Where it says INSERT CODE, you have a few options:
Option 1 - Hide the job when there is no mayor. The player may not switch from mayor to guard.
[code]
customCheck = function(ply) return (#team.GetPlayers(TEAM_MAYOR) >= 1 and (ply:Team() != TEAM_MAYOR)) end,
CustomCheckFailMsg = "You need a leader!" -- The message it sends to the client
[/code]
Option 2 - Job shows always, but they may not switch when there is no mayor. The player may not switch from mayor to guard.
[code]
customCheck = function(ply) return CLIENT or (#team.GetPlayers(TEAM_MAYOR) >= 1 and (ply:Team() != TEAM_MAYOR)) end,
CustomCheckFailMsg = "You need a leader!" -- The message it sends to the client
[/code]
Though I coded the method I posted previously, I recommend the method here for the sake of less code cluttering the shared/jobs lua.
If you want one character less code then you could use team.NumPlayers.
Thanks guys so much
Sorry, you need to Log In to post a reply to this thread.