• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Having a severe problem with this. *Solved*

Status
Not open for further replies.
Level 4
Joined
May 20, 2011
Messages
59
Hey Guys,
I'm developing a Trigger for my map to work alongside a spell that enslaves an enemy unit to make them into a worker. The spell is solely for animation and the Trigger is doing all of the work, but the problem is that it seems the Trigger isn't working properly and is jumping over the conditions and doing the action anyway. I've provided an image of the trigger to better explain.
HiveError.PNG

As you can see, I have an "If (All Conditions are True) then do...." Function at the beginning of my Actions section. I've confirmed that the Unit titled 15Percent indeed has only 15 Percent Health, but for some reason it just won't catch and I'm able to use the spell on and kill Units with 100% HP. What could be the problem here?
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
You should use this, to get the unit that is the target of an ability:
  • (Target unit of ability being cast) Equal to No unit
 
Level 13
Joined
May 10, 2009
Messages
868
Your second condition is using the wrong function to get the target unit. So, it always returns 0 and tries to compare with the other value (15%), which is always true.

->
  • (Life of (Target unit of ability being cast)) Less than or equal to yourValue
 
Level 4
Joined
May 20, 2011
Messages
59
Thank you all so much for your help, can't believe I didn't see this initially!

*Still having trouble with this, not understanding why the logic isn't working here. I've included the edited Trigger, right now whats happening is it is displaying the test message whenever I cast ANY spell, not the Enslave Enemy one that it should only be displaying for, an on top of this, now the Spell won't work at all. 15Percent is still at 15 Percent HP. Isn't there a simpler way to reference 15% health instead of working through a unit?* Any further help would be beyond appreciated.
*Code included below*
  • Enslave
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Enslave
          • (Life of (Target unit of ability being cast)) Less than or equal to (Percentage life of 15Percent 0315 <gen>)
        • Then - Actions
          • Unit - Create 1 Peon for (Triggering player) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
          • Unit - Kill (Target unit of ability being cast)
        • Else - Actions
          • Game - Display to (Player group((Triggering player))) the text: Enemy has more than...
 
Last edited:

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
You are comparing absolute life with percentage life. Percentage life ranges from 0 to 100. Your message is in the else block, so it will always trigger, if the spell is not enslave.
Just compare the percentage from the targeted unit with 15.
If you want your trigger to only work when the target has 15% hp or less you could use:
  • Enslave
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Enslave
      • (Percentage life of (Target unit of ability being cast)) Less than or equal to 15.00
    • Actions
      • Do your actions
 
Level 13
Joined
May 10, 2009
Messages
868
That's happening because when any unit begins casting a spell, the actions run directly. It checks if the spell is Enslave. If not, the else actions do run instead. Move your first condition to the trigger conditions block.
 
Level 11
Joined
Nov 15, 2007
Messages
781
Thank you all so much for your help, can't believe I didn't see this initially!

*Still having trouble with this, not understanding why the logic isn't working here. I've included the edited Trigger, right now whats happening is it is displaying the test message whenever I cast ANY spell, not the Enslave Enemy one that it should only be displaying for, an on top of this, now the Spell won't work at all. 15Percent is still at 15 Percent HP. Isn't there a simpler way to reference 15% health instead of working through a unit?* Any further help would be beyond appreciated.
*Code included below*
  • Enslave
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Enslave
          • (Life of (Target unit of ability being cast)) Less than or equal to (Percentage life of 15Percent 0315 <gen>)
        • Then - Actions
          • Unit - Create 1 Peon for (Triggering player) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
          • Unit - Kill (Target unit of ability being cast)
        • Else - Actions
          • Game - Display to (Player group((Triggering player))) the text: Enemy has more than...

Let's break everything wrong with this down point by point:


  • Enslave
    • Events
      • Unit - A unit Begins casting an ability
First of all, use

  • Unit - A unit Starts the effect of an ability
