Attack-Move near another unit

futeki

Active Member
Reaction score
4
I'm trying to get units to move with the main unit, but want them to attack any enemies that are nearby. I may be going about this the wrong way and perhaps I need it to be a 'periodic event' instead of 'issued an order' event, but I'm really unsure.

However, the overall goal is simple, I want to have a group of units of a certain type, attack-move around the owner of a particular unit and at the same time, not all move to the same location. I want them to move to random locations around that unit ranging from 100-500 range.

Anyone have any ideas and able to help?

I'm guessing I need to set the location of the unit I want them to move with into a variable, but it's the rest that confuses me.

Here is my code so far:
Trigger:
  • Trigger
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Owner of (Triggering unit)) Equal to (Owner of Unit)
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Hero
    • Actions
      • Unit Group - Pick every unit in (Units within 540.00 of (Position of (Triggering unit)) matching ((Unit-type of (Picked unit)) Equal to Helping Unit)) and do (Unit - Order (Picked unit) to Attack-Move To (Position of (Triggering unit)))
 

Tyman2007

Ya Rly >.
Reaction score
74
Always use multiple functions for unit groups even if it's only for 1 function. It makes your life much easier.

But, you should have a wait at the beginning, and even then, this is more of a job for jass.
 

futeki

Active Member
Reaction score
4
Always use multiple functions for unit groups even if it's only for 1 function. It makes your life much easier.

But, you should have a wait at the beginning, and even then, this is more of a job for jass.

Don't know jass, but would be happy to use it as long as it can be used in correlation with GUI.
 

Baby-Bever

Cool Member
Reaction score
11
Trigger:
  • Events
    • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Owner of (Triggering unit)) Equal to (Owner of Unit)
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Hero
    • Actions
      • Set Temp_Group = (Units within 540.00 of (Position of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to HelpingUnit))
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • Set Temp_Point = ((Position of (Triggering unit)) offset by (Random real number between 100.00 and 500.00) towards (Random angle) degrees)
          • Unit - Order (Picked unit) to Attack-Move To Temp_Point
          • Custom script: call RemoveLocation(udg_Temp_Point)
      • Custom script: call DestroyGroup (udg_Temp_Group)


That's how I'd go about doing what you want. Changed a couple of things. First of all, I used the other "Pick every unit" thingy so that you get a better overlook of what you're doing.

The second thing I did was adding 2 variables, one point variable and one unit group. This is for the reason that these kinds of variables leak otherwise, and for the same reason I remove them after their usage (the two Custom Script lines).

When using "Units matching condition" in any scenario, remeber to use "Matching Unit", not "Picked Unit", as it's not picked yet, it's just being subject to a comparison.

The Units will now also be ordered to move to a random position in the range interval 100-500 range in any direction.


Does that work for you?
 

futeki

Active Member
Reaction score
4
Trigger:
  • Events
    • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Owner of (Triggering unit)) Equal to (Owner of Unit)
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Hero
    • Actions
      • Set Temp_Group = (Units within 540.00 of (Position of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to HelpingUnit))
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • Set Temp_Point = ((Position of (Triggering unit)) offset by (Random real number between 100.00 and 500.00) towards (Random angle) degrees)
          • Unit - Order (Picked unit) to Attack-Move To Temp_Point
          • Custom script: call RemoveLocation(udg_Temp_Point)
      • Custom script: call DestroyGroup (udg_Temp_Group)


That's how I'd go about doing what you want. Changed a couple of things. First of all, I used the other "Pick every unit" thingy so that you get a better overlook of what you're doing.

The second thing I did was adding 2 variables, one point variable and one unit group. This is for the reason that these kinds of variables leak otherwise, and for the same reason I remove them after their usage (the two Custom Script lines).

When using "Units matching condition" in any scenario, remeber to use "Matching Unit", not "Picked Unit", as it's not picked yet, it's just being subject to a comparison.

The Units will now also be ordered to move to a random position in the range interval 100-500 range in any direction.


Does that work for you?

That's sexy! I knew I was close, but have been screwing around with it for close to 2 days now and could never really get it to work right. That makes much better sense, you would've laughed had you seen my other feeble attempts. :)

Thank you so much! +rep for being sexy
 

futeki

Active Member
Reaction score
4
Glad to be able to help!

I got one for you, how about being able to do the same thing, but making them move to the point in which the unit was ordered to move:

