Author Topic: Loading a random map when the server starts up  (Read 8949 times)

0 Members and 1 Guest are viewing this topic.

Offline Luk | twitch.tv/doctorluk

  • Newbie
  • *
  • Posts: 40
  • Karma: 12
Loading a random map when the server starts up
« on: March 05, 2015, 09:48:27 AM »
Hello everyone :)

I'm having some - expected - problems with my TTT Server. As you all know GMod likes to crash once in a while and it's quite annoying if a map is being played many times because it's the server's default start map.

The start map is sometimes manually changed by me, but that is by far no permanent solution. I seek someone to create a script that randomly starts a map from the mappool on server start.

I've tried some LUA and made some progress but I'm not sure where to start and I'm also not sure whether there is a hook for the first server start.

Would be awesome if someone could help out :)
Host of Spielwiese der Erwachsenen, a German TTT Server for adults only.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Loading a random map when the server starts up
« Reply #1 on: March 05, 2015, 06:28:23 PM »
I'm 98% sure you wouldn't be able to do this strictly in lua.
I was about to say not at all, then my mind started thinking 'well, perhaps a startup batch file could read from a gmod\data\<somefile> that contains a map randomly selected on startup for NEXT time', but, unless you wanted the server to start up, load command line/config file map, then restart loading a random map, you'd HAVE to have the command line outside of lua loading whatever randomly selected map.

So, 2 options I see.
100% outside lua.
Have server start non-lua startup script randomly pick from map in a list.

Using GLua and outside.
Server starts, picks random, writes it to a \data\ file for next startup.
Next server start, command line reads the map from that \data\ file.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
Re: Loading a random map when the server starts up
« Reply #2 on: May 06, 2015, 10:16:54 PM »
I'm 98% sure you wouldn't be able to do this strictly in lua.
I was about to say not at all, then my mind started thinking 'well, perhaps a startup batch file could read from a gmod\data\<somefile> that contains a map randomly selected on startup for NEXT time', but, unless you wanted the server to start up, load command line/config file map, then restart loading a random map, you'd HAVE to have the command line outside of lua loading whatever randomly selected map.

So, 2 options I see.
100% outside lua.
Have server start non-lua startup script randomly pick from map in a list.

Using GLua and outside.
Server starts, picks random, writes it to a \data\ file for next startup.
Next server start, command line reads the map from that \data\ file.

Could you not use an array and then get a random value from the array and force the map to it? or even read the maps/ directory and pick a map random from the names (this would cause problems unless the maps are named like: (e.g) gm_flatgrass)
« Last Edit: May 06, 2015, 10:19:42 PM by Tomzen »
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: Loading a random map when the server starts up
« Reply #3 on: May 07, 2015, 03:52:53 PM »
I worked on a game mode a while ago where if the server crashed, it would go back to the last map it was on.  This is entirely possible through Lua and data files.

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Loading a random map when the server starts up
« Reply #4 on: May 08, 2015, 12:34:43 AM »
I worked on a game mode a while ago where if the server crashed, it would go back to the last map it was on.  This is entirely possible through Lua and data files.

Would such system load the server on a default map, check if it crashed, then load the map it was originally on?

Edit: I'm asking cause I think maps are loaded before Lua is. You wouldn't be able to manipulate this without loading the server twice. Correct me if I'm wrong though. :)
« Last Edit: May 08, 2015, 12:50:54 AM by Timmy »

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: Loading a random map when the server starts up
« Reply #5 on: May 08, 2015, 07:53:38 AM »
Would such system load the server on a default map, check if it crashed, then load the map it was originally on?

Edit: I'm asking cause I think maps are loaded before Lua is. You wouldn't be able to manipulate this without loading the server twice. Correct me if I'm wrong though. :)
You are completely correct.  It is almost instant and hardly noticeable though.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Loading a random map when the server starts up
« Reply #6 on: May 09, 2015, 08:10:36 AM »
Additionally, you could use a (batch cmd or shell depending on the OS your server is running on) script to read from a file created while server is running normally.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Loading a random map when the server starts up
« Reply #7 on: May 09, 2015, 01:54:54 PM »
Add a command to execute load_random_map.lua on your server shortcut/start-up script.
Experiencing God's grace one day at a time.

Offline Tomzen

  • Full Member
  • ***
  • Posts: 115
  • Karma: -1
  • A new lua adventurer
    • Thirdage Gaming
Re: Loading a random map when the server starts up
« Reply #8 on: May 12, 2015, 05:15:33 PM »
This isn't quite what you want, but I've made this: http://forums.ulyssesmod.net/index.php/topic,8549.msg43938
You could easily convert it to do it on start up.
Finished:
Impersonate
<==> FakePromote/Demote <==> RandomMap <==> ForceMic <==> Search <==> PlayMenu <==
WIP:
ServerMode <==