• 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.

[Trigger] Detecting Mana Loss

Status
Not open for further replies.
Level 12
Joined
May 12, 2012
Messages
631
Hello people of Hive!

I have created a spell in which an arrow is fired towards an enemy unit and drains 50/100/150 of their mana, the problem is when the enemy's mana is less than the amount of mana to be drained the caster still gets the amount of mana to be drained.

ex. I used the skill while on level 3 (suppose to drain 150) but the enemy's mana is only 80, the amount of mana I gain is still 150.

how do I gain equal to the amount of mana drained?

Thanks in advance :grin:
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Use a unit indexer or hashtable so that you can store a CurrentMana real variable for each unit in the map (or maybe just each hero) to keep track of their current mana.

Every 0.03 seconds, you compare each of those values to the unit's current mana, the difference is the change.

ACTUALLY:
Now that I read your problem again, why can't you just calculate the target's current mana when the spell is cast?
 
Level 12
Joined
May 12, 2012
Messages
631
ACTUALLY:
Now that I read your problem again, why can't you just calculate the target's current mana when the spell is cast?
will this work for a level 1 skill? (the amount of mana to be gain is 50)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Level of Mana Arrow for MA_Caster) Equal to 1
    • Then - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of MA_Target) Less than or equal to 49.00
        • Then - Actions
          • Unit - Set mana of MA_Caster to ((Mana of MA_Caster) + (Mana of MA_Target))
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of MA_Target) Greater than or equal to 50.00
        • Then - Actions
          • Unit - Set mana of MA_Caster to ((Mana of MA_Caster) + 50.00)
        • Else - Actions
    • Else - Actions
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Since your spell has more than 1 Level, you should turn it to variable, making it easier to calculate instead of mass IF/THEN/ELSE

I would do this;
  • Mana Arrow Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set DrainSetup[1] = 50.00
      • Set DrainSetup[2] = 100.00
      • Set DrainSetup[3] = 150.00
  • Mana Arrow Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Mana Arrow
    • Actions
      • Set TempInt = (Level of Mana Arrow for (Triggering unit))
      • Set Drain = DrainSetup[TempInt]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Mana of (Target unit of ability being cast)) Greater than or equal to Drain
        • Then - Actions
          • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + Drain)
        • Else - Actions
          • Unit - Set mana of (Triggering unit) to ((Mana of (Triggering unit)) + (Mana of (Target unit of ability being cast))
This trigger would work for multiple levels.

And I was wondering, if the word "Drain", why don't you decrease the target's Mana ?
 
Status
Not open for further replies.
Top