• 🏆 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!

[Trigger] Spell Issue [SOLVED]

Level 11
Joined
Aug 11, 2009
Messages
594
Hi!
I am making a spell for a boss fight where a missile spawns at the outer edges of the battle area and moves in a circular motion around the center, slowly moving closer and closer to the center at which point it is destroyed.

The problem is when a second missile spawn before the first missile has been destroyed, the first missile stops moving in a circular motion around the center and is only moved slowly towards the boss at the same angle.

EDIT: I found that in Trigger 2 i had the wrong array, it was "Spell2Instances" instead of "Spell2Loop", this change fixed the first issue but created another. Now all missiles from the start just randomly jumps around between angles instead of following a circular motion... :(

Anyone can figure out what is wrong?

  • Camp53 Spell 2
    • Events
      • Time - Every (Random real number between 10.00 and 25.00) seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Camp53_Spell2Instances = (Camp53_Spell2Instances + 1)
      • Set VariableSet Camp53_Spell2Angle[Camp53_Spell2Instances] = (Random real number between 0.00 and 360.00)
      • Set VariableSet Camp53_Spell2Point[Camp53_Spell2Instances] = (Camp53_BossPoint offset by 1800.00 towards Camp53_Spell2Angle[Camp53_Spell2Instances] degrees.)
      • Unit - Create 1 Death Coil (5-3) for Neutral Hostile at Camp53_Spell2Point[Camp53_Spell2Instances] facing Default building facing degrees
      • Set VariableSet Camp53_Spell2Unit[Camp53_Spell2Instances] = (Last created unit)
      • Custom script: call RemoveLocation(udg_Camp53_Spell2Point[udg_Camp53_Spell2Instances])
      • Trigger - Turn on Camp53 Spell 2 Loop <gen>

  • Camp53 Spell 2 Loop
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Camp53_Spell2Loop) from 0 to Camp53_Spell2Instances, do (Actions)
        • Loop - Actions
          • Set VariableSet Camp53_Spell2Count[Camp53_Spell2Loop] = (Camp53_Spell2Count[Camp53_Spell2Loop] + 1.00)
          • Set VariableSet Camp53_Spell2Angle[Camp53_Spell2Instances] = (Camp53_Spell2Angle[Camp53_Spell2Loop] + (Camp53_Spell2Count[Camp53_Spell2Loop] x 6.00))
          • Set VariableSet Camp53_Spell2Point[Camp53_Spell2Loop] = (Camp53_BossPoint offset by (1800.00 - (Camp53_Spell2Count[Camp53_Spell2Loop] x 5.00)) towards Camp53_Spell2Angle[Camp53_Spell2Loop] degrees.)
          • Unit - Move Camp53_Spell2Unit[Camp53_Spell2Loop] instantly to Camp53_Spell2Point[Camp53_Spell2Loop]
          • Custom script: call RemoveLocation(udg_Camp53_Spell2Point[udg_Camp53_Spell2Loop])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Camp53_Spell2Count[Camp53_Spell2Loop] Equal to 360.00
            • Then - Actions
              • Unit - Kill Camp53_Spell2Unit[Camp53_Spell2Loop]
              • Unit - Remove Camp53_Spell2Unit[Camp53_Spell2Loop] from the game
              • Set VariableSet Camp53_Spell2Unit[Camp53_Spell2Loop] = No unit
              • Set VariableSet Camp53_Spell2UG = (Units owned by Neutral Hostile of type Death Coil (5-3))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in Camp53_Spell2UG) Equal to 0
                • Then - Actions
                  • Set VariableSet Camp53_Spell2Instances = 0
                  • Set VariableSet Camp53_Spell2Count[Camp53_Spell2Loop] = 0.00
                  • Trigger - Turn off (This trigger)
                • Else - Actions
              • Custom script: call DestroyGroup(udg_Camp53_Spell2UG)
            • Else - Actions

Thanks in advance!
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
Your Loop goes from 0 to Instance count, which doesn't make sense since your Array is indexed starting at 1.

Unless you set it's default value to -1 but I doubt that. The default value is 0 so it's going to be set to 1 for the first instance:
  • Set VariableSet Camp53_Spell2Instances = (Camp53_Spell2Instances + 1)
You never want to check if a Real is equal to an exact value:
  • Camp53_Spell2Count[Camp53_Spell2Loop] Equal to 360.00
Reals can lose precision and you can end up with a value like 359.9999 instead of 360.0.

Check if it's Greater than or equal to that value or rely on Integers which are always precise.

You're using a Dynamic Indexing approach but failing to "de-index" it at the end. You don't need any of this:
  • Set VariableSet Camp53_Spell2Unit[Camp53_Spell2Loop] = No unit
  • Set VariableSet Camp53_Spell2UG = (Units owned by Neutral Hostile of type Death Coil (5-3))
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Number of units in Camp53_Spell2UG) Equal to 0
    • Then - Actions
      • Set VariableSet Camp53_Spell2Instances = 0
      • Set VariableSet Camp53_Spell2Count[Camp53_Spell2Loop] = 0.00
      • Trigger - Turn off (This trigger)
    • Else - Actions
  • Custom script: call DestroyGroup(udg_Camp53_Spell2UG)
Instead, you want to follow the instructions you can find here:

You swap the Arrays associated with Camp53_Spell2Loop with the Arrays associated with the last instance. For example:
  • Set VariableSet Camp53_Spell2Unit[Camp53_Spell2Loop] = Camp53_Spell2Unit[Camp53_Spell2Instances]