"Begins casting" will fire off the second the cast starts, even if it's canceled before completing. "Starts effect" will only fire when the spell has actually been cast, including having its mana cost reduced and going on cooldown (if applicable).

  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Ability being cast) Equal to Enslave
This condition should be in the conditions block, not an if/then/else - otherwise it will run this trigger whenever you cast any spell, which is what you're experiencing.

  • If - Conditions
    • (Life of (Target unit of ability being cast)) Less than or equal to (Percentage life of 15Percent 0315 <gen>)
You're comparing the numerical life of the target with a percentage. This conditioned will only be fulfilled if the target has 15 hitpoints or fewer. You want

  • (Percentage life of (Target unit of ability being cast)) Less than or equal to 15.00
I'm not sure why you're comparing it to another unit, that's wholly unnecessary.

  • Unit - Create 1 Peon for (Triggering player) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
Finally, this is a location leak. Read Things That Leak to learn how to avoid memory leaks and save yourself a headache in the long run.
 
Level 4
Joined
May 20, 2011
Messages
59
Let's break everything wrong with this down point by point:


  • Enslave
    • Events
      • Unit - A unit Begins casting an ability
First of all, use

  • Unit - A unit Starts the effect of an ability
"Begins casting" will fire off the second the cast starts, even if it's canceled before completing. "Starts effect" will only fire when the spell has actually been cast, including having its mana cost reduced and going on cooldown (if applicable).

  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Ability being cast) Equal to Enslave
This condition should be in the conditions block, not an if/then/else - otherwise it will run this trigger whenever you cast any spell, which is what you're experiencing.

  • If - Conditions
    • (Life of (Target unit of ability being cast)) Less than or equal to (Percentage life of 15Percent 0315 <gen>)
You're comparing the numerical life of the target with a percentage. This conditioned will only be fulfilled if the target has 15 hitpoints or fewer. You want

  • (Percentage life of (Target unit of ability being cast)) Less than or equal to 15.00
I'm not sure why you're comparing it to another unit, that's wholly unnecessary.

  • Unit - Create 1 Peon for (Triggering player) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
Finally, this is a location leak. Read Things That Leak to learn how to avoid memory leaks and save yourself a headache in the long run.
Thank you very, very much for breaking this down as well as providing the Leaks link, as all this information will serve me quite well not only now but in all my triggers and projects to come, and thanks to everyone else for the other responses; this has all been greatly appreciated! My only question that remains however is why wouldn't the if/then/else work? In my mind it would hit the condition and be inhibited as if this was a traditional program in say Java or such; But seeing as how it would not work in this situation, what kind of situations in the editor would you use a If/Then/Else function?
 
Level 13
Joined
May 10, 2009
Messages
868
My only question that remains however is why wouldn't the if/then/else work? In my mind it would hit the condition and be inhibited as if this was a traditional program in say Java or such; But seeing as how it would not work in this situation, what kind of situations in the editor would you use a If/Then/Else function?

We said to take those conditions back to the trigger conditions, because you may want those actions to run for a single spell, and you also have all the information needed there (life percentage and target). You could still use the if/then/else, but there's no need for that.

Now, there are cases where you may want to apply effects to some objects in your map, and those objects might be sharing the same event. For example: I want to display different special effects at a triggering unit's position as soon as such unit picks up some items.

  • PickupItems
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Claws of Attack +15
        • Then - Actions
          • Special Effect - Create a special effect attached to the origin of (Triggering unit) using Abilities\Spells\Human\HolyBolt\HolyBoltSpecialArt.mdl
          • Special Effect - Destroy (Last created special effect)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
            • Then - Actions
              • Special Effect - Create a special effect attached to the origin of (Triggering unit) using Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
I can even move both conditions to the trigger conditions block by positioning them within an "Or". However, I would still need to distinguish which item is which in order to apply different effects later.

  • Ugh
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to Claws of Attack +15
          • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Claws of Attack +15
        • Then - Actions
          • Special Effect - Create a special effect attached to the origin of (Triggering unit) using Abilities\Spells\Human\HolyBolt\HolyBoltSpecialArt.mdl
          • Special Effect - Destroy (Last created special effect)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
            • Then - Actions
              • Special Effect - Create a special effect attached to the origin of (Triggering unit) using Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
