• Automatic Gamemode Switching Script for a server
    7 replies, posted
This is an interesting idea. I'm having some issues with a server my friend hosts, I'm admin but ULX is glitching and i can't override the game mode to sandbox for an event regarding my group. My idea is that at a certain time, judging by the System Clock on the computer that hosts the server, it will do an automated Gamemode Switch. After a few hours, it would switch back. How would this be done, and does it already exist? It seems like a great idea in my opinion.
Well, if i knew the function to change gamemode, i would make one for you ... i will be searching on the wiki...
Use the console command "sv_gamemode" "gamemode name".
[QUOTE=sintwins;23960426]Use the console command "sv_gamemode" "gamemode name".[/QUOTE] :golfclap:
Wow, now all i need is the arguments in gamemode.Register and i am done! [editline]04:59PM[/editline] Actually, nvm :3 i got that covered [editline]05:08PM[/editline] [LUA] local gamemodes = { } local old_reg = gamemode.Register function gamemode.Register( ... ) local ret = old_reg( ... ) local tab = {...} gamemodes[ #gamemodes + 1 ] = tab[1] return ret end function gamemode.ChooseRandomGamemode() local cur = gmod.GetGamemode() local tab = gamemodes for k,v in pairs( tab ) do if v == cur then table.remove( tab , k ) break end end local random = table.Random( tab ) game.ConsoleCommand( "sv_gamemode " .. random ) end [/LUA] use it with a timer :) goes serverside
Thats a random gamemode.... I meant to have it be Sandbox, and then back to another gamemode
then modify it yourself... its not that hard.
[lua] local gms = { -- Hour to change on (00-23), gamemode folder name, map name { hour = 06, gamemode = "sandbox", map = "gm_flatgrass" }, { hour = 16, gamemode = "prop-hunt", map = "cs_office" } } timer.Create("GamemodeChanger", 60, 0, function() for _, v in pairs(gms) do if v.hour == os.date("%H") and not GAMEMODE.FolderName == v.gamemode then RunConsoleCommand("changegamemode", v.map, v.gamemode) end end end) [/lua] Untested but should work. Not too sure about the GAMEMODE.FolderName thing though, but I can't test at the moment. The timer could be changed to have a longer interval if you're _that_ bothered about performance, though if the server crashed, it would only take 1 minute until the gamemode was changed back to what it should be (within the same hour).
Sorry, you need to Log In to post a reply to this thread.