Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • 0
gufu

Selecting random Actor of a specific class through ACS (GZDOOM)

Question

Greetings. I probably should be asking this question on ZDoom forums, but I decided to try my luck here first. I'm working on a mod where at some point, a script should select a random actor that would be replaced by a newly spawned actor. Currently, I do have a similar function that replaces a monster that is targeted by a player (using SetActivatorToTarget) - but I wish for the new script to keep trying to select a new Actor until one of a specific kind (Pinky, Imp, or Lost Soul) has been selected. Sadly, I don't believe there is an ACS function to select a random Actor nor a random Actor of a kind.


 

 

 

 

Is there a viable way to achieve this? I would like the newly spawned Actor to be a surprise for a player, rather than being spawned right in front of them (I guess I could also have them spawn in place of an existing monster, have them be tied in Parent/Child relationship and become visible/regain bounding after a few seconds - but that feels incredibly hacky, even for Doom).


 

 

 

 

Bonus question: Is there a way to set Actor's Maximum health? Currently, I modify player's health using cloned UpgradeStamina object. However, I wish to be able to reduce player's maximum health as well.
 

Share this post


Link to post

6 answers to this question

Recommended Posts

  • 0

Define an array with class names or spawn numbers of several different actors, call Random to generate a number between 0 and the index of the last item in the array, use the generated number as an index into the array to get a class name or spawn number from, and use a spawning function to spawn an actor of that type. (EDIT: Wait, I probably misunderstood the question, sorry.)

4 hours ago, gufu said:

Bonus question: Is there a way to set Actor's Maximum health? Currently, I modify player's health using cloned UpgradeStamina object. However, I wish to be able to reduce player's maximum health as well.

According to this page, "Inventory.MaxAmount" in the definition of the UpgradeStamina-derived pickup is doing just that. (EDIT: I might have misunderstood this question as well, can't tell.)

Share this post


Link to post
  • 0

Sadly, that won't do: I wish to be able to select an existing random actor on the map (preferably of a set type), so I can use their X,Y,Z, and Facing Angle to spawn another actor in it's exact location. The problem is not spawning - it's being able to select a random Actor on the map.


 

 

 

As for US's MaxAmount, it does not appear to allow for values to go below the regular 100 health, since you can only take away US itself. A workaround, perhaps, is to set player health to 1HP by default, and have them receive 99 US's at ENTER state?
 

Share this post


Link to post
  • 0

There's currently, at least to my knowledge, no ACS function that would let you select a specific monster without an associated TID, nor target a group of monster based on their type. So, you need to tackle this first.

 

I'd start by altering all types of monsters with decorate. Each type (eg Imp) now calls a script once in its spawn state. This script assigns a free TID within a specified TID range for that type of monster (eg. 100 to 200 for type Imp). A subsequent script can now randomly choose from such a range a specific TID, which you can then use directly for whatever you had in mind.

 

About current health of the actor: you can set this with SetActorProperty.

Share this post


Link to post
  • 0

The call ACS call in decorate seems like a viable approach. Shame that it will reduce cross-mod compatibility (unless I modify base Actor class or something).


 

 

 

As for health question, I wish to edit Maximum Player Health - NOT current health.
 

Share this post


Link to post
  • 0

Wonderful, can't believe I missed that Property entirely. This simplifies things  so much for me. Thank you.
 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×