1. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  2. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  3. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  4. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  5. Shoot to thrill, play to kill. Sate your hunger with the 33rd Modeling Contest!
    Dismiss Notice
  6. Do you hear boss music? It's the 17th Mini Mapping Contest!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

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

Discussion in 'World Editor Help Zone' started by mik, Apr 16, 2009.

  1. mik

    mik

    Joined:
    Dec 13, 2007
    Messages:
    59
    Resources:
    0
    Resources:
    0
    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?
     
  2. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    I think there is an ability or mix of them that makes the unit never attack the same target two times in a row if there is more than 1 unit near.

    I can't remember now :(
     
  3. ap0calypse

    ap0calypse

    Joined:
    Jan 26, 2007
    Messages:
    4,776
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    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: Apr 16, 2009
  4. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    Infinite loop.
     
  5. jadegolem

    jadegolem

    Joined:
    Feb 1, 2008
    Messages:
    293
    Resources:
    0
    Resources:
    0
    • 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
     
  6. mik

    mik

    Joined:
    Dec 13, 2007
    Messages:
    59
    Resources:
    0
    Resources:
    0
    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: Apr 16, 2009
  7. ap0calypse

    ap0calypse

    Joined:
    Jan 26, 2007
    Messages:
    4,776
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    Changed it, it should work now... (a little "wait"-action and "turn off trigger" would do the trick)

    {EDIT}
    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: Apr 16, 2009
  8. mik

    mik

    Joined:
    Dec 13, 2007
    Messages:
    59
    Resources:
    0
    Resources:
    0
    Nice, that works. Thanks a lot, problem solved.