Is it possible to export the name of the map I am playing...

Tue Jun 22, 2021 10:14 am

Real title:Is it possible to export the name of the map I am playing to a CVar?

So, sometimes I play through a bunch of maps in a bot DM, then I forget the name of the map I was playing, then I have to keep using map commands to switch maps until I find one i don't remember, which is annoying. Is there a way to save the map name in a CVAR, then just be able to type out sv_lastmap or something like that, then type map <value from sv_lastmap goes here> dm?

Re: Is it possible to export the name of the map I am playin

Tue Jun 22, 2021 4:40 pm

Yep! A small ZScript mod can certainly do that.

Note this isn't tested and probably won't work as-is, but the concept should look something like:

CVARINFO
Code:
server string sv_lastmap;

MAPINFO
Code:
GameInfo { AddEventHandler = "SaveLastLevel"; }

ZSCRIPT
Code:
class SaveLastLevel : EventHandler {
  override void WorldLoaded(worldevent e) {
    CVar lastmap = CVar.FindCVar('sv_lastmap');
    lastmap.SetString(level.MapName);
  }

  override void OnRegister() {
    CVar lastmap = CVar.FindCVar('sv_lastmap');
    console.printf("Last played map was ... "..lastmap.GetString());
  }
}

Having this mod autoloaded should automatically save the current map lump name into a cvar every time you load into a new map. Ideally, this shouldn't conflict with anything at all, so you could set it up and forget about it.

Of course, starting a new game would instantly overwrite your sv_lastmap cvar, so check it first if you want to know! :laff:

EDIT: Added an OnRegister() override that prints the last played map to the console when the event handler is registered, so if you do accidentally start a new game you can just check the console.

8-)

Re: Is it possible to export the name of the map I am playin

Mon Jul 26, 2021 9:26 am

Caligari87 wrote:Yep! A small ZScript mod can certainly do that.

Note this isn't tested and probably won't work as-is, but the concept should look something like:

CVARINFO
Code:
server string sv_lastmap;

MAPINFO
Code:
GameInfo { AddEventHandler = "SaveLastLevel"; }

ZSCRIPT
Code:
class SaveLastLevel : EventHandler {
  override void WorldLoaded(worldevent e) {
    CVar lastmap = CVar.FindCVar('sv_lastmap');
    lastmap.SetString(level.MapName);
  }

  override void OnRegister() {
    CVar lastmap = CVar.FindCVar('sv_lastmap');
    console.printf("Last played map was ... "..lastmap.GetString());
  }
}

Having this mod autoloaded should automatically save the current map lump name into a cvar every time you load into a new map. Ideally, this shouldn't conflict with anything at all, so you could set it up and forget about it.

Of course, starting a new game would instantly overwrite your sv_lastmap cvar, so check it first if you want to know! :laff:

EDIT: Added an OnRegister() override that prints the last played map to the console when the event handler is registered, so if you do accidentally start a new game you can just check the console.

8-)



Doesn't work, as expected.

Spoiler:


How do I fix this? I have zero ZScript experience.

Re: Is it possible to export the name of the map I am playin

Mon Jul 26, 2021 11:55 am

Add
Code:
version 4.6
to the beginning of ZSCRIPT lump.

Re: Is it possible to export the name of the map I am playin

Mon Jul 26, 2021 2:07 pm

m8f wrote:Add
Code:
version 4.6
to the beginning of ZSCRIPT lump.


now it loads, but typing sv_lastmap says that it's value is " ".