User Tools

Site Tools


4rpl:commands:getunitposition

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
4rpl:commands:getunitposition [2021/01/08 11:01] – external edit 127.0.0.14rpl:commands:getunitposition [2023/01/19 09:28] (current) – Expanded example to show how to use vector (aka TrickyCorp Discord Version mod) Karsten75
Line 1: Line 1:
 ~~NOTOC~~ ~~NOTOC~~
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
 +
 +<WRAP tabs>
 +  * [[4rpl:commands:GetUnitPosition|Get]]
 +  * [[4rpl:commands:SetUnitPosition|Set]]
 +</WRAP>
  
 ====== GetUnitPosition ====== ====== GetUnitPosition ======
Line 8: Line 13:
 Get the 3D position of a unit.  A vector is returned.  The X and Z positions are where on the map the unit is, and the Y coordinate Get the 3D position of a unit.  A vector is returned.  The X and Z positions are where on the map the unit is, and the Y coordinate
 is the height, or elevation, of the unit. is the height, or elevation, of the unit.
 +
 +Note: If this call is attempted on an non-existing unit, nothing will be put on the stack. 
 +In V 2.4, this behavior changes and this API will now return V3(0 0 0), similar to other APIs. 
  
 ===== Examples ===== ===== Examples =====
 <code 4rpl> <code 4rpl>
 GetUnitPosition(<-UID) ->pos GetUnitPosition(<-UID) ->pos
 +
 +# to extract the individual values from the above vector:
 +<-pos.x ->positionX
 +<-pos.y ->positionY
 +<-pos.z ->positonZ
 +
 +# or use the .dot syntax above to directly access the values in the vector, or 
 +
 +EV3(<-pos) ->z ->y ->x
 +
 </code> </code>
 +
 +
 +A "safe" method to use this function and to handle the lack of a return value on non-existent units are as follows:
 +
 +<code 4rpl>
 + Trace (@UnitPos(7) )
 +
 +:unitPos
 +    StackSize ->size
 +    GetUnitPosition
 +    If (Stacksize <-size NEQ)
 +        V3(-1 -1 -1)
 +    endif
 +</code>
 +
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
  
4rpl/commands/getunitposition.1610121708.txt.gz · Last modified: 2021/01/08 11:01 by 127.0.0.1