Hello.
I would like to make a timer that: if there aren't 7+ players, demote the player to Citizen.
I tried to use the customjobfield (PlayerSpawn), but I don't know why, it doesn't work:
TEAM_MYTEAM = DarkRP.createJob("MyTeam", {
color = Color(170, 190, 255, 255),
model = {""},
description = [[description]],
command = "command",
max = 1,
salary = 0,
admin = 0,
vote = false,
hasLicense = false,
customCheck = function(ply) return #player.GetAll() > 7 end,
PlayerSpawn = function(ply)
timer.Create("DemoteIf", 1, 0, function()
if ply:Team() == TEAM_MYTEAM and #player.GetAll() < 8 then
DarkRP.notify(ply, 1, 5, "You will be demoted in 120 seconds")
timer.Simple(120, function()
ply:changeTeam( TEAM_CITIZEN, true )
end)
end
end)
end,
category = "Gangsters"
})
Any script error appears in the console, simply it doesn't work.
Maybe have I to use customCheck and not PlayerSpawn?
Thank you!
Use [code] tags in the future. Also, don't declare the timer everytime on PlayerSpawn, just run the timer:
[code]timer.Create( "MyTeamDemote", 5, 0, function()
if ( #players.GetAll() < 7 ) then
local tTeamPlayers = team.GetPlayers( TEAM_MYTEAM )
for i = 1, #tTeamPlayers do
tTeamPlayers[i]:SetTeam( TEAM_CITIZEN )
end
end
end )[/code]
[editline]4th July 2016[/editline]
Alternatively, you could make this more efficient by tracking a variable in the PlayerConnect/Disconnect hooks, but that'd be a little more work.
[QUOTE=code_gs;50644557]Use [code] tags in the future. Also, don't declare the timer everytime on PlayerSpawn, just run the timer:
[code]timer.Create( "MyTeamDemote", 5, 0, function()
if ( #players.GetAll() < 7 ) then
local tTeamPlayers = team.GetPlayers( TEAM_MYTEAM )
for i = 1, #tTeamPlayers do
tTeamPlayers[i]:SetTeam( TEAM_CITIZEN )
end
end
end )[/code]
[editline]4th July 2016[/editline]
Alternatively, you could make this more efficient by tracking a variable in the PlayerConnect/Disconnect hooks, but that'd be a little more work.[/QUOTE]
Is My method completely wrong? Or you used another way for do that?
Your method would just recreate the same timer everytime a player spawns from that team and it would never be removed. I don't see a way with your method actually working
Thank you!
Last question, can I do this?:
[CODE]
timer.Create( "DemoteIF", 5, 0, function()
if ( #players.GetAll() < 7 ) then
DarkRP.notify(ply, 1, 5, "you will be demoted in 300 seconds!!")
timer.Simple(300, function()
local tTeamPlayers = team.GetPlayers( TEAM_MYTEAM )
for i = 1, #tTeamPlayers do
tTeamPlayers[i]:SetTeam( TEAM_CITIZEN )
end
end)
end
end )
[/CODE]
No, because you'll print the notification every 5 seconds, and the player is not guarenteed to be that job after 300 seconds. I'll post a better solution when I get home.
[QUOTE=code_gs;50646475]No, because you'll print the notification every 5 seconds, and the player is not guarenteed to be that job after 300 seconds. I'll post a better solution when I get home.[/QUOTE]
Ok, I'm waiting for you! Thanks
did you forget it? xD
Sorry, you need to Log In to post a reply to this thread.