• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

A trigger to attack back

Status
Not open for further replies.
Level 4
Joined
Feb 7, 2007
Messages
61
How would i make a trigger to order a Unit whos being attacked to attack back. But if attacked by a different unit, then ignore it. Because if more than 1 Unit attacks the mob. The unit whos being attacked will not know which one to attack.
 
Last edited:
Ok..

Player 12 has a unit. and it is getting attacked by 5 units by Player 1 simultaneously. If i have a trigger that looks like..

  • Untitled Trigger 001
    • Events
      • Unit - A unit owned by Player 12 (Brown) Is attacked
    • Conditions
    • Actions
      • Unit - Order (Attacked unit) to Attack (Attacking unit)
When this happens, player 12 unit will keep looking at the last unit who attacked it, but wont attack.

I need something that will make it to where, if player 12 unit is already attacking the unit who attacked it, then ignore any other unit who attacks it.
 
i think neutrals attack the 1st attacker automatically. same goes for player-controlled units, unless given a different order.
 
Actually, my game does give a different order. I have Player 12 units to target a gate. So with the trigger there, if Player 12 brown gets attack otherwise by a ground unit, it will attack back. But, like i said, if it gets jumped by 10 people. It wont know who to attack...

SO i need something that makes it to where Whatever Unit attacked Player 12's Unit First, it will lock on to that specific unit until its dead.
 
Well you could just make it stop when attacked, then it will attack whatever is hitting it, using the unit priority within its AI
 
Attack back is a built in function am I right?
Units will attack back whenever they're attacked.
 
Yes, of course, but like I say, if the unit who is being attacked gets hit by multiple enemies at once, that would be a problem since it keeps trying to target the specific unit who attacked him, therefore he will keep looking at the last target who attacked him, but will not attack back
 
If you wanted this to happen for every unit that is attacked then you would have to add the units that were attacked to a unit group, and only issue the attack order if the unit is not already in the unit-group. In order to reset a unit's "fight back" status you would simply need to remove the unit from that group. This could be done on a number of events, or even a periodic interval after the first unit of the "mob" attacks.

It's not very difficult to have a unit strike the first unit to strike it, but what's harder is determining when the mob has been dispatched of and when to allow the unit to attack the next unit to attack him.
 
Can you provide an example trigger so that i can understand you more clearly?

Edit: i did try to solve this problem with this trigger: but unfortunately, i dont think it works.

  • Untitled Trigger 001
    • Events
      • Unit - A unit owned by Player 12 (Brown) Is attacked
    • Conditions
      • (Current order of (Attacked unit)) Not equal to (Order(attack))
    • Actions
      • Unit - Order (Attacked unit) to Attack (Attacking unit)
 
Just use a hashtable. Store the unit that attacks your unit and check if hes dead periodically.

  • EX
  • Events
    • Unit - Unit is attacked
  • Conditions
    • Unit - *Attacked unit belongs to you*
    • Unit - Attacker belongs to enemy
    • Unit - Attacker not equal to 0 of key(attacked unit) in hashtable
  • Actions
    • If -
      • 0 of key(attacked unit) in hashtable is dead = true
    • Then
      • Hashtable - Save attacking unit as 0 of key(attacked unit) in hashtable
      • Unit - Order attacked unit to attack 0 of key(attacked unit) in hashtable
    • Else
      • ---
Remember to create a hashtable variable so you don't overwrite data. This is the basic idea behind it, and can be changed. Note that spells will not trigger this event. If you attempt to do the same with spells, note that AoE spells could bug. Also note that this isn't the only way to do this. You can make it more complex this way, or you can simplify it and try without hashtables. Experiment some and see what you come up with. :)


*Not necessary. Can be replaced with a user/computer check to prevent the computers from doing the same or you can remove it and everything will perform this way.
 
That looks complexed..is there anyway you can, perhaps help me, or explain it better..i am a nub. lol

i dont know how to work with hatchables
 
Hshtables are great to learn as they make complex GUI systems and spells possible. Basically, It saves data under two numbers instead of one. This wouldn't be much different than an array variable, except for the use of handles. A handle is a number used to call upon in-game objects. By using (for example, Attacked Unit) a handle, you are saving data exclusive to each object. 0 of key(Attacked Unit) is the 0th position of Attacked Unit's hashtable.

You should read a tutorial for a better explanation. This is made up from my mind. :)

So in my example trigger, I have a hastable and It saves 0 of (Attacked Unit) as the Attacking Unit. It checks that units status whenever attacked to determine if it should retaliate. With some extra work and tweaking, you could make this an in-depth AI that can respond with or to spells and ranged attacks.
 
Status
Not open for further replies.
Back
Top