• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Trigger crashing the game

Level 2
Joined
Jan 29, 2021
Messages
5
Hi guys!

I'm currently creating a td, where i added an ability so the builder can use it and all of his towers will focus the selected mob.

  • FocusAttack
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Focus |cffff0000Attack|r
      • Or - Any (Conditions) are true
        • Conditions
          • ((Owner of (Target unit of ability being cast)) controller) Equal to (Player 10 (Light Blue) controller)
          • ((Owner of (Target unit of ability being cast)) controller) Equal to (Player 11 (Dark Green) controller)
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of (Casting unit))) 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 True
            • Then - Actions
              • Unit - Order (Picked unit) to Attack (Target unit of ability being cast)
            • Else - Actions
The issue is that the trigger is working perfectly until minute 8 of the game aprox, where if i use the ability the game crashes for all of the players where before adding this ability it didn't happen.

By crashing I mean that the game completely freezes and you need to go to task administrator to close it, no error message is being displayed.

I also tried doing nothing for 8 minutes, in minute 8/8:20 aprox i cast the ability and the crash is still there.

What can be happening?

EDIT: Another thing to add is that if i change generic unit event to specific unit event crash disappears, but the units are dynamic.

Many thanks in advance!
 
Level 2
Joined
Jan 29, 2021
Messages
5
Yes, i do, actually more than one!

Thing is, shouldn't the conditions set in the trigger prevent it from entering into a loop?

For instance, the usage of Focus |cffff0000Attack|r is just reserved for this case alone.

Many thanks for your prompt response!
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,703
Hi guys!

I'm currently creating a td, where i added an ability so the builder can use it and all of his towers will focus the selected mob.
I would kill two birds with one stone here, first you should be tracking all of your towers at all times:
  • Tower Is Built
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Level of Tower Class (Classification) for (Triggering unit)) Greater than 0
    • Actions
      • Unit Group - Add (Triggering unit) to Player_Towers[(Player number of (Owner of (Triggering unit)))]
      • Game - Display to (All players) for 10.00 seconds the text: (Tower Count: + (String((Number of units in Player_Towers[(Player number of (Owner of (Triggering unit)))]))))
  • Tower Is Destroyed
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Level of Tower Class (Classification) for (Triggering unit)) Greater than 0
    • Actions
      • Unit Group - Remove (Triggering unit) from Player_Towers[(Player number of (Owner of (Triggering unit)))].
      • Game - Display to (All players) for 10.00 seconds the text: (Tower Count: + (String((Number of units in Player_Towers[(Player number of (Owner of (Triggering unit)))]))))
Now you can easily issue an Attack order for all living towers that belong to the Player:
  • Tower Focus Fire
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Focus Fire
    • Actions
      • Game - Display to (All players) for 10.00 seconds the text: (Attacks Issued: + (String((Number of units in Player_Towers[(Player number of (Triggering player))]))))
      • Set VariableSet Focus_Fire_Target = (Target unit of ability being cast)
      • Unit Group - Pick every unit in Player_Towers[(Player number of (Triggering player))] and do (Actions)
        • Loop - Actions
          • Set VariableSet Focus_Fire_Tower = (Picked unit)
          • Unit - Order Focus_Fire_Tower to Attack Focus_Fire_Target
Much more efficient, no memory leaks, no fear of dead towers, etc.

Some important things to note:

1) The Tower Class (Classification) ability is a hidden ability based on Storm Hammers. You would add this to all your Towers in the Object Editor and use it as an identifier in your triggers for what is and isn't considered a Tower.

2) Make sure your Unit Group has it's Size initialized in the Variable Editor:
1715869808755.png


3) If your Towers are removed from the game instead of "killed":
  • Unit - Remove (Triggering unit) from the game
  • Unit - Replace (Triggering unit) with a...
Then they won't run the Tower Is Destroyed trigger and won't be removed from the player's Unit Group. The solution is to manually remove them from the unit group whenever this occurs or use something like GUI Unit Event to gain access to the Event "A unit is removed" so you can account for both situations.


If you still have issues, you may want to add some more Conditions such as this:
  • Loop - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Focus_Fire_Tower is A ranged attacker) Equal to True
      • Then - Actions
        • Unit - Order Focus_Fire_Tower to Attack Focus_Fire_Target
      • Else - Actions
Also, you should look into what other triggers happen around the 8 minute mark. Something must have changed around that time to cause this problem.

Edit: Added a unique variable for the (Picked unit) to avoid the potential issue of it getting changed from other triggers.
 

Attachments

  • Tower Focus Fire 1.w3m
    19.4 KB · Views: 0
Last edited:
Level 17
Joined
Mar 21, 2011
Messages
1,608
Yes, i do, actually more than one!

Thing is, shouldn't the conditions set in the trigger prevent it from entering into a loop?

For instance, the usage of Focus |cffff0000Attack|r is just reserved for this case alone.

Many thanks for your prompt response!
As soon as you use the attack order function, it will jump into every single Order event-based trigger before it continues with the next line in your Focus Attack trigger. "Picked Unit" for example, is a global variable, which means that it can easily be overwritten in other triggers before you jump back. You might even have other lines of code inside of those order event triggers, which will then fire other triggers and so on.. that is why you should use local variables or seperate variables for some triggers.
 
Top