Okay, here, what I've written.
I didn't find any command which returns number of players connected (Is there any?), so I had to do it that way.
When map is changed and it's not the defined one, server changes map properly. And when some1 joins timer stops.
But the disconnecting thingy doesn't work... The player disconnects but the function doesn't get called at all? Used "print( "Function got called" )" before the checks to determine it's getting called, but it's not.
But that's not a big deal, since the map just needs about 30 minutes till it's over even if no one is online.
Maybe some1 can refine my code or give me some hints? That's the first real code I wrote in lua and for GMod...
Code:
local changeMap = function()
if (table.Count(player.GetAll()) == 0) then
RunConsoleCommand( "changelevel", "ph_restaurant" )
end
end
local startTimer = function (i)
if (table.Count(player.GetAll()) == i ) then
if(!timer.Exists("mapChanger")) then
if (game.GetMap() != "ph_restaurant") then
timer.Create( "mapChanger", 180, 1, changeMap)
end
end
end
end
local stopTimer = function ()
if (timer.Exists("mapChanger")) then
timer.Remove("mapChanger")
end
end
hook.Add("Initialize", "StartTimerInit", startTimer(0))
hook.Add("PlayerConnect", "StopTimerConnect", stopTimer)
hook.Add("PlayerDisconnected", "StartTimerDC", startTimer(1))