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

How to prevent a player from attacking his allies

Status
Not open for further replies.
Level 4
Joined
Aug 24, 2005
Messages
50
hi,
the title is the question already.

how can i make a unit ordered to attack an allied unit to stop without defining it again and again for each player/playergroup, just by checking if the 2 units are allied?
(in other words, how can i script such an ally-check system?)
 
Level 4
Joined
Aug 24, 2005
Messages
50
event
unit is attacked

condition
attacking unit belongs to an ally of owner of attacked unit equal to true

action
order attacking unit to stop

this doesnt seem to work.
i tried to use conditions this way:
a unit is attacked
-attacking unit is p1
-attacked unit is p2 (p1+p2 are allied)
->order attacking unit to "stop"

this had absolutely no effect :/

and the way with the variable for the attacking unit .. this should work for sure but using it on a map with lots of units might cause problems i think - besides, i always prefer to use a short way to keep the map as small as possible :)
 
Level 8
Joined
Mar 12, 2008
Messages
437
this doesnt seem to work.
i tried to use conditions this way:
a unit is attacked
-attacking unit is p1
-attacked unit is p2 (p1+p2 are allied)
->order attacking unit to "stop"

this had absolutely no effect :/

and the way with the variable for the attacking unit .. this should work for sure but using it on a map with lots of units might cause problems i think - besides, i always prefer to use a short way to keep the map as small as possible :)

Try doing what darkrider said instead.
(Owner of (Attacked unit)) is an ally of (Owner of (Attacking unit))
 
Level 14
Joined
Nov 23, 2008
Messages
187
  • AntiAllyAttack
    • 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
Strange, trigger listed above works fine for me...

...Well, the only solution I see is to pause unit before giving order and unpause after that:

  • AntiAllyAttack
    • Events
      • Unit - A unit is attacked
    • Conditions
      • ((Triggering unit) belongs to an ally of (Owner of (Attacking unit))) equal to True
    • Actions
      • Unit - Pause (Attacking unit)
      • Unit - Order (Attacking unit) to stop
      • Unit - Unpause (Attacking unit)
Pausing unit should break his current order (attack).
 
Level 11
Joined
May 31, 2008
Messages
698
Maybe this will work

  • Attack
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Issued order) Equal to (Order(attack))
      • ((Target unit of issued order) belongs to an ally of (Owner of (Triggering unit))) Equal to True
    • Actions
      • Unit - Order (Triggering unit) to Stop
 
Level 12
Joined
Mar 16, 2006
Messages
992
Copied straight from my map for you, so I know it works.

Events
Unit - A unit Is attacked
Conditions
((Attacked unit) belongs to an ally of (Owner of (Attacking unit))) Equal to True
(Unit-type of (Attacking unit)) Not equal to Dummy Unit
Actions
Unit - Order (Attacking unit) to Stop
 
Level 2
Joined
Dec 11, 2008
Messages
12
Newbie

Can't you just change the 'targets allowed' in the object editor. Just check the box that says 'Enemy' and uncheck the box that says 'Friend'
That should stop units from attacking other allied unit
:spell_breaker:
 
Status
Not open for further replies.
Top