• 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.

Attack Random Unit {making a unit automatically attack other than its closer}

Status
Not open for further replies.

mik

mik

Level 4
Joined
Dec 13, 2007
Messages
59
Normally, a unit will attack the first unit that comes into its range and will continue attacking it until it dies.

Now, is it possible to make units attack any random unit within its range automatically, no matter if the unit it last attacked died in the meantime or not?

Best is if it used the normal attack for that (including animation, damage type etc.), but if thats not possible, is there a workaround that could be similar to it?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Maybe this works:

  • Events
    • Unit - A unit Is attacked
  • Conditions
    • (Unit-type of (Attacking unit)) Equal to [Your Unit]
  • Actions
    • Trigger - turn off (This Trigger)
    • Set TempLoc = (Position of (Attacking unit))
    • Set TempUnitGroup = (Units within [Range of Your Unit] of TempLoc matching ((Owner of (Matching unit)) Not equal to (Owner of (Attacking unit))))
    • Unit - Order (Attacking unit) to Attack (Random unit from TempUnitGroup)
    • Custom script: call RemoveLocation (udg_TempLoc)
    • Custom script: call DestroyGroup(udg_TempUnitGroup)
    • Wait 0.10 Seconds of Game time
    • Trigger - turn on (This Trigger)
Since the event "a unit is attacked" reacts right before the the unit is actually attacked
 
Last edited:
Level 12
Joined
Mar 23, 2008
Messages
942
Maybe this works:

  • Events
    • Unit - A unit Is attacked
  • Conditions
    • (Unit-type of (Attacking unit)) Equal to [Your Unit]
  • Actions
    • Set TempLoc = (Position of (Attacking unit))
    • Set TempUnitGroup = (Units within [Range of Your Unit] of TempLoc matching ((Owner of (Matching unit)) Not equal to (Owner of (Attacking unit))))
    • Unit - Order (Attacking unit) to Attack (Random unit from TempUnitGroup)
    • Custom script: call RemoveLocation (udg_TempLoc)
    • Custom script: call DestroyGroup(udg_TempUnitGroup)
Since the event "a unit is attacked" reacts right before the the unit is actually attacked

Infinite loop.
 

mik

mik

Level 4
Joined
Dec 13, 2007
Messages
59
  • Lol Trigger
  • Events
    • Insert Event
  • Conditions
    • Insert Conditions
  • Actions
    • Unit Group - Pick random 1 unit in (Entire Map) and do Multiple Actions
      • Loop
        • Unit - Order <Your Unit> to attack picked unit
Theres Ur Answur

Hmm i dont think this is what i wanted... it will attack a random unit, but what if its not in range? And how do i get it to attack another unit after that attack, without getting a trigger loop?

Anyway, thanks for replies so far.
 
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
Infinite loop.

Changed it, it should work now... (a little "wait"-action and "turn off trigger" would do the trick)

{EDIT}
Hmm i dont think this is what i wanted... it will attack a random unit, but what if its not in range? And how do i get it to attack another unit after that attack, without getting a trigger loop?

Anyway, thanks for replies so far.

I've changed my trigger, but it'll only work if the attack speed is higher than 0.1
Otherwise, it will attack the same unit multiple times and then (after 0.1 sec), attack another unit.

Also, it won't work if there are a lot of those units attacking at the same moment
 
Last edited by a moderator:

mik

mik

Level 4
Joined
Dec 13, 2007
Messages
59
I've changed my trigger, but it'll only work if the attack speed is higher than 0.1
Otherwise, it will attack the same unit multiple times and then (after 0.1 sec), attack another unit.

Also, it won't work if there are a lot of those units attacking at the same moment

Nice, that works. Thanks a lot, problem solved.
 
Status
Not open for further replies.
Top