WoW:API GetPlayerMapPosition: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(Added minor info about the 0,0 error and SetMapToCurrentZone.)
m (Move page script moved page API GetPlayerMapPosition to API GetPlayerMapPosition without leaving a redirect)
 
(12 intermediate revisions by 12 users not shown)
Line 1: Line 1:
<center>'''GetPlayerMapPosition''' ''-Documentation by [[user:Meog|Meog]]-''</center>
{{wowapi}} __NOTOC__


==Initialization==
A one-time call to [[API SetMapToCurrentZone|SetMapToCurrentZone]]() is required before GetPlayerMapPosition() will return the correct values.


Returns the postion of a unit on the current map
==Usage==
Returns the position of a unit on the current map


  posX, posY = GetPlayerMapPosition("unit");
  posX, posY = GetPlayerMapPosition("unit");


----
== Parameters ==
;''Arguments''
=== Arguments ===


:("unit")
:;unit : String - The [[unitId]] for which the position is returned. Does not work with all unit types. Works with <tt>"player"</tt>, <tt>"party''N''"</tt> or <tt>"raid''N''"</tt> as unit type. In particular, it does not work on pets.  This was to disable range-checking mods.
:;unit : String - The [[API TYPE UnitId|UnitId]] for which the position is returned. (Does not work with all unit types. Works with <tt>player</tt>, <tt>party<i>N</i></tt> or <tt>raid<i>N</i></tt> as unit type. This was to disable range-checking mods).


----
=== Returns ===
;''Returns''


:posX, posY
:posX, posY
Line 19: Line 20:
:;posY : Number - Y value of the unit position (a proportion between 0 and 1, relative to WorldMapDetailFrame)
:;posY : Number - Y value of the unit position (a proportion between 0 and 1, relative to WorldMapDetailFrame)


If both posX and posY are 0, then the position is unknown, unknowable, or not valid for the current map. This usually happens inside an instance, if the map hasn't been updated (by either opening the map or using [[API_SetMapToCurrentZone|SetMapToCurrentZone]]) after entering a new zone, or using a [[API TYPE UnitId|UnitId]] other than the ones above.
: If both posX and posY are exactly 0, the position is unknown, unknowable, or not valid for the current map, i.e.
:* The map hasn't been updated yet; either open the map or use [[API SetMapToCurrentZone|SetMapToCurrentZone]]() after entering a new zone
:* An unsupported [[unitId]] was given.
:* You're actually at 0,0 in a given map, which although its unlikely, its perfectly possible and legal.


----
== Example ==
;''Example''
  local posX, posY = GetPlayerMapPosition("player");
  local posX, posY = GetPlayerMapPosition("player");


;''Result''
=== Result ===
  0.43320921063423, 0.69365233182907
  0.43320921063423, 0.69365233182907
----
{{Template:WoW API}}
[[Category:API Functions|GetPlayerMapPosition]]
[[Category:API World Map Functions|GetPlayerMapPosition]]

Latest revision as of 04:46, 15 August 2023

WoW API < GetPlayerMapPosition

Initialization[edit]

A one-time call to SetMapToCurrentZone() is required before GetPlayerMapPosition() will return the correct values.

Usage[edit]

Returns the position of a unit on the current map

posX, posY = GetPlayerMapPosition("unit");

Parameters[edit]

Arguments[edit]

unit
String - The unitId for which the position is returned. Does not work with all unit types. Works with "player", "partyN" or "raidN" as unit type. In particular, it does not work on pets. This was to disable range-checking mods.

Returns[edit]

posX, posY
posX
Number - X value of the unit position (a proportion between 0 and 1, relative to WorldMapDetailFrame)
posY
Number - Y value of the unit position (a proportion between 0 and 1, relative to WorldMapDetailFrame)
If both posX and posY are exactly 0, the position is unknown, unknowable, or not valid for the current map, i.e.
  • The map hasn't been updated yet; either open the map or use SetMapToCurrentZone() after entering a new zone
  • An unsupported unitId was given.
  • You're actually at 0,0 in a given map, which although its unlikely, its perfectly possible and legal.

Example[edit]

local posX, posY = GetPlayerMapPosition("player");

Result[edit]

0.43320921063423, 0.69365233182907