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

[Solved] Event when a unit is near an allied unit

Status
Not open for further replies.
Level 2
Joined
Dec 15, 2019
Messages
11
So, I want to create an event which converts a unit to another when the player gives a smart order (right click) on a certain building, but I want this event to work only if the targeted building is owned by the player who owns the triggering unit and if the unit is near the targeted building.

So, when the player right clicks on a certain building with a certain unit, this unit moves to the building and changes to another unit when he has reached a certain area around this building. (and only if this building is in the same team as the unit)

For now I did this (Some of it is in french, sorry in advance)

wy0u.png


Everything works as intended except for the "same-team" and "near the building" part.
I looked for an answer on internet for a day now and I found nothing :(
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
When the unit is issued the move order, put it in a unit group. Periodically check in the radius around all of the buildings and if you find a unit owned by the same player that's in the group then convert it.
If the unit is given any other order, remove it from the group. I suggest morphing with Hero passive transformation instead of replacing the unit because that will keep command groups.

When a unit is stunned it's issued the order 851972, which has no string equivalent. You can either choose to ignore the possibility that a unit is stunned while in transit to be converted, which would break the conversion, or filter it out with a JASS custom script (since you can't check order ids in GUI, only order strings).

  • Events
    • Unit - A unit is issued an order targeting an object
    • Unit - A unit is issued an order targeting a point
    • Unit - A unit is issued an order with no target
  • Conditions
    • (Unit-type of (Triggering Unit)) equal to Différent de Archer
  • Actions
    • Custom script: if GetIssuedOrderId() != 851972 then
    • If (All conditions are true) then do (then actions) else do (else actions)
      • If - Conditions
        • (Issued order) equal to Order(smart)
        • (Unit-type of (Target unit of issued order)) equal to Ferme
        • (Owner of (Target unit of issued order)) equal to (Owner of (Triggering Unit))
      • Then - Actions
        • Unit Group - Add (Triggering Unit) to ArcherGroup
      • Else - Actions
        • Unit Group - Remove (Triggering Unit) from ArcherGroup
    • Custom script: endif
  • Events
    • Time - Every 0.50 seconds of game-time
  • Conditions
  • Actions
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units of type Ferme) and do (Actions)
      • Loop - Actions
        • Set FUnit = (Picked Unit)
        • Set FPlayer = (Owner of FUnit)
        • Unit Group - Pick every unit in ArcherGroup and do (Actions)
          • Loop - Actions
            • Set AUnit = (Picked Unit)
            • If (All conditions are true) then do (Then actions) else do (Else actions)
              • If - Conditions
                • (Owner of AUnit) equal to FPlayer
              • Then - Actions
                • Set Point1 = (Position of AUnit)
                • Set Point2 = (Position of FUnit)
                • If (All conditions are true) then do (Then actions) else do (Else actions)
                  • If - Conditions
                    • (Distance between Point1 and Point2) less than or equal to TRANSFORM_DISTANCE
                  • Then - Actions
                    • Unit - Add REVERSE_BEAR_FORM_MORPH to AUnit
                    • Unit - Remove REVERSE_BEAR_FORM_MORPH from AUnit
                  • Else - Actions
                • Custom script: call RemoveLocation(udg_Point1)
                • Custom script: call RemoveLocation(udg_Point2)
              • Else - Actions
 
Status
Not open for further replies.
Top