I changed position of triggering unit to target point of issued order, but that doesn't seem to work.
Trigger:
  • Set Temp_Point = ((Target point of issued order) offset by (Random real number between 100.00 and 500.00) towards (Random angle) degrees)
 

canons200

New Member
Reaction score
50
you can always set the unit acquisition range to higher value, so that when they are moving, with enough vision, if they manage to find enemy. they will attack first.
 

Baby-Bever

Cool Member
Reaction score
11
Question: Are you ordering your hero to attack another unit?

As we use the Event - A unit is issued an order targeting a point, that also means a point, as in move or attack-move or such. In case you order your hero to attack a unit, he gets no such order, and thus the trigger will not run at all.
 

futeki

Active Member
Reaction score
4
Question: Are you ordering your hero to attack another unit?

As we use the Event - A unit is issued an order targeting a point, that also means a point, as in move or attack-move or such. In case you order your hero to attack a unit, he gets no such order, and thus the trigger will not run at all.

To give more insight into what I'm trying to do, I'm trying to make it where while this unit (Hero) is on this quest and unable to attack, He'll have protection but I want that protection to completely surround him. If He's given an order to move somewhere, I want them to surround him and always be completely around him - e.g. ahead of him, behind him and either side.

He's in a rush to complete the quest before His protectors die and He's left unprotected, which means the attackers will kill him and the player loses the trial and has to start all over. But He has to move all over an open area of map that's why I need them all around him. Like a barrier or perimeter.
 

Baby-Bever

Cool Member
Reaction score
11
Ahhh,

I understand


Then:

Do you want them to stand in a certain formation, or just spread out randomly around the hero?

How many units do you want?
 

futeki

Active Member
Reaction score
4
Ahhh,

I understand


Then:

Do you want them to stand in a certain formation, or just spread out randomly around the hero?

How many units do you want?

I wouldn't mind a certain formation as long as they move to a random distance each time He moves.

I currently have 4 units, but may add more. However, if I have to stay with 4 units, it won't kill me as I can weaken the attackers a bit.
 

Baby-Bever

Cool Member
Reaction score
11
Tried around a little, recreating your wanted effect.

With the trigger we had before only one of my units would move togheter with the hero correctly. The other 3 ran to the middle. It seems that the line "Target Point of Issued Order" is overridden when anyone else is given an order. The following trick will solve that:

Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Owner of (Triggering unit)) Equal to (Owner of Footman 0002 <gen>)
      • (Triggering unit) Equal to Mountain King 0004 <gen>
    • Actions
      • Set Move_Point = (Target point of issued order)
      • Set Temp_Group = (Units within 540.00 of (Position of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to Footman))
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • Set Temp_Point = (Move_Point offset by (Random real number between 100.00 and 500.00) towards (Random angle) degrees)
          • Unit - Order (Picked unit) to Attack-Move To Temp_Point
          • Custom script: call RemoveLocation(udg_Temp_Point)
      • Custom script: call DestroyGroup (udg_Temp_Group)
      • Custom script: call RemoveLocation(udg_Move_Point)


What I did was introducing a new variable, another point one. In that one ("Move_Point") I store the Target point of issued order.

Better? :)
 

futeki

Active Member
Reaction score
4
Tried around a little, recreating your wanted effect.

With the trigger we had before only one of my units would move togheter with the hero correctly. The other 3 ran to the middle. It seems that the line "Target Point of Issued Order" is overridden when anyone else is given an order. The following trick will solve that:

Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Owner of (Triggering unit)) Equal to (Owner of Footman 0002 <gen>)
      • (Triggering unit) Equal to Mountain King 0004 <gen>
    • Actions
      • Set Move_Point = (Target point of issued order)
      • Set Temp_Group = (Units within 540.00 of (Position of (Triggering unit)) matching ((Unit-type of (Matching unit)) Equal to Footman))
      • Unit Group - Pick every unit in Temp_Group and do (Actions)
        • Loop - Actions
          • Set Temp_Point = (Move_Point offset by (Random real number between 100.00 and 500.00) towards (Random angle) degrees)
          • Unit - Order (Picked unit) to Attack-Move To Temp_Point
          • Custom script: call RemoveLocation(udg_Temp_Point)
      • Custom script: call DestroyGroup (udg_Temp_Group)
      • Custom script: call RemoveLocation(udg_Move_Point)


What I did was introducing a new variable, another point one. In that one ("Move_Point") I store the Target point of issued order.

