Jump to content
  • 0

Lost Soul Limit for Individual Pain Elementals


Skunkbear

Question

Hello All,

 

I was just wondering if there's an easy way to limit the amount of Lost Souls that any individual Pain Elemental can have spawned and active at any given time (e.g. if the limit was 3 and a Pain Elemental had spawned 3 which were still alive, then it wouldn't be able to spawn any more until at least one was killed)? I can't seen to find any info about this on the Zdoom Wiki or old forum posts apart from ones talking about the original Vanilla limit of 21 Lost Souls total for the entire map.

 

Thanks in advance.

Share this post


Link to post

7 answers to this question

Recommended Posts

  • 0

I'm not proficient with this particular code, but thinking of it from a coding perspective, if a PE is spawning LS, then I would assume the LS would have to have a reference back to how it was created, via PE or just normal spawn. I don't know if this is already built in or not, but I would assume not and I would also assume its just spawning an LS object, and the normal LS object has no reference to how it was instantiated. If that's the case, you wouldn't be able to limit a specific PE's LS spawns. What I would imagine is you would have to create a new PE object and a new LS object, and the nPE only spawns nLS, and those nLS have references to which nPE spawned it. Then you can limit it in code under the nPE. I'm just speculating all of this. But if the actions and behavior is identical, players couldn't tell a difference, and you would get what you wanted. Just always use the new Pain Elemental

Share this post


Link to post
  • 0

Is there an easy way? No.

 

Is there a way? Probably.

 

This is several levels above my understanding of ZScript at the moment and there might be a better way than this, but I'd guess your approach would be to create a new class of Pain Elemental (or replace the existing one) that overrides the existing lost soul spawn function. You'd then have a variable assigned to the PE that tracks how many souls it has active. For the function:

  • First, it would only spawn if the variable is under the limit.
  • Second, it would spawn a Lost Soul with a specific reference back to the PE. You might need a custom LS enemy as well for this. (You could potentially use TagIDs for these links, but that could screw up your map if you want to assign tags to monsters for other reasons). Maybe the simplest approach would be to assign a value to each newly spawned PE and that same value to its "children".

You'd then want an event handler that looks for monster deaths. If that death is one of your custom Lost Souls, you can use that reference value to identify which PE has opened up a new "slot" for a new LS and decrement the value for it.

 

Where the headaches start will be scope - event handlers and monster details may not want to talk to each other in this way - and this is where my knowledge of ZScript fails me. Hopefully the suggestion above is enough to get you started.

 

 

Share this post


Link to post
  • 0

I don't know ZScript either, so my knowledge is coming from C++/C# and Java. To add to what Artinum said, the value would be on the PE, and reference would be on LS. The LS doesn't need to have access to the entire PE details, or have a copy of anything, just a reference to some value. The LS object doesn't care what that value is or where it comes from. It just decrements it upon death. The PE does all the calculations on the value.

So wouldn't that mean you don't need an EventHandler to look at all monster deaths. You just need EventHandler on the LS to look at when it dies? When it dies, it calls back to the referenced value to change it. I wouldn't think that would be out of scope since its referenced. Again, I have no idea about zScript, so none of this may even be applicable to it.

Share this post


Link to post
  • 0

I agree that Event Handler is kinda overkill here.

LS does not even need to be modified, everything could be done in a PE replacement class (it could have an array of references to spawned souls, and when it is about to attack, it would check if it has a free "slot", or if any of the referenced souls are dead).

 

Most problematic thing here is, that A_PainAttack (and A_PainShootSkull) does not return any reference to the spawned LS, neither it gives the spawned LS reference to itself, so you would probably need to extract code from A_PainShootSkull and modify it so it returns reference to the LS.

Share this post


Link to post
  • 0

A global event handler is probably overkill, but I'm not entirely sure how to work them and I don't know whether a smaller scope would be possible.

 

You can certainly assign a value to each PE and then assign that same value to an equivalent variable in the LS objects when you spawn them, and you can certainly include some custom code in the LS's Die() function, but feeding data back to the PE could be out of scope.

 

That said, I'm vaguely aware (since yesterday evening, when I was investigating something else) that there are parent/child relationships in ZScript, which might tie your PE parent to LS children - so you might be able to do something with that instead of using event handlers at all. However, I have no idea how to use them!

Share this post


Link to post
  • 0
8 minutes ago, Artinum said:

there are parent/child relationships in ZScript, which might tie your PE parent to LS children

 

Those exist, but unfortunately, PE's soul spawning procedure does not create this relationship. There are no links from PE to LS or from LS to PE (so even with an event handler, you can't link dying LS to its originator).

 

Share this post


Link to post
  • 0
4 hours ago, jaeden said:

 

Those exist, but unfortunately, PE's soul spawning procedure does not create this relationship. There are no links from PE to LS or from LS to PE (so even with an event handler, you can't link dying LS to its originator).

 

 

You'd need to replace it with your own code, I guess - apart from anything else, the standard PE code would spawn regular LS enemies without your variable check. If you can then spawn LS enemies as child objects to the parent PE class, you may be able to feed information back and forth.

 

I've unearthed an old post that seems to be heading in a similar direction:

Hopefully the code in there will help point you (OP, I mean) in the right direction!

Edited by Artinum

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...