That is redundant. Then, just leave it as the first example above.

Another case would be: Whenever you use an event where you don't have all information needed in the trigger conditions block. For example: I have a trigger with a periodic event, and I want to damage some units in a specific area every X seconds.

  • IT IS A TRAP
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Set point = (Center of Rect 0000 <gen>)
      • Special Effect - Create a special effect at point using Abilities\Spells\Other\Incinerate\FireLordDeathExplode.mdl
      • Special Effect - Destroy (Last created special effect)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within 100.00 of point) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is A structure) Equal to False
              • ((Picked unit) is dead) Equal to False
            • Then - Actions
              • Unit - Cause (Picked unit) to damage (Picked unit), dealing 50.00 damage of attack type Spells and damage type Normal
            • Else - Actions
      • Custom script: call RemoveLocation(udg_point)
As you can see, I can't filter units in the conditions block yet. Even if I could, I'd still want to display that special effect at a certain position, whether there's a unit there or not.

I hope I cleared things up for you.
 
Last edited:
Level 4
Joined
May 20, 2011
Messages
59
Yes th
We said to take those conditions back to the trigger conditions, because you may want those actions to run for a single spell, and you also have all the information needed there (life percentage and target). You could still use the if/then/else, but there's no need for that.

Now, there are cases where you may want to apply effects to some objects in your map, and those objects might be sharing the same event. For example: I want to display different special effects at a triggering unit's position as soon as such unit picks up some items.

  • PickupItems
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Claws of Attack +15
        • Then - Actions
          • Special Effect - Create a special effect attached to the origin of (Triggering unit) using Abilities\Spells\Human\HolyBolt\HolyBoltSpecialArt.mdl
          • Special Effect - Destroy (Last created special effect)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
            • Then - Actions
              • Special Effect - Create a special effect attached to the origin of (Triggering unit) using Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
I can even move both conditions to the trigger conditions block by positioning them within an "Or". However, I would still need to distinguish which item is which in order to apply different effects later.

  • Ugh
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to Claws of Attack +15
          • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Claws of Attack +15
        • Then - Actions
          • Special Effect - Create a special effect attached to the origin of (Triggering unit) using Abilities\Spells\Human\HolyBolt\HolyBoltSpecialArt.mdl
          • Special Effect - Destroy (Last created special effect)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
            • Then - Actions
              • Special Effect - Create a special effect attached to the origin of (Triggering unit) using Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
That is redundant. Then, just leave it as the first example above.

Another case would be: Whenever you use an event where you don't have all information needed in the trigger condition block. For example: I have a trigger with an Periodic Event, and I want to damage some units in a area every X seconds.

  • IT IS A TRAP
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Set point = (Center of Rect 0000 <gen>)
      • Special Effect - Create a special effect at point using Abilities\Spells\Other\Incinerate\FireLordDeathExplode.mdl
      • Special Effect - Destroy (Last created special effect)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within 100.00 of point) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is A structure) Equal to False
              • ((Picked unit) is dead) Equal to False
            • Then - Actions
              • Unit - Cause (Picked unit) to damage (Picked unit), dealing 50.00 damage of attack type Spells and damage type Normal
            • Else - Actions
      • Custom script: call RemoveLocation(udg_point)
As you can see, I can't filter units in the conditions block yet. Even if I could, I'd still want to display that special effect at a certain position, whether there's a unit there or not.

I hope could clear things up for you.
Yes, this was great! Thank you so much! If you have a spare moment and wouldn't mind taking a look at this: Complicated Trigger Question *Still Need Help*, it would be greatly appreciated as this one problem might be the greatest inhibition I've experienced so far with my map; and it directly relates to this trigger as the Units being produced by Enslave are meant to be placed in Burrows.
 
Status
Not open for further replies.
Top