Better? :)

I'll admit, it works good for the majority of the time because of the units range, but there are some times when the enemies get too close because the units don't fully surround him.

Is there a way to make them move/stand in say a box formation around him?
 

Pritrostell

New Member
Reaction score
1
when you have the units move to the variable based on your hero's move, make each units point offset by (x,y) from the hero's move target point... should do the trick
 

futeki

Active Member
Reaction score
4
when you have the units move to the variable based on your hero's move, make each units point offset by (x,y) from the hero's move target point... should do the trick

Yea, I finally figured that out. :shades: Took me forever though and it's still not perfect, especially when encountering edges of a forest, but it'll work.
 

haxic

New Member
Reaction score
2
when you have the units move to the variable based on your hero's move, make each units point offset by (x,y) from the hero's move target point... should do the trick

Been reading this thread now and its interesting.

But in my opinion you should have a none-temp UnitGroup (a UnitGroup Array if you want more Heroes) were you save all the Hero's guardians, instead of pick all units around him.

The reason is simply to make it all easier :)
etc; if the units get out of range when "picking all units within 540 range", well, those units wont get picked... If you pick all units from the Hero's UnitGroup, they will always get picked if they so are on the other side of the map...

If you only want 1 Hero its easy to do, if you want many Heroes you have to use UnitGroup array and register the Hero. Easiest way to do imo is; set a "new" Custom Value for each Hero (Hero 1 - Custom Value = 1, Hero 2 - Custom Value = 2 and so on) and when you want to add Guardians to a specific Hero's UnitGroup -> you add those units to UnitGroup[Custom Value of "Hero 1"].

When you then do the order (move / attack move) you pick units in UnitGroup[Custom value of Triggering Unit]

I can't cook up a trigger for you cus I'm not at my own comp, but if I made myself clear perhaps someone else can help you with that.
 

Baby-Bever

Cool Member
Reaction score
11
Well, It's true as Haxic states, as I suppose you want all guards to go to the hero's position no matter the distance between them, not only those close, it would be wise creating a trigger at map init were you add all your guards to a unit group:

Trigger:
  • Guard Initializing
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Add all your guards here --------
      • Unit Group - Add Unit to Guards_Group
      • Unit Group - Add Unit to Guards_Group
      • Unit Group - Add Unit to Guards_Group
      • Unit Group - Add Unit to Guards_Group


This adds all your guards to the unitgroup Guards_Group.

I also made some changes in the main trigger, partly to make them move in a formation around the hero, and partly to use our new unit group:

Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Owner of (Triggering unit)) Equal to (Owner of Unit)
      • (Triggering unit) Equal to Hero
    • Actions
      • Set Move_Point = (Target point of issued order)
      • Set Angle = 0.00
      • Unit Group - Pick every unit in Guards_Group and do (Actions)
        • Loop - Actions
          • Custom script: call RemoveLocation (udg_Move_Point)
          • Set Temp_Point = (Move_Point offset by (Random real number between 100.00 and 500.00) towards Angle degrees)
          • Unit - Order (Picked unit) to Attack-Move To Temp_Point
          • Set Angle = (Angle + (360.00 / (Real((Number of units in Guards_Group)))))
          • Custom script: call RemoveLocation (udg_Temp_Point)


As you can see, a couple minor changes. First of all, instead of using the Temp_Group, I now use the Guards_Group. In addition to this i added a real variable. This variable tells us in what directions in which the guards are supposed to stand.

Trigger:
  • Set Angle = (Angle + (360.00 / (Real((Number of units in Guards_Group)))))


That line sets the direction of every guard but the firsts direction from the hero. If you got 4 guards, that would place one at 0 degrees, one at 90, one at 180 and finally one at 270. If you decide to have 5 guards, they will be ordered to stand at the degrees: 0, 72, 144, 216 and 288.

Beware that they might not fully cover all sides of the hero if one of the guards do happen to die. The way to solve this is to remove Guards from the "Guards_Group" when one of them dies.

Actually, I don't know if you were in need of this post, but I'll post it anyway. Might be able to help someone, some time.
 

futeki

Active Member
Reaction score
4
Believe it or not I actually did just that considering the range kept screwing up. I just have trouble sometimes getting started with a trigger, once it's started I can easily improve it.

Overall though, it's a nifty trigger and I couldn't find something similar to start with on the forum. Thanks a-lot!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top