How to create a mapcycle?(DARKRP)

How would I create a map cycle for DarkRP?

I would like to have one map playing through the day. Lets say about 10am till 6pm then the mapchange would start and the night map at 6pm till 10am again.

Is this possible to do?:smile:

You could create a timer and index the maps from a table. Then use game.ConsoleCommand to have the server change the map to the next index.

How would timers work with this? The change are to occur at a specific time, not time after server started or whatever, if you used timers, you would have to calculate how much time untill it actually have to change map, rather than some other more practical, fail-safe way.

OT:
You’d want to have a timer that loops every minute or so and checks wether tonumber(os.date("%H")) is equal to 18 or 10, in that case, change map to whatever using **[Game.ConsoleCommand

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Game.ConsoleCommand)** like Chessnut said.
**[Os.date

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Os.date)**
**[Timer.Create

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Timer.Create)**
You’d want to start the timer here:
**[Gamemode.Initialize

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.Initialize)**

[lua]
hook.Add(“Initialize”,“142154125781258125”,function()
timer.Create(“DRP.AutoMap”,60,0,function()
if tonumber(os.date("%H")) >= 18 and not game.GetMap() == “NIGHTMAP.bsp” then
game.ConsoleCommand(“map NIGHTMAP.bsp
“) //Keep that
there.
elseif (tonumber(os.date(”%H”)) >= 10 and tonumber(os.date("%H")) < 18) and not game.GetMap() == “DAYMAP.bsp” then
game.ConsoleCommand("map DAYMAP.bsp
") //Keep that
there.
end
end)
end)
[/lua]

Thank you so much, only other question I have is for OS.date how would I get it to run off of my time zone? It’s hosted off a website.

It doesn’t already?
If it doesn’t, put if SERVER then infront of the timer, and an end after the timer’s end), which is the first one with a parenthese

If you want to offset the time zone it gets slightly more complicated.


local offset = 2 // will make it 2 hours later than what the server's timezone is.
hook.Add("Initialize","142154125781258125",function()
	timer.Create("DRP.AutoMap",60,0,function()
		local osd = tonumber(os.date("%H"))
		local offseted = (osd+offset)%24
		if offseted >= 18 and not game.GetMap() == "NIGHTMAP.bsp" then
			game.ConsoleCommand("map NIGHTMAP.bsp
") //Keep that 
 there.
		elseif (offseted >= 10 and offseted < 18) and not game.GetMap() == "DAYMAP.bsp" then
			game.ConsoleCommand("map DAYMAP.bsp
") //Keep that 
 there.
		end
	end)
end)

I haven’t really done a hours offset like this before, but with my maths it should work.
Change the “local offset = 2” to whatever “delay” you want based on server time. If server’s timezone is GMT-5, and you want it to be at GMT+2, you set offset to 7. offset can NOT be negative, instead work it around 24 hours, so instead of -1, put 23.