WoW:AddOn tutorial: Difference between revisions

Funky error occurring if there is a comment after the .xml file but not after the .toc file
(Initial upload)
 
(Funky error occurring if there is a comment after the .xml file but not after the .toc file)
Line 1: Line 1:
I'll try to keep this brief. Note: The formatting alone makes this look longer than it really is. This AddOn will give you your characters (x, y) coordinates located under the Mini map and it will updated in real time as you move around. Minor programming experience with any language is recommended.  
I'll try to keep this brief. Note: The formatting alone makes this look longer than it really is. This AddOn will give you your characters (x, y) coordinates located under the Mini map and it will updated in real time as you move around. Minor programming experience with any language is recommended.


Begin:
Begin:
Line 20: Line 20:


==== eCoordinates.toc contents Start ====
==== eCoordinates.toc contents Start ====
  ## Interface: 60200  -- Required. game version. <br>
  ## Interface: 60200  -- Required. game version.  
## Title: eCoordinates -- Name shown when viewing AddOn list<br>
<nowiki>##</nowiki> Title: eCoordinates -- Name shown when viewing AddOn list
## Version: 1.0        -- <br>
<nowiki>##</nowiki> Version: 1.0        --  
## Notes: Simple GPS  -- Popup title seen with mouseover on AddOn title in load screen <br>
<nowiki>##</nowiki> Notes: Simple GPS  -- Popup title seen with mouseover on AddOn title in load screen  
## Author: eSaith  -- not require<br>
<nowiki>##</nowiki> Author: eSaith  -- not require<br><br>
<br>
  eCoordinates.lua  -- required, lets WoW know what to look for
  eCoordinates.lua  -- required, lets WoW know what to look for<br>
  eCoordinates.xml   
  eCoordinates.xml  -- required, let's WoW know what to look for


[ /run print((select(4, GetBuildInfo()))) ]    -- Will give you your Interface number. Replace 60200 with your current version
[ /run print((select(4, GetBuildInfo()))) ]    -- Will give you your Interface number. Replace 60200 with your current version


==== eCoordinates.xml contents ====
==== eCoordinates.xml contents ====
  <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\..\FrameXML\UI.xsd">  <br>
  <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\..\FrameXML\UI.xsd">   
  <Script File="eCoordinates.lua"/><br>
  <Script File="eCoordinates.lua"/>
<br>
  <Frame name="eCoordinates" parent="UIParent">
  <Frame name="eCoordinates" parent="UIParent"><br>
     <Scripts>
     <Scripts><br>
         <OnLoad function="eCoordinates_OnLoad"></OnLoad>
         <OnLoad function="eCoordinates_OnLoad"></OnLoad><br>
         <OnEvent function="eCoordinates_OnEvent"></OnEvent>
         <OnEvent function="eCoordinates_OnEvent"></OnEvent><br>
     </Scripts><br></Frame>
     </Scripts><br>
</Frame><br>
  </Ui>
  </Ui>
Bare bones:
Bare bones:
Line 62: Line 59:


eCoordinates.lua contents - programming. It may look like a lot, and a lot is happening but I will try to be as clear and concise as I can be. Don't fret if it takes a minute to figure out!
eCoordinates.lua contents - programming. It may look like a lot, and a lot is happening but I will try to be as clear and concise as I can be. Don't fret if it takes a minute to figure out!
  local zone = nil<br>
  local zone = nil
  local TimeSinceLastUpdate = 0<br>
  local TimeSinceLastUpdate = 0<br>
  local function UpdateCoordinates(self, elapsed)<br>
  local function UpdateCoordinates(self, elapsed)
if zone ~= GetRealZoneText() then<br>
    if zone ~= GetRealZoneText() then<br> zone = GetRealZoneText()<br> SetMapToCurrentZone()<br>   end<br>
zone = GetRealZoneText()<br>
    TimeSinceLastUpdate = TimeSinceLastUpdate + elapsed<br>
SetMapToCurrentZone()<br>
  if TimeSinceLastUpdate > .5 then <br>         TimeSinceLastUpdate = 0<br>       local posX, posY = GetPlayerMapPosition("player"); <br>     local x = math.floor(posX * 10000)/100<br>     local y = math.floor(posY*10000)/100<br>     eCoordinatesFontString:SetText("|c98FB98ff("..x..", "..y..")") <br>
end<br>
  end
<br>
TimeSinceLastUpdate = TimeSinceLastUpdate + elapsed<br>
  if TimeSinceLastUpdate > .5 then <br>
TimeSinceLastUpdate = 0<br>
local posX, posY = GetPlayerMapPosition("player"); <br>
local x = math.floor(posX * 10000)/100<br>
local y = math.floor(posY*10000)/100<br>
eCoordinatesFontString:SetText("|c98FB98ff("..x..", "..y..")") <br>
  end <br>
  end<br>
  end<br>
  <br>
   
  function eCoordinates_OnLoad(self, event,...) <br>
  function eCoordinates_OnLoad(self, event,...)  
     self:RegisterEvent("ADDON_LOADED") <br>
     self:RegisterEvent("ADDON_LOADED")
  end<br>
  end<br>
<br>
  function eCoordinates_OnEvent(self, event, ...) <br>
  function eCoordinates_OnEvent(self, event, ...) <br>
     if event == "ADDON_LOADED" and ... == "eCoordinates" then<br>
     if event == "ADDON_LOADED" and ... == "eCoordinates" then<br>       self:UnregisterEvent("ADDON_LOADED") <br>     eCoordinates:SetSize(100, 50)<br>           eCoordinates:SetPoint("TOP", "Minimap", "BOTTOM", 5, -5)<br>       eCoordinates:SetScript("OnUpdate", UpdateCoordinates)<br>     local coordsFont =    eCoordinates:CreateFontString("eCoordinatesFontString", "ARTWORK", "GameFontNormal")<br>     coordsFont:SetPoint("CENTER", "eCoordinates", "CENTER", 0, 0)<br>     coordsFont:Show()<br>     eCoordinates:Show()
    self:UnregisterEvent("ADDON_LOADED") <br>
  end
