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

Help fixing my anti team kill trigger

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
  • AntiTeamKill
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (BaseRegionsForTeamKill[(Integer A)] contains (Targeted unit)) Equal to True
              • (Issued order) Equal to (Order(attack))
              • BasesInUse[(Integer A)] Equal to True
              • Bases[(Integer A)] Not equal to (Owner of (Triggering unit))
            • Then - Actions
              • Unit - Order (Triggering unit) to Stop
            • Else - Actions

  • Starting Events
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set BaseRegionsForTeamKill[1] = Base1 <gen>
      • Set BaseRegionsForTeamKill[2] = Base2 <gen>
      • Set BaseRegionsForTeamKill[3] = Base3 <gen>
      • Visibility - Disable black mask

So on game start, I set BaseRegionsForTeamKill index to each base region. Base 1 = a region, 2 3 etc

But I just tested with some friends, and the building gets destroyed even though it's claimed. Any idea what the issue could be? Is the building being destroyed before the trigger can fire?

And regarding all the variables in the first trigger, they are all correct and have the player stored. I know because my claim base trigger works, and I have another bit of code that cancels construction if the base is claimed and someone not the owner builds. That works good. Just the team kill doesn't.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
You are ordering the unit to stop before it is ordered to attack. The event fires before the order is queued to the unit command queue, hence stop gets ordered before the unit is ordered to attack and so the unit keeps attacking.

I recall the solution being to pause the unit, order it to stop and then unpause the unit or something like that.
 
Level 12
Joined
Dec 2, 2016
Messages
733
You are ordering the unit to stop before it is ordered to attack. The event fires before the order is queued to the unit command queue, hence stop gets ordered before the unit is ordered to attack and so the unit keeps attacking.

I recall the solution being to pause the unit, order it to stop and then unpause the unit or something like that.
How do you pause a unit?
 
Level 12
Joined
Dec 2, 2016
Messages
733
So I added a message to test if the trigger was firing, and it isn't. So that means the event doesn't fire. I'm using the milita human model, and attacking a building via pressing the A hotkey. Any idea which event I should use?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,201
So that means the event doesn't fire.
The event works perfectly. Maybe the conditions are wrong? There is no Targeted unit in that context, that is for a different event. Use Target unit of issued order instead. These are unit argument functions.

If the trigger truly is not firing, proved by printing a message before any conditions, that means that something is crashing the event initialization thread during map initialization. A common cause for this is hitting the thread operation limit due to excessive initialisation of GUI arrays, eg initialization multiple 8,000 index arrays. It is also possible the trigger is turned off/disabled in the editor, or turned off accidently by another trigger during game play. In worst case you may have to provide the map so the cause can be debugged.
How do you pause a unit?
With the Unit - Pause/Unpause action.
 
Level 14
Joined
Aug 31, 2009
Messages
775
I find it a lot easier to fix this issue by writing it like this:

  • Events
    • Unit - A unit is attacked
  • Conditions
    • (Owner of (Attacking unit)) belongs to ally of (Owner of (attacked unit)) equal to true
  • Actions
    • Unit - Order (attacking unit) to Stop
The only downside to this is that "Event - a unit is attacked" can be a resource hog if there's a lot of them in your map. Also, it will only tell the unit to stop once it actually attempts to attack, so the unit will walk to within range of its target before stopping.
 
Status
Not open for further replies.
Top