Possible to script up a respawn limit?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

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!)
Post Reply
User avatar
I'mMog
Posts: 8
Joined: Thu Feb 07, 2019 1:42 am

Possible to script up a respawn limit?

Post by I'mMog »

Hello, everybody! Been playing DOOM since '97. I'm semi-new to most of these parts. Played around quite a bit with Duke3D back in the day, but most of that knowledge has bled out of my head in the last 20 years. I have a few queries, honestly, and would love to just throw them all here, but I'm sure that would be frowned upon. On to the query at hand...

Something I thought of when I first started playing DOOM with the respawn tag on was, is it possible to write a script that limits how many respawns there are? The original thought would be to just 200~300% of the map, but now, I'm thinking if it's possible to do that to 2~3 times per monster (except boss enemies). Maybe even something that is changeable as to which monster/item respawns X number of times in a menu from an iwad? I'm sure it's possible, I just don't know where to start (outside of learning the script from scratch). Thank you for your time!
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Possible to script up a respawn limit?

Post by Matt »

I'm in the middle of (re)writing something like that now...

Can be done in ACS or ZScript, might be easier with the latter.

Have something (probably an integer array in a thinker) track the number of times each player has died.

Create a function that returns a death count depending on the game mode:
- Coop: Add up all the deaths from everybody. (use a for loop: "for (int i=0; i < MAXPLAYERS; i++)")
- FFA: Retrieve the death count for the player in question only.
- TDM: Find all members of the player in question's team and add up their death counts only. (something like "Players[n].GetTeam()")

When a player respawns, call the above function and see if the number exceeds the respawn limit. If it does, morph the player into a spectator (which playerclass you'll have to define (here's an example - the most important things are to make the spectator unshootable, non-solid and given a "userange" of zero so they can move around but can't actually influence the game)).

Have an additional check so that the map restarts or moves on to the next one if:
- Any mode: no one's death count is below the limit
- FFA: only one player's death count is below the limit
- TDM: all the players whose death counts are below the limit belong to the same team
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Possible to script up a respawn limit?

Post by Matt »

Of course, if you just want a general pool for co-op purposes and have no need for elimination modes, the only things to track are the total number of deaths and the limit.

(I think the total number of deaths is already internally tracked in GZDoom but I have no idea where... if it isn't or no one knows where it is, it can still be explicitly re-tracked in the script, it's just kinda redundant to do so.)
User avatar
I'mMog
Posts: 8
Joined: Thu Feb 07, 2019 1:42 am

Re: Possible to script up a respawn limit?

Post by I'mMog »

Thanks for the quick reply! I was looking for something more along the lines of monster/item respawns. There is already a tag in GZDoom that can turn unlimited respawns for monsters/items. I was just wanting to put a limit on how many times those things can respawn per map.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Possible to script up a respawn limit?

Post by Matt »

No idea how to do that at all, sorry.

(Is that even open to ZScript at this point?)
User avatar
I'mMog
Posts: 8
Joined: Thu Feb 07, 2019 1:42 am

Re: Possible to script up a respawn limit?

Post by I'mMog »

I don't see why it shouldn't be doable. It should just be adding another tag to them, like health, except it's "lives". Then have a menu option to assign how many lives they get.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Possible to script up a respawn limit?

Post by Arctangent »

Well, the main problem is that the monster and item respawn systems are currently completely hardcoded, leaving exactly nothing to hook into with scripting.

Though, if you want a simple, static limit on how many times all monsters can respawn, you can make new skill levels that make use of the RespawnLimit property. The +NEVERRESPAWN adds a bit of extra flexibility to this, although only to the extent of allowing a specific actor class to either respawn RespawnLimit times or not at all.

If you want anything more complicated, your best bet is to make a feature request to expose the default system to ZScript, or at least a part of it that makes sense to expose. And if that fails, you can always eschew the default respawn system entirely and make use of [wiki]A_Respawn[/wiki], like the standard exploding barrel does for the "Barrels respawn" dmflag ... though that's only geared towards respawning monsters, so you might have to recreate item respawning yourself if needed.
User avatar
I'mMog
Posts: 8
Joined: Thu Feb 07, 2019 1:42 am

Re: Possible to script up a respawn limit?

Post by I'mMog »

Weeeell, one way I could technically do it is rewrite how all of the enemies die. Instead of leaving their corpses at something like "BEAS Z -1" (just a body, dead forever), it SHOULD be possible to make a semi-random wait time before they bounce back up again, a different death state for the second and third times (provided I give it a limit of three). Not too sure if I could get them to pop back up from whence they originally spawned through known existing scripts. Heretic has an item that teleports the player back to the beginning of the level. I'd hope it could be used towards mobs as well, but that's a strong assumption.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Possible to script up a respawn limit?

Post by Matt »

For the enemies that's fairly straightforward enough. I think there's an A_Respawn() function too, but if it doesn't do what I think it does, then there's also RaiseActor() and the SpawnPoint variable.

Items, I'm not sure how to get around that except with, like, an invisible non-interactive actor that replaces the inventory item, which then calls A_SpawnItemEx with SXF_ISMASTER whenever
(a) it hasn't had a master for X tics
(b) it hasn't spawned its limited quota
Post Reply

Return to “Scripting”