How can I detect a unit's life becoming certain value?

Status
Not open for further replies.

Rheiko

Spell Reviewer
Level 26
Joined
Aug 27, 2013
Messages
4,214
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Life of YourUnit) Greater than 200.00
    • Then - Actions
      • Unit - Set life of YourUnit to 200.00
    • Else - Actions
It depends on when you want to detect it. For example, you want to detect it when the unit takes a damage, then you should use DDS.
However, if you want to detect it all the time, you probably should use Periodic Timer as an event.
 
Level 2
Joined
Jun 28, 2016
Messages
12
You have to keep track of what units you added the life bonus to and how much that life bonus is. In addition, as system like DDS, detects instances of damage and will not respond to life regeneration or heals (depending on how you implement your heals). You'll have to supplement this with some periodic check to account for life regeneration. A damage detection system which detects all damage instances on the map is overkill if this buff (or effect?) will only be active on one or two easily tracked units. However, for a map that regularly requires damage detection on a large number of units - you should consider using DDS.

Edit: Say for example - you add an ability based on the item bonus health ability which grants 200 health. Now when you want to get the original life of the unit, you simply deduct 200 from the life if he has the ability.
Code:
True_Max_Life=GetUnitState(unit,UNIT_STATE_MAX_LIFE) - GetUnitAbilityLevel(unit,'ABID')*200.
Edit: Assuming unit is the unit and 'ABID' is your ability id of your custom bonus life ability.
 
Last edited:
Level 2
Joined
Jun 28, 2016
Messages
12
I'm not that familiar with the API of DDS myself - but you have 2 problems:
  • Getting the true life of an unit: Unfortunately there is no native function for doing so, so you have to have an way of obtain the original life value.
  • Detecting any changes to the unit's health and adjust its health as required.
    • Use a timer to check the units health (or group of units if this effect is active on multiple units). This is required for things life health regeneration and ensuring that the unit doesn't exceed its pseudo max life.
    • Use a self created trigger (or dds) to detect any changes due to damage. This is required since a unit might regain some life between the ticks of your timer and you want to reset the life before damage gets done.
 
Status
Not open for further replies.
Top