• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

make an unit unable to attack allies?

Status
Not open for further replies.
Level 5
Joined
Dec 8, 2012
Messages
149
  • Dont Attack Allies
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Owner of (Target unit of issued order)) Equal to (Random player from (All allies of (Owner of (Ordered unit))))
    • Actions
      • Unit - Order (Ordered unit) to Stop
This?

Updated
  • Dont Attack Allies
    • 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 (Ordered unit))) Equal to True
    • Actions
      • Unit - Order (Ordered unit) to Stop
Hope that helps...
 
Last edited:
Level 6
Joined
Jul 26, 2010
Messages
167
Change attack targets Combat - Attack 1 - Targets Allowed: Enemy, Derbs, Items, Wards

That allows the unit to attack only enemies. May be missing a filter

the unit doesnt attack anything like that and if I add other targets I remaings the same

ill see what I can do maybe the stop order doest work cuz my wc3 is in spanish or something
 
Last edited by a moderator:
Level 33
Joined
Mar 27, 2008
Messages
8,035
That is because the function works too fast, you're gonna need a 0s Wait to deal with this situation.

Try this;
  • Stop
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • ((Target unit of issued order) belongs to an ally of (Triggering player)) Equal to True
      • (Issued order) Equal to (Order(attack))
    • Actions
      • Wait 0.00 seconds
      • Unit - Order (Triggering unit) to Stop
Don't worry, it's MUI, I've tested it.
The funny thing is, someone said to use 0s Timer for this, it is the "0s Timer" approach that is not MUI compared to 0s Wait.

@alexmantor
DotA has this small system implemented too.
Well, you can't attack your own units as well - but there is an exception, but that's a different story.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Why not use this system. Saves you having to wait. This also allows you to attack your own units. Just remove the second condition if thats not what you want.

  • Friendly Fire
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacked unit) belongs to an ally of (Owner of (Attacking unit))) Equal to True
      • (Owner of (Attacking unit)) Not equal to (Owner of (Attacked unit))
    • Actions
      • Unit - Order (Attacking unit) to Stop
 
Level 5
Joined
Dec 8, 2012
Messages
149
Ok, i found this sometime in Wc3c.net(i forgot the link) but it's trully working to me...
JASS:
function AntiAttack takes nothing returns nothing
    if IsUnitAlly(GetTriggerUnit(),GetOwningPlayer(GetAttacker())) == true then
        if GetUnitState(GetTriggerUnit(),UNIT_STATE_LIFE) > (GetUnitState(GetTriggerUnit(),UNIT_STATE_MAX_LIFE) * 0.05) then
            call IssueImmediateOrder(GetAttacker(),"stop")
        endif
    endif
endfunction

function InitTrig_AntiAttack takes nothing returns nothing
    local integer i = 0
    set gg_trg_AntiAttack = CreateTrigger(  )
    loop
        exitwhen i == bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerUnitEvent(gg_trg_AntiAttack,Player(i),EVENT_PLAYER_UNIT_ATTACKED,null)
        set i = i + 1
    endloop
    call TriggerAddAction(gg_trg_AntiAttack,function AntiAttack)
endfunction
Credits to whoever create that... :ogre_hurrhurr:
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Do you even know the meaning of "leak" in computer programming ?
If you don't know, don't use it @@"

Are you 100% sure that the unit will still be able to attack that unit ?
I have tested it with 100 times per second order attack to a unit, and the unit still won't be able to launch an attack.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
"Leak" is something that will eat your memory if you do not clean it.
In time, it will pile up your memory, making them heavier and heavier for each leak - causing the program to reduce its performance.
Until there's no space left, the game could crash.

By your definition of "leak" in this topic, it doesn't make sense at all.
 
Two trigger based approaches:
    1. Create a Trigger named "NoTeamKill" without quotes.
    2. Convert it to JASS (Edit->Convert to Custom Text).
    3. Delete JASS code and repace with this:
      JASS:
      function NoKill takes nothing returns nothing
          local unit A=GetAttacker()
          local unit D=GetTriggerUnit()
          local player P=GetOwningPlayer(A)
          if IsUnitAlly(D,P)then
              call IssueImmediateOrder(A,"stop")
          endif
          set A=null
          set D=null
          set P=null
      endfunction
      
      function InitTrig_NoTeamKill takes nothing returns nothing
          local integer I=0
          set gg_trg_NoTeamKill=CreateTrigger()
          loop
              call TriggerRegisterPlayerUnitEvent(gg_trg_NoTeamKill,Player(I),EVENT_PLAYER_UNIT_ATTACKED,null)
              set I=I+1
              exitwhen I>11
          endloop
          call TriggerAddAction(gg_trg_NoTeamKill,function NoKill)
      endfunction
  • Or...
    1. Copy this function into the map's header:
      JASS:
      function NoKill takes unit A,unit D returns nothing
          local player P=GetOwningPlayer(A)
          if IsUnitAlly(D,P)then
              call IssueImmediateOrder(A,"stop")
          endif
          set A=null
          set D=null
          set P=null
      endfunction
    2. Create a trigger to go off when a unit attacks a unit.
    3. Add this:
      • Custom script: call NoKill(GetAttacker(),GetTriggerUnit())
      You can replace GetAttacker() and GetTriggerUnit() with variables, or anything, as long as the attacking unit is the first one, and what it is attacking is the second one.
      Remember: Global variables start with udg_ in JASS.
    4. Have the Trigger do anything else you want.

After messing around with the object editor; I can not find a filter list to only allow enemy attacking. Sorry for my previous post.

PS: Units owned by a computer AI (Such as Neutral Passive, Neutral Hostile, Neutral Victim, and Neutral Extra) WILL NOT attack allies, so no reason to add them to the trigger events in the first method above.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Already Solved:

Why not use this system. Saves you having to wait. This also allows you to attack your own units. Just remove the second condition if thats not what you want.

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