• 🏆 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!

How to teleport Units without them losing their waypoint?

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Use the JASS only functions "SetUnitX" and "SetUnitY".

Their declarations are given below.
JASS:
native SetUnitX takes unit whichUnit,real newX returns nothing
native SetUnitY takes unit whichUnit,real newY returns nothing
What they do is instantly move whichUnit to the new cord. No pathing checks are run in doing so. The units current orders are not interrupted so if it was going to a waypoint it should still keep trying to move there. For a brief moment the unit might act funny and do something like walking in the wrong direction however that should quickly auto correct the next pathfinder tick it is given by the game engine.

If you are not used to JASS scripting you can call these functions like this.
JASS:
call SetUnitX(udg_AUNIT, udg_AREALA)
call SetUnitY(udg_AUNIT, udg_AREALB)

All you need to do is before calling them set the global variable "AUNIT" of type unit to the unit you want to move, the global variable "AREALA" of type real to the X cord of the point you want to move to and the global variable "AREALB" of type real to the Y cord of the point you want to move to.
 
Level 5
Joined
Jun 25, 2013
Messages
52
Use the JASS only functions "SetUnitX" and "SetUnitY".

Their declarations are given below.
JASS:
native SetUnitX takes unit whichUnit,real newX returns nothing
native SetUnitY takes unit whichUnit,real newY returns nothing
What they do is instantly move whichUnit to the new cord. No pathing checks are run in doing so. The units current orders are not interrupted so if it was going to a waypoint it should still keep trying to move there. For a brief moment the unit might act funny and do something like walking in the wrong direction however that should quickly auto correct the next pathfinder tick it is given by the game engine.

If you are not used to JASS scripting you can call these functions like this.
JASS:
call SetUnitX(udg_AUNIT, udg_AREALA)
call SetUnitY(udg_AUNIT, udg_AREALB)

All you need to do is before calling them set the global variable "AUNIT" of type unit to the unit you want to move, the global variable "AREALA" of type real to the X cord of the point you want to move to and the global variable "AREALB" of type real to the Y cord of the point you want to move to.

Thanks for the precise answer.
But what to do when you have multiple Unit Types... I got like 12 different which all need to be moved. And can I somehow check for player colour of moved unit? Do I need to do the Triggercode 12 times ?

So with native I would have to write
which_unit = Orc (Object Editor Name (?))
NewX = xcoordinates
NewY = ycoordinates (how do I look coordinates up btw?)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
So with native I would have to write
which_unit = Orc (Object Editor Name (?))
NewX = xcoordinates
NewY = ycoordinates (how do I look coordinates up btw?)
No you do as I told you.

All you need to do is before calling them set the global variable "AUNIT" of type unit to the unit you want to move, the global variable "AREALA" of type real to the X cord of the point you want to move to and the global variable "AREALB" of type real to the Y cord of the point you want to move to.
Before calling these two lines of custom script.
JASS:
call SetUnitX(udg_AUNIT, udg_AREALA)
call SetUnitY(udg_AUNIT, udg_AREALB)
As the game only runs correct JASS code and like scripting languages it has a very precise syntax.

But what to do when you have multiple Unit Types... I got like 12 different which all need to be moved. And can I somehow check for player colour of moved unit? Do I need to do the Triggercode 12 times ?
You use the same trigger that works for all 12 unit types. Although some form of case like binary search would probably be fastest, you can simply perform a linear test against all of the unit types to see if it is applicable for movement. You probably can check the player colour of units however I would rather recommend checking the owner player (for a value or inside a force (player group)).

(how do I look coordinates up btw?)
You can get them from a location (point). I am not sure if GUI has the functions but they do certainly exist in JASS.
JASS:
native GetLocationX takes location whichLocation returns real
native GetLocationY takes location whichLocation returns real
Which leads to some alternative lines of custom script you could use.
JASS:
call SetUnitX(udg_AUNIT, GetLocationX(udg_APOINT))
call SetUnitY(udg_AUNIT, GetLocationY(udg_APOINT))
Where AUNIT is the unit you want to move and APOINT is the location (point) you want to move it to. Do remember that locations are not destroyed automatically so unless you use a constant location for movement (such as a spawn point) then you will need to remove them after you are done using them to prevent leaks.
 
Level 12
Joined
Nov 3, 2013
Messages
989
I'm guessing OP didn't get how he would set the variable to the unit that has been trained?

In GUI the event would be "generic event - building finishes training a unit" or something like that.

and then you would do "set AUNIT = Trained unit" and then you would have APOINT be the rallypoint.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
That was an example of doing it in GUI..
No it was not.

This...
unit move trained unit to tempPoint2
Violates his requirements of this...
teleport them and the Waypoint set at the first facility still applies
Since rally points need not target points.

Here is evidence why it does not work from BattleNet.
You can command workers to build and harvest Lumber or mine Gold by setting the Rally Point of the Town Hall on trees or the Gold Mine.
Rally Points can be set on any unit.
Rally Points set on transports or Orc Burrows will cause the newly built units to load into them.
 
Status
Not open for further replies.
Top