Is there any way I can restart / stop a server using server side lua? I've tried doing RunConsoleCommand('exit'), as well as game.ConsoleCommand("exit") but it seems to block that. The "killserver" command works but it does not have the behavior that I would like it to, where a script running in the background can restart the server when it stops. Any help is appreciated, thank you.
You can do a trick using a cfg file. For example, one of the automatically executed CFG files that is unused in garrysmod is network.cfg
garrysmod/cfg/network.cfg, If it doesn't exist you can create it.
Lua blocks console commands based on string and not the command reference.
So put this in the network.cfg file.
[code] alias restart_server "exit" [/code]
Now, you'll be able to use restart_server to exit your server.
[lua] RunConsoleCommand("restart_server") [/lua]
Cheers.
You can just do [B]RunConsoleCommand( "_restart" )[/B], which is a native command that works fine.
[QUOTE=Mista Tea;48618509]You can just do [B]RunConsoleCommand( "_restart" )[/B], which is a native command that works fine.[/QUOTE]
I had no idea this was a thing... seems to be working. Thank you!
[QUOTE=Mista Tea;48618509]You can just do [B]RunConsoleCommand( "_restart" )[/B], which is a native command that works fine.[/QUOTE]
:( I've had trouble in the past where it hangs the server.
[QUOTE=Freezebug;48618736]:( I've had trouble in the past where it hangs the server.[/QUOTE]
I've only used it a few times and don't remember having an issue. Dunno :/
[QUOTE=Freezebug;48618736]:( I've had trouble in the past where it hangs the server.[/QUOTE]
I've had it run daily for a few months with no issues.
Sorry, you need to Log In to post a reply to this thread.