Mercurial > wow > whistle-master
comparison WhistleMaster.lua @ 0:06d230725448
Initial build of WhistleMaster
| author | Geoff Brock <mischivin@gmail.com> |
|---|---|
| date | Mon, 24 Oct 2016 15:41:49 -0400 |
| parents | |
| children | 4402edd42a3f |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:06d230725448 |
|---|---|
| 1 | |
| 2 function WM_Debug() | |
| 3 print("debug text") | |
| 4 end | |
| 5 | |
| 6 --indexes corrispond to map IDs that contain valid flight points for the Flight Masters Whistle | |
| 7 local validIDs = { [1014] = true, [1015] = true, [1017] = true, [1018] = true, [1024] = true, [1033] = true, [1096] = true } | |
| 8 | |
| 9 local WhistleLoc = CreateFrame("FRAME", "WhistleLOC", WorldMapPOIFrame) | |
| 10 WhistleLoc:SetSize(64, 64) | |
| 11 WhistleLoc:SetPoint("CENTER", 0, 0) | |
| 12 WhistleLoc:Show() | |
| 13 | |
| 14 --[[local Rotate = WhistleLoc:CreateTexture() | |
| 15 Rotate:SetTexture("Interface\minimap\UI-Minimap-Ping-Rotate") | |
| 16 Rotate:SetPoint("CENTER") | |
| 17 Rotate:SetSize(48, 48) | |
| 18 Rotate:SetVertexColor(0.9, 0.1, 0.1) | |
| 19 | |
| 20 local Ring = WhistleLoc:CreateTexture() | |
| 21 Ring:SetTexture("Interface\minimap\UI-Minimap-Ping-Center") | |
| 22 Ring:SetPoint("CENTER") | |
| 23 Ring:SetSize(32, 32) | |
| 24 Ring:SetVertexColor(0.9, 0.1, 0.1)]] | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 local function GetDistance(nX, nY) | |
| 30 local pX, pY = GetPlayerMapPosition("player") | |
| 31 | |
| 32 local dX = pX - nX | |
| 33 local dY = pY - nY | |
| 34 | |
| 35 return math.sqrt( ( dX^2 ) + ( dY^2 ) ) | |
| 36 end | |
| 37 | |
| 38 local function GetNode() | |
| 39 local node | |
| 40 local distance | |
| 41 local index | |
| 42 for k = 1, GetNumMapLandmarks() do | |
| 43 local n = {} | |
| 44 n.type, n.name, n.description, n.textureIndex, n.x, n.y = GetMapLandmarkInfo(k) | |
| 45 if n.type == LE_MAP_LANDMARK_TYPE_TAXINODE then --LE_MAP_LANDMARK_TYPE_TAXINODE is a constant defined by Blizzard | |
| 46 local d = GetDistance(n.x, n.y) | |
| 47 if distance == nil or d < distance then | |
| 48 n.index = k | |
| 49 distance = d | |
| 50 node = n | |
| 51 end | |
| 52 end | |
| 53 end | |
| 54 print("The closest node is... " .. node.name) | |
| 55 return node | |
| 56 end | |
| 57 | |
| 58 local function UpdateWhistleMaster() | |
| 59 if GetCurrentMapContinent() == 8 and validIDs[ select(1, GetCurrentMapAreaID() ) ] then | |
| 60 local closest = GetNode() | |
| 61 WhistleLoc:SetPoint("CENTER", "WorldMapFramePOI" .. closest.index, 0, 0) | |
| 62 WhistleLoc:Show() | |
| 63 WhistlePing.Ping:Play() | |
| 64 else | |
| 65 WhistleLoc:Hide() | |
| 66 WhistlePing.Ping:Stop() | |
| 67 print("wrong continent for whistle master") | |
| 68 end | |
| 69 end | |
| 70 | |
| 71 local mapVisible = false | |
| 72 | |
| 73 local function EventHandler(self, event, ...) | |
| 74 if ( (event == "WORLD_MAP_UPDATE") and WorldMapFrame:IsVisible() ) then | |
| 75 mapVisible = true | |
| 76 UpdateWhistleMaster() | |
| 77 end | |
| 78 if ( (mapVisible) and not WorldMapFrame:IsVisible() ) then | |
| 79 mapVisible = false | |
| 80 end | |
| 81 end | |
| 82 | |
| 83 | |
| 84 | |
| 85 local WhistleMaster = CreateFrame("FRAME", "WhistleMaster", WorldMapPOIFrame) | |
| 86 WhistleMaster:RegisterEvent("WORLD_MAP_UPDATE") | |
| 87 WhistleMaster:SetScript("OnEvent", EventHandler) | |
| 88 |