eCoordinates:SetSize(100, 50)<br>
eCoordinates:SetPoint("TOP", "Minimap", "BOTTOM", 5, -5)<br>
eCoordinates:SetScript("OnUpdate", UpdateCoordinates)<br>
local coordsFont =    eCoordinates:CreateFontString("eCoordinatesFontString", "ARTWORK", "GameFontNormal")<br>
coordsFont:SetPoint("CENTER", "eCoordinates", "CENTER", 0, 0)<br>
coordsFont:Show()<br>
eCoordinates:Show() <br>
  end<br>
  end
  end


Line 100: Line 79:


Remember in the .xml file, line 5 we were looking for the first event OnLoad.  
Remember in the .xml file, line 5 we were looking for the first event OnLoad.  
  function eCoordinates_OnLoad(self, event,...) <br>
  function eCoordinates_OnLoad(self, event,...)  
     self:RegisterEvent("ADDON_LOADED") <br>
     self:RegisterEvent("ADDON_LOADED") <br>
  end
  end
Line 119: Line 98:
  function eCoordinates_OnEvent(self, event, ...) <br>
  function eCoordinates_OnEvent(self, event, ...) <br>
     if event == "ADDON_LOADED" and ... == "eCoordinates" then<br>
     if event == "ADDON_LOADED" and ... == "eCoordinates" then<br>
    self:UnregisterEvent("ADDON_LOADED") <br>
self:UnregisterEvent("ADDON_LOADED") <br>       eCoordinates:SetSize(100, 50)<br>       eCoordinates:SetPoint("TOP", "Minimap", "BOTTOM", 5, -5)<br> eCoordinates:SetScript("OnUpdate", UpdateCoordinates)<br> local coordsFont = eCoordinates:CreateFontString("eCoordinatesFontString", "ARTWORK", "GameFontNormal")<br>
eCoordinates:SetSize(100, 50)<br>
coordsFont:SetPoint("CENTER", "eCoordinates", "CENTER", 0, 0)<br> coordsFont:Show()<br> eCoordinates:Show()
eCoordinates:SetPoint("TOP", "Minimap", "BOTTOM", 5, -5)<br>
    end<br>
eCoordinates:SetScript("OnUpdate", UpdateCoordinates)<br>
local coordsFont = eCoordinates:CreateFontString("eCoordinatesFontString", "ARTWORK", "GameFontNormal")<br>
coordsFont:SetPoint("CENTER", "eCoordinates", "CENTER", 0, 0)<br>
coordsFont:Show()<br>
eCoordinates:Show() <br>
end<br>
  end
  end
  eCoordinates:SetSize(100, 50)
  eCoordinates:SetSize(100, 50)
Line 151: Line 124:
  -- NO CHANGES. Just a copy and paste from above for your convenience while reading so that you don;t have to scroll up as much
  -- NO CHANGES. Just a copy and paste from above for your convenience while reading so that you don;t have to scroll up as much


  local zone = nil<br>
  local zone = nil
  local TimeSinceLastUpdate = 0<br>
  local TimeSinceLastUpdate = 0<br>
  local function UpdateCoordinates(self, elapsed)<br>
  local function UpdateCoordinates(self, elapsed)
if zone ~= GetRealZoneText() then<br>
    if zone ~= GetRealZoneText() then<br> zone = GetRealZoneText()<br> SetMapToCurrentZone()<br>   end<br>
zone = GetRealZoneText()<br>
    TimeSinceLastUpdate = TimeSinceLastUpdate + elapsed<br>
SetMapToCurrentZone()<br>
  if TimeSinceLastUpdate > .5 then <br>         TimeSinceLastUpdate = 0<br>       local posX, posY = GetPlayerMapPosition("player"); <br>     local x = math.floor(posX * 10000)/100<br>     local y = math.floor(posY*10000)/100<br>     eCoordinatesFontString:SetText("|c98FB98ff("..x..", "..y..")") <br>
end<br>
  end
<br>
TimeSinceLastUpdate = TimeSinceLastUpdate + elapsed<br>
  if TimeSinceLastUpdate > .5 then <br>
TimeSinceLastUpdate = 0<br>
local posX, posY = GetPlayerMapPosition("player"); <br>
local x = math.floor(posX * 10000)/100<br>
local y = math.floor(posY*10000)/100<br>
eCoordinatesFontString:SetText("|c98FB98ff("..x..", "..y..")") <br>
  end <br>
  end
  end


Line 198: Line 162:
  local posX, posY = GetPlayerMapPosition("player");  
  local posX, posY = GetPlayerMapPosition("player");  
-- Call the Blizzard function, GetPlayerMapPosition("player"), that will return our x and y coordinate.  
-- Call the Blizzard function, GetPlayerMapPosition("player"), that will return our x and y coordinate.  
  local x = math.floor(posX * 10000)/100 <br>
  local x = math.floor(posX * 10000)/100 
  local y = math.floor(posY*10000)/100  
  local y = math.floor(posY*10000)/100  
-- The returned values will be between 0 and 1. A little math allows an arbitrary number, say.7865 into 78.65, for both the x and y values.
-- The returned values will be between 0 and 1. A little math allows an arbitrary number, say.7865 into 78.65, for both the x and y values.
Anonymous user