[Solved] Unit suicides after taking damage

Status
Not open for further replies.
Level 1
Joined
May 3, 2017
Messages
5
Hey all,

I want to create a unit that, upon recieving fatal damage/health comes under a certain threshold, triggers a countdown, before it explodes and deals area damage.

Think Rotfiends from Witcher 3, link below:


The map will have respawning enemies, so if it's possible for such a feature to be included with the base editor, any help would be appreciated.


Thanks for reading
 
There is an event for detecting when a specific unit's health changes, I suggest to start from there.
The event is only for a specific unit put there when the event is added to the trigger (unless they changed it in the new patch).
For it to work for more than one unit, you can use additional triggers to add the event for every unit on the map at map initialization, and for every unit created after (detecting "unit enters Playable map area"), using the command "Trigger - Add new event".

Then in the main trigger (for which you add events with the previous ones) you would need to store the damaged unit in whichever way you want (local variable, array, hashtable), create a text tag for the countdown, etc.
 
I’d just put the units into a group and check their health with a fast periodic trigger. If any of them are low enough to activate, create a floating text and add them to a dynamically-indexed list of counting down enemies (3 parallel arrays: unit, floating text, & time remaining). Then (in same trigger) loop through the list, reduce each unit’s timer by the timer period, update the floating text, and if time left is <= 0 explode the unit.
 
Damage detection system. When unit of the type takes damage and its current health is below the threshold then added it to a timed explosion system.

Such system might be an array set which is iterated through every second and decrements a counter associated with the unit. When that counter hits 0 then the unit explodes. This is implemented by picking all appropriate victim units nearby and dealing the desired damage to them from the exploding unit and finally killing the exploding unit and performing clean up. This will give correct kill credit since the exploding unit will be alive if its damage kills someone and the exploding unit itself will have a null killer.
 
You may also consider using a timed life and damage on death ability. What you would need then would be a damage detection system to detect when the unit took enough damage so you can add timed life and add the damage on death ability.

  • Actions
    • Unit - Make *your unit* Explode on death
    • Unit - Add a 10.00 second Generic expiration timer to *your unit*
    • Unit - Add AOE damage upon death (Big Mine) to *your unit*
 
My solution to this (although simpler) was to periodically add every unit on the map to a Unit Group, check ever 0.1 seconds if units' health within that Group was below a certain value, and then add a custom, damage dealing ability with visual effects to said unit. It also checks if the unit has the damage dealing ability, and doesn't add it if it detects the ability on the unit. Gave the exploding unit alot of armor to keep it alive for good measure, and made it pause what it's doing to give the players time to evade the explosion during the sequence.

When the unit dies, a dummy unit with short timed life is created, which explodes on death using the landmine ability.

There are probably a lot of more elegant solutions to this problem, but this worked for me atleast :D

Thanks for all the replies
 
Status
Not open for further replies.
Back
Top