• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Life Steal Based on Attacked Units % Life

Status
Not open for further replies.
Level 2
Joined
Jul 26, 2011
Messages
12
Hello there.
I'm making a spell called "Life Tap" similar to Diablo II's necromancer curse.

For those who isn't familiar with Life Tap; there's two explanations of this:
1. Any monster that is STRUCK by physical damage, while under this curse(buff), adds 50% of the damage RECEIVED to the monster to the attackers life pool.
2. Basically life leech. It's like having a 50% Life Leech.

And now to the point
A unit have Life Tap Buff - i want attacking unit(any attacking unit not only melee) to get life steal based on attacked units Life.

So if attacked unit have 100% life(FULL) then i want the attacking unit to have 100% life steal.
If attacked unit have 34% life left, then i want to give attacking unit 34% life steal.

So a life steal ability based on units % life.
 
Level 8
Joined
Jul 3, 2011
Messages
251
Solution

Use this

  • Dmg Start
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Trigger - Add to Damage Event <gen> the event (Unit - (Picked unit) Takes damage))
  • Dmg Add
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • Trigger - Add to Damage Event <gen> the event (Unit - (Triggering unit) Takes damage)
  • Damage Event
    • Events
    • Conditions
      • ((Triggering unit) has buff YourBuffHere) Equal to True
    • Actions
      • Unit - Set life of (Damage source) to ((Life of (Damage source)) + ((Damage taken) x ((Percentage life of (Triggering unit)) / 100.00)))
It adds all possible units as an event for said unit taking damage, checks if they have the buff and if so heals the damaging unit.
 
Level 5
Joined
Jun 30, 2004
Messages
170
Do know that those triggers will cause leaks since the units being referenced each time Damage Event is added will be dead. And if they're body disappears they're gone forever.
 
Level 8
Joined
Jul 3, 2011
Messages
251
Do know that those triggers will cause leaks since the units being referenced each time Damage Event is added will be dead. And if they're body disappears they're gone forever.

Pretty sure they arent being referrenced each time, look at it this way; it is adding them as an event for the trigger, so if say 5 units are on the map it would theoretically look something like this:

  • Unit - Paladin 0000 <gen> Takes damage
  • Unit - Paladin 0001 <gen> Takes damage
  • Unit - Paladin 0002 <gen> Takes damage
  • Unit - Paladin 0003 <gen> Takes damage
  • Unit - Paladin 0004 <gen> Takes damage
So only one unit is being referrenced.
 
Level 5
Joined
Jun 30, 2004
Messages
170
Oh, no. What I mean was that since there's no way to remove events after they are made, they will stay there. For Heroes this isn't a problem, but for regular units that have their IDs removed after decay, it is. The event will still be there, but the unit it is referenced to is gone.

Well, there's not "no way" to remove events. The only way I know how to do is this to reset the trigger so all events are gone, but resetting the trigger also means removing every event referenced to a unit that is still alive. I don't think that should be a problem, now that I think about it... Or is it?
 
Level 8
Joined
Jul 3, 2011
Messages
251
Oh, no. What I mean was that since there's no way to remove events after they are made, they will stay there. For Heroes this isn't a problem, but for regular units that have their IDs removed after decay, it is. The event will still be there, but the unit it is referenced to is gone.

Well, there's not "no way" to remove events. The only way I know how to do is this to reset the trigger so all events are gone, but resetting the trigger also means removing every event referenced to a unit that is still alive. I don't think that should be a problem, now that I think about it... Or is it?

Well, you could reset the trigger and use a hashtable to add the alive units back, but i dont see this as an issue, the units will never be referred to as they are dead, they cant take damage.
 
Level 8
Joined
Jul 3, 2011
Messages
251
But the event still exists causing a so called 'Memory Leak' which can cause problems if games last longer and more and more leaks appear.

But how can it cause a memory leak if it is never triggered? With variables a memory leak is caused by setting a variable as something else when its already set as something before nulling it, so i fail to see how the event would cause a leak.
 
Level 2
Joined
Jul 26, 2011
Messages
12
Hello again.
I tried those triggers of yours Zaio.
Unfortunately it made the game crash, it just froze and I couldn't do nothing but end it trough task manager.
 
Level 11
Joined
Sep 30, 2009
Messages
698
But how can it cause a memory leak if it is never triggered? With variables a memory leak is caused by setting a variable as something else when its already set as something before nulling it, so i fail to see how the event would cause a leak.

Well actually you register the event to the trigger. Therefore you have an event leak refering to a null unit. So you still have some data saved by Wc3 even if its useless now.

Hello again.
I tried those triggers of yours Zaio.
Unfortunately it made the game crash, it just froze and I couldn't do nothing but end it trough task manager.

Showing your triggers would help ;) Probably you used a damage function in a damage event, causing an endless loop freezing the game. If so disable the trigger deal your damage and enable the trigger again.
 
Level 8
Joined
Jul 3, 2011
Messages
251
Hello again.
I tried those triggers of yours Zaio.
Unfortunately it made the game crash, it just froze and I couldn't do nothing but end it trough task manager.

You must have done something wrong, i tested it and it worked perfectly fine.

To Axarion: ah i see, that could be fixed by resetting the trigger, using a hashtable and checking if the units in it are alive, if so add them back, right?
 
Last edited:
Level 7
Joined
May 18, 2010
Messages
264
Hello there.
I'm making a spell called "Life Tap" similar to Diablo II's necromancer curse.

For those who isn't familiar with Life Tap; there's two explanations of this:
1. Any monster that is STRUCK by physical damage, while under this curse(buff), adds 50% of the damage RECEIVED to the monster to the attackers life pool.
2. Basically life leech. It's like having a 50% Life Leech.

And now to the point
A unit have Life Tap Buff - i want attacking unit(any attacking unit not only melee) to get life steal based on attacked units Life.

So if attacked unit have 100% life(FULL) then i want the attacking unit to have 100% life steal.
If attacked unit have 34% life left, then i want to give attacking unit 34% life steal.

So a life steal ability based on units % life.
none of replay was good... helpfull...
gime moment il fix you up

This is the Sistem you gona use to DETECT UNIT TAKING DAMAGE
http://www.thehelper.net/forums/showthread.php/137957-GUI-Friendly-Damage-Detection

NOW:
EDIT:problems with the Math!!! (it was so simple when used paper+Dad^^)
  • Untitled Trigger 001
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
      • (GDD_DamagedUnit has buff Acid Bomb) Equal to (==) True
    • Actions
      • Set Hero_Life = ((Integer(GDD_Damage)) x (Integer((Percentage life of GDD_DamageSource))))
      • Above thing cuz numbers cant go 0.1
      • Set Hero_Life_Damage = (Hero_Life / 100)
      • Next part cuz Hero_Life_Damage+His hp = (More then his max hp) = no heal so we do check
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Hero_Life_Damage + (Integer((Life of GDD_DamageSource)))) Greater than (>) (Integer((Max life of GDD_DamageSource)))
          • Then - Actions
            • Unit - Set life of GDD_DamageSource to (Max life of GDD_DamageSource)
          • Else - Actions
            • Unit - Set life of GDD_DamageSource to ((Life of GDD_DamageSource) + (Real(Hero_Life_Damage)))
Hope helps

EDIT: btw i saw u want lifeteap 50% of his hp so just 2/the dmg or hp^^
 
Last edited:
Status
Not open for further replies.
Top