DarkRP: Temporary Job Ban

Hello!
Alright so for when the mayor dies he will be changed to citizen, but I was wondering how I would make a team ban for when he dies, it bans him for X seconds.
Currently, I have this for mayor death:

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);

So how would I make this ban him from going the job TEAM_MAYOR for X seconds

You could try to look at the demote function? Maybe grab som code from that.

Thanks for the reasponse, where would the demote function be found?

Just saying, you don’t need to use ipairs unless you care about the order.

v:TeamBan()

So would it be something like
hook.Add(“PlayerDeath”,“DemoteMayor”,function(v,k)
if (v:Team() == TEAM_MAYOR) then
v:ChangeTeam(TEAM_CITIZEN,true);
v:TeamBan(“30”)
for k, v in ipairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTCENTER,“The mayor has died!”);
end;
end;
end);

No, it goes by this function
[lua]function meta:TeamBan(t)
if not self.bannedfrom then self.bannedfrom = {} end
t = t or self:Team()
self.bannedfrom[t] = 1
timer.Simple(GAMEMODE.Config.demotetime, function()
if not IsValid(self) then return end
self:TeamUnBan(t)
end)
end[/lua]
So you don’t need a string in your parentheses.

Oh, do you happen to know the default timer? Also where did you find that file?
Sorry i’m new to LUA and i’m just trying to learn some more of this.

You should be able to just use v:TeamBan(30) and not v:TeamBan(“30”). He’s just showing you the function to explain why you don’t need to use a string for the argument there. The function is coded into the base darkrp gamemode and already includes a timer, all you have to do is call v:TeamBan(30) which will “team ban” the player for 30 seconds then unban them according to the Timer.Simple function: http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index93f1.html http://wiki.garrysmod.com/page/Libraries/timer/Simple.

Secondly, you don’t need to use ipairs unless you want the table it produces to be in a specific order (which is unnecessary and takes extra computing power or whatever that is unneeded for your purposes). Just replace ipairs with pairs.

As a matter of etiquette, you should also disclose any code you post within [lua] brackets so it looks like this:
[lua]testing[/lua] It makes it much easier to read

Wow thank you, that answer was amazing.
After readying a little on the wiki about LUA tutorial, I understood this.
Also I looked for the [lua] button but could not find one, thanks for clearing that up.

[editline]5th December 2012[/editline]

When using this:
[lua]hook.Add(“PlayerDeath”,“DemoteMayor”,function(v,k)
if (v:Team() == TEAM_MAYOR) then
v:ChangeTeam(TEAM_CITIZEN,true);
v:TeamBan(300)
for k, v in ipairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTCENTER,“The mayor has been killed!”);
end;
end;
end);[/lua]
I do not get any errors but it simply does not work.

Should v:TeamBan(300) be before v:ChangeTeam(TEAM_CITIZEN, true)
???

Because v changed teams to citizen then you teamban them from citizen? idk if it works like that…