Then you reduce both Camp53_Spell2Instances and Camp53_Spell2Loop by 1. Then you check if Camp53_Spell2Instances is equal to 0, if it is, you know that ALL instances have finished and you can turn off the trigger.

Also, Special Effects have become generally more favorable than relying on Dummy units for these types of Missile effects. You have all sorts of extra customization options and less overhead, but I suppose it all depends on what you want to achieve.
 
Last edited:
Level 11
Joined
Aug 11, 2009
Messages
594
Thanks!

I had to think a bit to understand but it was a very good visual guide to the indexing :D however, the second issue that happened still remain.

But here are the triggers, I think I got it right with the indexing atleast:
  • Camp53 Spell 2
    • Events
      • Time - Every (Random real number between 10.00 and 25.00) seconds of game time
    • Conditions
    • Actions
      • Set VariableSet Camp53_Spell2Index = (Camp53_Spell2Index + 1)
      • Set VariableSet Camp53_Spell2Angle[Camp53_Spell2Index] = (Random real number between 0.00 and 360.00)
      • Set VariableSet Camp53_Spell2Point[Camp53_Spell2Index] = (Camp53_BossPoint offset by 1800.00 towards Camp53_Spell2Angle[Camp53_Spell2Index] degrees.)
      • Unit - Create 1 Death Coil (5-3) for Neutral Hostile at Camp53_Spell2Point[Camp53_Spell2Index] facing Default building facing degrees
      • Set VariableSet Camp53_Spell2Unit[Camp53_Spell2Index] = (Last created unit)
      • Custom script: call RemoveLocation(udg_Camp53_Spell2Point[udg_Camp53_Spell2Index])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Camp53_Spell2Index Equal to 1
        • Then - Actions
          • Trigger - Turn on Camp53 Spell 2 Loop <gen>
        • Else - Actions

  • Camp53 Spell 2 Loop
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Camp53_Spell2Loop) from 1 to Camp53_Spell2Index, do (Actions)
        • Loop - Actions
          • Set VariableSet Camp53_Spell2Count[Camp53_Spell2Loop] = (Camp53_Spell2Count[Camp53_Spell2Loop] + 1)
          • Set VariableSet Camp53_Spell2Angle[Camp53_Spell2Loop] = (Camp53_Spell2Angle[Camp53_Spell2Loop] + (Real((Camp53_Spell2Count[Camp53_Spell2Loop] x 4))))
          • Set VariableSet Camp53_Spell2Point[Camp53_Spell2Loop] = (Camp53_BossPoint offset by (1800.00 - (Real((Camp53_Spell2Count[Camp53_Spell2Loop] x 5)))) towards Camp53_Spell2Angle[Camp53_Spell2Loop] degrees.)
          • Unit - Move Camp53_Spell2Unit[Camp53_Spell2Loop] instantly to Camp53_Spell2Point[Camp53_Spell2Loop]
          • Custom script: call RemoveLocation(udg_Camp53_Spell2Point[udg_Camp53_Spell2Loop])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Camp53_Spell2Count[Camp53_Spell2Loop] Greater than or equal to 360
            • Then - Actions
              • Unit - Remove Camp53_Spell2Unit[Camp53_Spell2Loop] from the game
              • Set VariableSet Camp53_Spell2Unit[Camp53_Spell2Loop] = Camp53_Spell2Unit[Camp53_Spell2Index]
              • Set VariableSet Camp53_Spell2Point[Camp53_Spell2Loop] = Camp53_Spell2Point[Camp53_Spell2Index]
              • Set VariableSet Camp53_Spell2Angle[Camp53_Spell2Loop] = Camp53_Spell2Angle[Camp53_Spell2Index]
              • Set VariableSet Camp53_Spell2Count[Camp53_Spell2Loop] = Camp53_Spell2Count[Camp53_Spell2Index]
              • Set VariableSet Camp53_Spell2Index = (Camp53_Spell2Index - 1)
              • Set VariableSet Camp53_Spell2Loop = (Camp53_Spell2Loop - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Camp53_Spell2Index Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions

I dont understand what is happening with the angles. The missile just keeps jumping between random angles until it reaches the center. Do you have any idea why that happens?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
You don't need this line since the Point is being created/removed within the same frame:
  • Set VariableSet Camp53_Spell2Point[Camp53_Spell2Loop] = Camp53_Spell2Point[Camp53_Spell2Index]
In fact you should make Camp53_Spell2Point a non-Array variable since there's no reason to track it over time.

This line looks a bit strange to me:
  • Set VariableSet Camp53_Spell2Angle[Camp53_Spell2Loop] = (Camp53_Spell2Angle[Camp53_Spell2Loop] + (Real((Camp53_Spell2Count[Camp53_Spell2Loop] x 4))))
You're increasing the angle by 4, then by 8, then by 12.

I think you want to simply increase it by 4 each interval:
  • Set VariableSet Camp53_Spell2Angle[Camp53_Spell2Loop] = (Camp53_Spell2Angle[Camp53_Spell2Loop] + 4)
 
Level 11
Joined
Aug 11, 2009
Messages
594
You are absolutely correct about everything, sometimes I am ashamed of my math lol. I also forgot to reset the count variable so i added that whenever a new missile is created. Now it works flawlessly, thanks alot for your help! :D
 
Top