One unit only!

excis

Member
Reaction score
1
Hi, I got a spell that heals a target when attacked, but i can cast it on more than one target, Could anyone do a trigger that only allows one unit to have the buff at the time. Example If unit A has buff and Unit A is casting Spell on unit B remove the buff from unit A and vice versa
 

tommerbob

Minecraft. :D
Reaction score
110
Use a Unit variable, and when the spell is casted, set the variable to the target unit. Then if it is cast again, check if it is a different unit, and if it is, then remove the buff from the first unit.
 

tommerbob

Minecraft. :D
Reaction score
110
You need two triggers for this. The first trigger is for the first time the ability is cast so that you can set the unit variable. The second trigger is for every time the ability is cast AFTER that. We will call your ability Heal, and the unit variable HealTarget. The triggers will look something like this:

Trigger:
  • HealCast first time
    • Events
      • Unit - A unit starts the effects of an ability
    • Conditions
      • (ability being cast) equal to Heal
    • Actions
      • Trigger - Turn off (this trigger)
      • Set HealTarget = (target unit of ability being cast)
      • Trigger - Turn on HealCast


Trigger:
  • HealCast
    • Events
      • Unit - A unit starts the effect of an ability
    • Conditions
      • (ability being cast) equal to Heal
    • Actions
      • If/Then/Else Multiple Functions
        • If (conditions)
          • ((taret unit of ability being cast) equal to HealTarget) equal to true, Then Do
        • Then (actions)
        • Else (else actions)
          • Unit - Remove Heal (buff) from HealTarget
          • Set HealTarget = (target unit of ability being cast)


So if your hero casts the ability on a different unit, the buff is removed from the old unit, and the variable is set to the new one. Does that all make sense?
 

Accname

2D-Graphics enthusiast
Reaction score
1,464
you dont need the first trigger, the second one is perfectly fine alone. In GUI it doesnt matter whether the "HealTarget" variable is set, you can still perform actions for units which arent even there, thats the reason for the BJ's they are calling, they are like a fail-save Jass function.
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top