[ACS/Zscript] resetting cvars to default on new game? [SOLVED]

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
aeonlight
Posts: 29
Joined: Sat May 20, 2023 6:43 pm
Preferred Pronouns: They/Them

[ACS/Zscript] resetting cvars to default on new game? [SOLVED]

Post by aeonlight »

hello hello, looking for advice. I'd like to reset a few cvars I have set up when a new game is started. specifically, and this is the part I'm having trouble with, I'd like to to so before the replaceevents I have set up check against them.

to explain in more detail: I have a set of items I'm putting through a sequential replacement tree. once you have the first one, the next one starts spawning in its place, and so on in order. I've done this with a basic acs script that checks your inventory for each item when a level is unloaded for the transition screen and sets cvars to track which ones you have, and a zscript replacement eventhandler checking against these cvars to see which one of the set to spawn,
the trouble is, acs unloading scripts don't activate on new game, and when I tried using an eventhandler with newgame() and acs_execute it told me that the script wasn't recognised.

as it is, starting a new game doesn't reset the cvars, and thus doesn't reset the item upgrade progress, until the first end-of-map check. I'd like a way to fix this.
Last edited by aeonlight on Tue Aug 25, 2026 3:37 am, edited 1 time in total.
Jarewill
 
 
Posts: 1871
Joined: Sun Jul 21, 2019 8:54 am

Re: [ACS/Zscript] resetting cvars to default on new game?

Post by Jarewill »

I don't think using CVars for this is the best idea, as those are usually used for things that should carry over between sessions.
Event handlers can have their own set of variables that you can change, so you can use those instead of CVars, and you can directly modify those within ZScript too.
For example:

Code: Select all

Class ProgressionHandler : StaticEventHandler{ //StaticEventHandler is needed to remain loaded between maps
	bool shotgun_found; //Variable for storing if an item has been found already
	Override void WorldUnloaded(WorldEvent e){
		If(e.IsSaveGame){ //On loading a different save game, reset all variables
			shotgun_found = 0;
			Return;
		} //The map has already been loaded on a new save, so all replacements are correct. The variables will be updated once the map is unloaded
		let playe = players[consoleplayer]; //Get a pointer to the player
		If(playe&&playe.mo){ //Sanity check to make sure the player actually exists
			If(playe.mo.FindInventory("Shotgun")){shotgun_found = 1;} //If the player has a shotgun, set the variable to true
		}
	}
	Override void CheckReplacement(ReplaceEvent e){
		If(e.Replacee is "Shotgun" && shotgun_found){e.Replacement = "SuperShotgun";} //CheckReplacement makes use of the variables
	}
	Override void NewGame(){
		shotgun_found = 0; //On new game, reset all variables
	}
}
User avatar
aeonlight
Posts: 29
Joined: Sat May 20, 2023 6:43 pm
Preferred Pronouns: They/Them

Re: [ACS/Zscript] resetting cvars to default on new game?

Post by aeonlight »

huuuuh. yeah, I didn't know about any of this. I'm very beginner-level self-taught zscript and the wiki doesn't really explain how to do this kind of thing at all. I couldn't find any resources for checking player inventory without using acs, so this is a massive help, thank you
Jarewill
 
 
Posts: 1871
Joined: Sun Jul 21, 2019 8:54 am

Re: [ACS/Zscript] resetting cvars to default on new game?

Post by Jarewill »

Everyone starts somewhere and the wiki is indeed quite hard to find ZScript information on.
There are a few methods of checking inventory in ZScript, but my favorite one is FindInventory as it returns a direct pointer to the found item (or null if not found).
User avatar
aeonlight
Posts: 29
Joined: Sat May 20, 2023 6:43 pm
Preferred Pronouns: They/Them

Re: [ACS/Zscript] resetting cvars to default on new game?

Post by aeonlight »

Jarewill wrote: Tue Aug 25, 2026 3:18 am the wiki is indeed quite hard to find ZScript information on.
it wasn't much help with acs either lol. thanks again!

Return to “Scripting”