• 🏆 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] Why it is not working?

Status
Not open for further replies.
Level 5
Joined
Feb 18, 2016
Messages
96
I made a spell that every time casted spawns a unit and its limited to 3 units
Every time it is used when number of units equal to 3 the first dies, the second becomes the first, the third the second and the new spawned unit the third
The main issue is that some times works perfectly but sometimes, with no apparent reason, it does not despawn the first unit and the trigger stop working correctly (or completely)

  • Orbes
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to CustomAbility
    • Actions
      • Set P = (Casting unit)
      • Unit - Create 1 CustomUnit for (Owner of P) at (Target point of ability being cast) facing (Position of P)
      • Set PUnit[(Number of units in (Units of type CustomUnit))] = (Last created unit)
      • Unit - Change color of PUnit[(Number of units in (Units of type CustomUnit))] to Light Blue


  • Orbes 3
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • (Ability being cast) Equal to CustomAbility
          • (Number of living CustomUnit units owned by (Owner of P)) Greater than 3
    • Actions
      • Unit - Kill PUnit[1]
      • Set PUnit[1] = PUnit[2]
      • Set PUnit[2] = PUnit[3]
      • Set PUnit[3] = PUnit[4]
 
Level 39
Joined
Feb 27, 2007
Messages
5,012
One of the units is dying and you're not catching it. Then when you go to kill PUnit[1] there's nothing to kill or when you assign PUnit[1-3] it's assigned to a dead unit. You should also combine this into one trigger:
  • Orbes
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to CustomAbility
    • Actions
      • Set P = (Casting unit)
      • Unit - Create 1 CustomUnit for (Owner of P) at (Target point of ability being cast) facing (Position of P)
      • Set PUnit[(Number of units in (Units of type CustomUnit))] = (Last created unit)
      • Unit - Change color of PUnit[(Number of units in (Units of type CustomUnit))] to Light Blue
      • If (all conditions are true) then do (then actions) else do (else actions)
        • If - Conditions
          • (Number of living CustomUnit units owned by (Owner of P)) Greater than 3
        • Then - Actions
          • Unit - Kill PUnit[1]
          • Set PUnit[1] = PUnit[2]
          • Set PUnit[2] = PUnit[3]
          • Set PUnit[3] = PUnit[4]
To detect death and fix this problem do:
  • Orbes Death
    • Events
      • Unit - A unit dies
    • Conditions
    • Actions
      • If (all conditions are true) then do (then actions) else do (else actions)
        • If - Conditions
          • (Dying unit) equal to PUnit[1]
        • Then - Actions
          • Set PUnit[1] = PUnit[2]
          • Set PUnit[2] = PUnit[3]
      • If (all conditions are true) then do (then actions) else do (else actions)
        • If - Conditions
          • (Dying unit) equal to PUnit[2]
        • Then - Actions
          • Set PUnit[2] = PUnit[3]
      • -------- Note you don't have to do anything if PUnit[3] dies --------
 
Status
Not open for further replies.
Top