Thread Tools Display Modes
11/25/22, 03:56 PM   #1
CleetusTheDiabeetus
Join Date: Nov 2022
Posts: 2
Nearest Wayshrine to Player

Hello All,

I was looking for some guidance on where to start for creating an AddOn with a UI that displays the closest Wayshrine to a player's position.

I need to:
Determine Player PosX, PosY
Find All Wayshrine Locations
Calculate the closest wayshine from the players location
Output that information to a UI
Where can I pull player position?
Where can I get a list of wayshrines and their locations?

P.S:
I tried looking at the "FasterTravel" AddOn which determines the closest wayshrine to your quest but it was too advanced for me to figure out exactly what the functions they created were doing.

Thank you.
  Reply With Quote
11/25/22, 05:36 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,913
There is no api to detect that, you are not the first to try this.
You'd need to manually collect all washrine positions in a table of your addon, and update it every patch.
I hope you got time?

Last edited by Baertram : 11/25/22 at 05:40 PM.
  Reply With Quote
11/25/22, 06:36 PM   #3
CleetusTheDiabeetus
Join Date: Nov 2022
Posts: 2
It has been done in the AddOn FasterTravel by manually adding each entry, I can copy their table I suppose. I don't know how they have determined which one is closest though.

They found the closest Wayshrine to your quest, I just need to change it to Closest to player.
  Reply With Quote
11/25/22, 09:43 PM   #4
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 627
Are you going to be detecting the closest player to you in your group? Because you can't get other players positions that aren't in your group.
  Reply With Quote
11/25/22, 11:37 PM   #5
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Originally Posted by CleetusTheDiabeetus View Post
Hello All,

I was looking for some guidance on where to start for creating an AddOn with a UI that displays the closest Wayshrine to a player's position.

I need to:
Determine Player PosX, PosY
Find All Wayshrine Locations
Calculate the closest wayshine from the players location
Output that information to a UI
Where can I pull player position?
Where can I get a list of wayshrines and their locations?

P.S:
I tried looking at the "FasterTravel" AddOn which determines the closest wayshrine to your quest but it was too advanced for me to figure out exactly what the functions they created were doing.

Thank you.
There is a complicated code in minimap by Fyrakin doing that which I improved because POI_TYPE_WAYSHRINE also includes non wayshrines (e. g. the harborage) but it is quite a work to extract the code.
in function
Lua Code:
  1. function FyrMM.Wayshrines()
You do a loop with
Lua Code:
  1. for nodeIndex = 1, GetNumFastTravelNodes() do
, get node info with
Lua Code:
  1. GetFastTravelNodeInfo(nodeIndex)
then it is filtered to exclude houses and other non wayshrine stuff you can port to,
distance from each wayshrine is calculated with
Lua Code:
  1. math.sqrt((player.nx-wayshrine.nX)*(player.nx-wayshrine.nX)+(player.ny-wayshrine.nY)*(player.ny-wayshrine.nY))
then you have to do a table with all your wayshrines and their distances (which will update when player moves) to find the closest.
  Reply With Quote
11/27/22, 07:43 AM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,913
oh btw, player position:
Lua Code:
  1. local playerUnitTag = "player"
  2.  
  3. --- @return zoneId integer, worldX integer, worldY integer, worldZ integer
  4. local zoneId, worldX, worldY, worldZ = GetUnitWorldPosition(playerUnitTag)
  5. local zoneId, worldX, worldY, worldZ = GetUnitRawWorldPosition(playerUnitTag)
  6.  
  7. --- @return normalizedX number, normalizedZ number, heading number, isShownInCurrentMap bool
  8. local normalizedX, normalizedZ, heading, isShownInCurrentMap = GetMapPlayerPosition(playerUnitTag)

Maybe some libs can help here too, check the Lib descriptions for the ones relating to maps, positions, etc. and also to calculate between normalized and actual positions (not sure which lib was supporting this, maybe LibMapPin or LibGPS?).

Last edited by Baertram : 11/27/22 at 07:47 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Nearest Wayshrine to Player

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off