Thread Tools Display Modes
05-08-20, 01:37 AM   #1
Barleduq
Premium Member
 
Barleduq's Avatar
Premium Member
Join Date: Jan 2012
Posts: 135
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
  Reply With Quote
05-08-20, 02:09 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
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)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 05-08-20 at 03:25 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Guideline for turning lua code into addon?

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