disabling attacking allies.

Status
Not open for further replies.
Level 11
Joined
Jul 17, 2013
Messages
544
Hello i would like to ask you if there is any other way to disable attacking allied units with right click and attack, currently i am using triggers that check if units who are going to fight eachother are allied, if yes it stops them.

is there any other way than trigger to disable attacking allies? i still want units to be able to attack allies for some reasons so i am bit tired alrdy of adding new conditions to my trigger.
 

Uncle

Warcraft Moderator
Level 69
Joined
Aug 10, 2018
Messages
7,189
You can prevent attacking allies using orders:

When a player orders a unit to do something targeting another object -> unit, destructable, item, it triggers this Event:
  • Events:
  • Unit - A unit Is issued an order targeting an object

You can then check to see which order it was. In your case you're looking for the attack order:
  • Conditions:
  • (Issued order) Equal to "attack"

Simply add a condition to check if the (Target of issued order) belongs to an ally of the (Ordered unit) if you want this to only work when attacking allies:
  • ((Target unit of Issued order) belongs to an ally of (Owner of (Ordered unit)) Equal to True

Now it gets a little weird here. In order to interrupt an order you often have to use some strange workarounds:
  • Actions:
  • Set Variable TempPoint1 = Position of (Triggering unit)
  • Set Variable TempPoint2 = TempPoint1 offset by 0.0, 0.0
  • Unit - Order (Triggering unit) to Move to TempPoint2
  • Custom script: call RemoveLocation (udg_TempPoint1)
  • Custom script: call RemoveLocation (udg_TempPoint2)

The above trigger SHOULD interrupt the unit's order by telling it to move to it's own position. If that doesn't work then try adding a very slight offset like 0.01 to either the X/Y coordinates. I found that you can't just issue a "stop" order here for some reason. I don't think Pause/Stop/Unpause works either.

If you're ever confused about the names of these orders you can always Display a text message of the (Issued order). I recommend doing this in order to get a better understanding of how orders in Warcraft 3 work.
 
Last edited:
Level 12
Joined
May 16, 2020
Messages
660
Wouldn't that just disable all attacks?

For disabling attacking allies, this works, but not sure how efficient this is:

  • Prevent Friendly Fire
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacking unit) belongs to an ally of (Owner of (Attacked unit)).) Equal to True
    • Actions
      • Unit - Order (Attacking unit) to Stop.
      • Game - Display to (All players) the text: Friendly Fire is no...
 

Uncle

Warcraft Moderator
Level 69
Joined
Aug 10, 2018
Messages
7,189
I wasn't exactly sure what he wanted but I assume he's using that same trigger that you posted already as that's the one everyone uses.

So I was showing him how one can use Orders to prevent a unit from ever even attempting to attack an ally. I left out the Ally-checking Conditions but I figured it was obvious.

I'll add this to the original post:
  • ((Target unit of Issued order) belongs to an ally of (Owner of (Ordered unit)) Equal to True
 
Last edited:
Level 33
Joined
Mar 27, 2008
Messages
8,035
i still want units to be able to attack allies for some reasons
Please let us know what's the "reasons" so we can modify the triggers to accept this condition while creating this specific trigger for you ?
Also, it'd be more efficient (faster execution code) to use (Triggering unit) instead of (Attacked unit)

  • No Friendly Fire
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Triggering unit) belongs to an ally of (Owner of (Attacking unit)).) Equal to True
    • Actions
      • Unit - Order (Attacking unit) to Stop.
 
Status
Not open for further replies.
Top