WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Guideline for turning lua code into addon? (https://www.wowinterface.com/forums/showthread.php?t=57987)

Barleduq 05-08-20 01:37 AM

Guideline for turning lua code into addon?
 
Long ago, I found a post on here giving steps to turn any bit of lua code into an addon. I recently found a weakaura that reports token price, and I'd much rather have it as an addon. Unfortunately, my disk drive ate itself back in February, and I had to create a whole new machine, and lost my bookmarks. Could someone point me to this post?

I'm sure I'll have more questions then. I'm currently planning on snitching code from other addons to give it a frame and make it moveable. I don't code well, but I can copy-paste! (assuming I can figure out the effective code snippets)

Then I'll just have to make it *actually* update on price change. *sigh*
advTHANKSance
-Barleduq

Fizzlemizz 05-08-20 02:09 AM

This website allows you to paste some of your code and create a downloadable .zip addon as per sites like WoWI.

Change the Title from "My First Addon" to a unique name as that will be the name of the addon/folder.

Limits, it's a single .lua file and sadly they have remove the advanced .toc options button(s).

I hope that's close enough to what you are asking about (it gives you the basic folder name with corresponding .toc name and source file that makes up the core of an addon).

Something basic to paste to display/update on change the token price at the top/center of your screen initially.

Lua Code:
  1. -- Function to display the price
  2. local function UpdateTokenPrice(self)
  3.     local Price = C_WowTokenPublic.GetCurrentMarketPrice()
  4.     if not Price then
  5.         self.Text:SetText("N/A")
  6.         return
  7.     end
  8.     self.Text:SetText("|TInterface/ICONS/Wow_Token01:0:0:2:0|t "..GetMoneyString(Price, true))
  9.     self:SetSize(self.Text:GetSize())
  10. end
  11. -- Create a Frame and make it dragable
  12. local CurrencyFrame = CreateFrame("Button", "BarleduqCurrencyFrame", UIParent)
  13. CurrencyFrame:SetSize(14, 14)
  14. CurrencyFrame:SetPoint("TOP", 0, -4)
  15. CurrencyFrame:SetFrameStrata("DIALOG")
  16. CurrencyFrame:EnableMouse(true)
  17. CurrencyFrame:RegisterForDrag("LeftButton")
  18. CurrencyFrame:SetMovable(true) -- Create frame before PLAYER_LOGIN to save position
  19. CurrencyFrame:SetScript("OnDragStart", function(self) self:StartMoving() end)
  20. CurrencyFrame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
  21. -- Create a Fontstring to display the current price
  22. CurrencyFrame.Text = CurrencyFrame:CreateFontString("$parentText", "OVERLAY")
  23. CurrencyFrame.Text:SetFont("Fonts/FRIZQT__.TTF", 21)
  24. CurrencyFrame.Text:SetPoint("CENTER")
  25. CurrencyFrame.Text:SetJustifyH("CENTER")
  26. -- register the token change event
  27. CurrencyFrame:RegisterEvent("TOKEN_MARKET_PRICE_UPDATED")
  28. -- Script to update the price when it changes
  29. CurrencyFrame:SetScript("OnEvent", function(self, event, ...)
  30.     UpdateTokenPrice(self)
  31. end)
  32. --Display the price on startup (the event might not fire for minutes/hours/days...)
  33. UpdateTokenPrice(CurrencyFrame)


All times are GMT -6. The time now is 12:11 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI