Wildstar NASA Lua Template

Based on Carbine's default template. Includes a number of common sections not clearly documented or often included
Instructions

Find and Replace the following:
  • $AddonName -- Addon Name
  • $Author -- Author Name
Do not use whole word, but do make it Case Sensitive
Optional Sections

Remove sections if not desired

Slash Command
  • $SlashCommand -- String - Slash Command
  • Uncomment line in OnDocLoaded

Timer
  • $TimerInterval -- Number - Interval of Timer
  • $TimerRepeat -- Boolean - Timer Repeating
Uncomment line in OnDocLoaded if this is desired.

Interface Menu Button
  • $ShortcutKey -- String - Key for shortcut if desired. Replace with nothing if not desired
  • $MenuSprite -- String - The icon on the menu button if desired. Replace with nothing if not desired

Configuration Button
Remove if unneeded

Save and Restore Data
Remove if saved variables are undesired or unneeded

Copy
----------------------------------------------------------------------------------------------- -- $AddonName -- Copyright (c) $Author. All rights reserved -- ----------------------------------------------------------------------------------------------- require "Window" ----------------------------------------------------------------------------------------------- -- $AddonName Module Definition ----------------------------------------------------------------------------------------------- local $AddonName = {} ----------------------------------------------------------------------------------------------- -- Constants ----------------------------------------------------------------------------------------------- -- e.g. local kiExampleVariableMax = 999 -- Declare packages here also. Set them in OnLoad (See there for other aprt fo example.) -- e.g. local JSON ----------------------------------------------------------------------------------------------- -- Initialization ----------------------------------------------------------------------------------------------- function $AddonName:new(o) o = o or {} setmetatable(o, self) self.__index = self -- initialize variables here self.tSavedVariables = {} return o end function $AddonName:Init() local bHasConfigureFunction = false local strConfigureButtonText = "" local tDependencies = { -- "UnitOrPackageName", } Apollo.RegisterAddon(self, bHasConfigureFunction, strConfigureButtonText, tDependencies) end function $AddonName:OnDependencyError(strDep, strError) -- if you don't care about this dependency, return true. if strDep == " " then return true end return false end ----------------------------------------------------------------------------------------------- -- $AddonName OnLoad ----------------------------------------------------------------------------------------------- function $AddonName:OnLoad() -- load our form file -- JSON = Apollo.GetPackage("Lib:dkJSON-2.5").tPackage self.xmlDoc = XmlDoc.CreateFromFile("$AddonName.xml") self.xmlDoc:RegisterCallback("OnDocLoaded", self) end ----------------------------------------------------------------------------------------------- -- $AddonName OnDocLoaded ----------------------------------------------------------------------------------------------- function $AddonName:OnDocLoaded() if self.xmlDoc ~= nil and self.xmlDoc:IsLoaded() then self.wndMain = Apollo.LoadForm(self.xmlDoc, "$AddonNameForm", nil, self) if self.wndMain == nil then Apollo.AddAddonErrorText(self, "Could not load the main window for some reason.") return end self.wndMain:Show(false, true) -- if the xmlDoc is no longer needed, you should set it to nil -- Do this only if you don't intend to load any more forms. -- self.xmlDoc = nil -- Register handlers for events, slash commands and timer, etc. -- Events are flags that the game triggers that you can respond to. -- e.g. Apollo.RegisterEventHandler("KeyDown", "OnKeyDown", self) ---------------------- Event Handlers -------------------------------------------- -- Apollo.RegisterEventHandler("InterfaceMenuListHasLoaded", "OnInterfaceMenuLoaded", self) -- Apollo.RegisterEventHandler("$AddonName_InterfaceMenu", "$AddonNameInterfaceMenu", self) ------------------------ Slash Commands ---------------------------------------- -- Apollo.RegisterSlashCommand("$SlashCommand", "On$AddonNameOn", self) ------------------------------------- Timers ---------------------------------------- -- self.timer = ApolloTimer.Create($TimerInterval, $TimerRepeat, "OnTimer", self) -- Do additional Addon initialization that requires the UI here. end end ----------------------------------------------------------------------------------------------- -- Save and Restore Data ----------------------------------------------------------------------------------------------- function $AddonName:OnSave(eLevel) local tSavedData = {} -- This example uses account level saves. if eLevel == GameLib.CodeEnumAddonSaveLevel.Account then -- Set your variables into tData -- tData.bNoSound = self.tSavedVariables.bNoSound end return tSavedData end function $AddonName:OnRestore(eLevel, tData) if eLevel == GameLib.CodeEnumAddonSaveLevel.Account then -- Set your reference for the saved variables -- This example simply sets a table to mimic the loaded data. You can change this to split data up as you like. self.tSavedVariables = tData end end ----------------------------------------------------------------------------------------------- -- InterfaceMenu Button -- Remove if you don't want an interface menu button ----------------------------------------------------------------------------------------------- function $AddonName:OnInterfaceMenuLoaded() local tData = {"$AddonName_InterfaceMenu", "$ShortcutKey","$MenuSprite"} Event_FireGenericEvent("InterfaceMenuList_NewAddOn", "$AddonName" , tData) end function $AddonName:On$AddonNameInterfaceMenu() -- Define what happens when the InterfaceMenu button is clicked here. self:On$AddonNameOn() end ----------------------------------------------------------------------------------------------- -- Configuration Button -- Remove if you don't want configuration menu button ----------------------------------------------------------------------------------------------- function $AddonName::OnConfigure() -- Define what happens when the Configuration menu button is clicked. -- This is good for bringing uo settings menus. end ----------------------------------------------------------------------------------------------- -- $AddonName Functions ----------------------------------------------------------------------------------------------- -- This example has this section broken down a bit. ---------------------------------- Slash Command Functions ---------------------------- -- Remove if not needed function $AddonName:On$AddonNameOn() self.wndMain:Invoke() -- show the window end ----------------------------------------- Timer Functions --------------------------------- -- Remove if not needed function $AddonName:OnTimer() -- Do your timer-related stuff here. end ----------------------------------- General Functions ----------------------------------- -- General methods for your addon that do not interact with the UI go here. ----------------------------------------------------------------------------------------------- -- $AddonNameForm Functions ----------------------------------------------------------------------------------------------- --Ideally, you have multiple sections like this, one for each form. -- when the OK button is clicked function $AddonName:OnOK(wndHandler, wndControl, eMouseButton ) self.wndMain:Close() -- hide the window end -- when the Cancel button is clicked function $AddonName:OnCancel(wndHandler, wndControl, eMouseButton ) self.wndMain:Close() -- hide the window end ----------------------------------------------------------------------------------------------- -- $AddonName Instance ----------------------------------------------------------------------------------------------- local $AddonNameInst = $AddonName:new() $AddonNameInst:Init()