• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] How to get location of ally's army

Status
Not open for further replies.
Level 1
Joined
May 3, 2018
Messages
3
Hi guys,

I'm going to make AI stick together by lead them to other ally's army.

I have made every unit of AI follow their army or their heroes. It worked pretty good.

JASS:
set u = FirstOfGroup(g)
......
// Follow their army
call IssuePointOrder(u, "move", GetLocationX(army_loc[main_army]), GetLocationY(army_loc[main_army]))

// Follow their heroes
set major_hero = GetMajorHero()

call IssuePointOrder(u, "move", GetUnitX(major_hero), GetUnitY(major_hero))

But I don't know how to get ally's army/heroes location. I tried these script below but AI just go to somewhere.

JASS:
set u = FirstOfGroup(g)
......
call IssuePointOrder(u, "move", GetLocationX(ally_loc), GetLocationY(ally_loc))
call IssuePointOrder(u, "move", GetLocationX(hero_ally_loc[1]), GetLocationY(hero_ally_loc[1]))

I just use ally_loc and hero_ally_loc that available in the original script but it didn't work.

How can I get location from ally's army and ally's heroes?
 
Level 8
Joined
Mar 19, 2017
Messages
248
You need to assign those location vars some location data before using them.
In fact, you should simply use coordinates for that matter (in the last line of your first trigger, notice how you access a coordinate with GetUnitX(unit), instead of GetLocationX(GetUnitLocation(unit))), because you will most likely create lots of locations. If you insist on using locations you should use a global location variable and move it each time you want to use it.

Since you are using custom scripts, you can unlock the power of simply using clean coordinates instead of messing with locations.

JASS:
call IssuePointOrder(u, "move", GetRectCenterX(myRectVariable), GetRectCenterY(myRectVariable))

This function will order the unit to move to the center of a rect you know or created. This variable could be an array.


JASS:
call IssuePointOrder(u, "move", GetRandomReal(GetRectMinX(myRectVariable), GetRectMaxX(myRectVariable)), GetRandomReal(GetRectMinY(myRectVariable), GetRectMaxY(myRectVariable)))

This function will order the unit to move to a random point on a rect you know or created.

JASS:
call IssuePointOrder(u, "move", GetUnitX(myUnitVariable), GetUnitY(myUnitVariable))


This function will order the unit to move to the position of a unit you know or created.

JASS:
set realVariable1 = 50  //Offset
set realVariable2 = GetRandomReal(0,bj_PI*2) //Random angle in radians

call IssuePointOrder(u, "move", GetUnitX(myUnitVariable) + realVariable1 * Cos(realVariable2), GetUnitY(myUnitVariable) + realVariable1 * Sin(realVariable2))

This function will order the unit to move to the position of a unit you know or created, with a given offset towards a random angle (think of GUI polar projection function).
 
Level 1
Joined
May 3, 2018
Messages
3
JASS:
call IssuePointOrder(u, "move", GetUnitX(myUnitVariable), GetUnitY(myUnitVariable))


This function will order the unit to move to the position of a unit you know or created.

Thanks, I used the function above. By using ally's hero as a point, I will make AIs stick together in team game but I don't know how to get ally's hero of the AI, just like I got that AI's hero (major hero) that available in the original script.

JASS:
call IssuePointOrder(u, "move", GetUnitX(major_hero), GetUnitY(major_hero))
 
Status
Not open for further replies.
Top