• Changing map at a certain time/date
    14 replies, posted
Is it possible to make a script which changes a specific map on a particular day? So this kind of roster would work automatically? [b] Sunday to Wednesday - <some random map here> Thursday - <some random map here> Friday - <some random map here> Saturday - <some random map here>[/b] So it changes at exactly 12 am of that day? Thanks
Yep.
os.Date() [url]http://wiki.garrysmod.com/?title=Os.date[/url] ; )
[lua]local function Map(map) game.ConsoleCommand("changelevel "..map) end sunwed = "gm_construct" thurs = "gm_flatgrass" fri = "freespace06" sat = "gm_wireconstruct_rc" hook.Add("Think","CheckDate",function() if os.date("%H") == "12" then local weekday = os.date("%A") if weekday == "Sunday" or weekday == "Monday" or weekday == "Tuesday" or weekday == "Wednesday" then Map(sunwed) elseif weekday == "Thursday" then Map(thurs) elseif weekday == "Friday" then Map(fri) elseif weekday == "Saturday" then Map(sat) end end end)[/lua] It's something like this (I think). You would have to check me on my os.date stuff.
[QUOTE=Entoros;16793165][lua]local function Map(map) game.ConsoleCommand("changelevel "..map) end sunwed = "gm_construct" thurs = "gm_flatgrass" fri = "freespace06" sat = "gm_wireconstruct_rc" hook.Add("Think","CheckDate",function() if os.date("%H") == "12" then local weekday = os.date("%A") if weekday == "Sunday" or weekday == "Monday" or weekday == "Tuesday" or weekday == "Wednesday" then Map(sunwed) elseif weekday == "Thursday" then Map(thurs) elseif weekday == "Friday" then Map(fri) elseif weekday == "Saturday" then Map(sat) end end end)[/lua] It's something like this (I think). You would have to check me on my os.date stuff.[/QUOTE] You'd have to have a Bot or at least one Player on the server all the time, since Think hooks and timers don't get called when there is noone on the server ;)
what about [url]http://wiki.garrysmod.com/?title=Schedule.Add[/url] ?
[QUOTE=Entoros;16793165][lua]local function Map(map) game.ConsoleCommand("changelevel "..map) end sunwed = "gm_construct" thurs = "gm_flatgrass" fri = "freespace06" sat = "gm_wireconstruct_rc" hook.Add("Think","CheckDate",function() if os.date("%H") == "12" then local weekday = os.date("%A") if weekday == "Sunday" or weekday == "Monday" or weekday == "Tuesday" or weekday == "Wednesday" then Map(sunwed) elseif weekday == "Thursday" then Map(thurs) elseif weekday == "Friday" then Map(fri) elseif weekday == "Saturday" then Map(sat) end end end)[/lua] It's something like this (I think). You would have to check me on my os.date stuff.[/QUOTE] Looks good.
[QUOTE=Entoros;16793165][lua]local function Map(map) game.ConsoleCommand("changelevel "..map) end sunwed = "gm_construct" thurs = "gm_flatgrass" fri = "freespace06" sat = "gm_wireconstruct_rc" hook.Add("Think","CheckDate",function() if os.date("%H") == "12" then local weekday = os.date("%A") if weekday == "Sunday" or weekday == "Monday" or weekday == "Tuesday" or weekday == "Wednesday" then Map(sunwed) elseif weekday == "Thursday" then Map(thurs) elseif weekday == "Friday" then Map(fri) elseif weekday == "Saturday" then Map(sat) end end end)[/lua] It's something like this (I think). You would have to check me on my os.date stuff.[/QUOTE] [lua]local function changemap(map) game.ConsoleCommand("changelevel "..map) end local sunwed,thu,fri,sat = "gm_construct","gm_flatgrass","freespace06","gm_wireconstruct_rc" timer.Create("map changer",60,0,function() if os.date"%H%M" == "1200" then local w = tonumber(os.date"%w") if w < 4 then changemap(sunwed) elseif w == 4 then changemap(thu) elseif w == 5 then changemap(fri) else changemap(sat) end end end[/lua]
[QUOTE=Carnag3;16793523]what about [url]http://wiki.garrysmod.com/?title=Schedule.Add[/url] ?[/QUOTE] this. stop running think hooks. [code] schedule.Add("mapChange", mapMonday, 00, 00, 00, "Monday", nil, nil, nil) function mapMonday() --change map here end[/code]
Could someone write out a code to suit this? Sunday to Wednesday - gm_flatgrass Thursday - gm_contruct Friday - rp_coast_03_fix Saturday - Atomic. Thanks all for your help.
bump
[lua] schedule.Add("mapChange1", function() game.ConsoleCommand("changelevel mapname") end, 00, 00, 00, "Monday", nil, nil, nil) schedule.Add("mapChange2", function() game.ConsoleCommand("changelevel mapname") end, 00, 00, 00, "Tuesday", nil, nil, nil) schedule.Add("mapChange3", function() game.ConsoleCommand("changelevel mapname") end, 00, 00, 00, "Wednesday", nil, nil, nil)[/lua] And so on, and so on.
[QUOTE=Lexic;16851885][lua] schedule.Add("mapChange1", function() game.ConsoleCommand("changelevel mapname") end, 00, 00, 00, "Monday", nil, nil, nil) schedule.Add("mapChange2", function() game.ConsoleCommand("changelevel mapname") end, 00, 00, 00, "Tuesday", nil, nil, nil) schedule.Add("mapChange3", function() game.ConsoleCommand("changelevel mapname") end, 00, 00, 00, "Wednesday", nil, nil, nil)[/lua] And so on, and so on.[/QUOTE] Do I put this file in autorun? Or in the gamemodes folder and include it?
[QUOTE=SeeDee;16852577]Do I put this file in autorun? Or in the gamemodes folder and include it?[/QUOTE] neither, because that code doesn't work. It's what we call an '[i]example[/i]', that shows you how you could do something yourself, but would break if you tried to use it without first modifying it. But when you have filled in the missing days and missing mapnames, yes, you put it in autorun/server/
[QUOTE=Lexic;16852621]neither, because that code doesn't work. It's what we call an '[i]example[/i]', that shows you how you could do something yourself, but would break if you tried to use it without first modifying it. But when you have filled in the missing days and missing mapnames, yes, you put it in autorun/server/[/QUOTE] I know :) I'm not /that/ stupid. And thanks
Sorry, you need to Log In to post a reply to this thread.