Thread Tools Display Modes
06/09/17, 04:41 PM   #1
DesertDwellers
AddOn Author - Click to view addons
Join Date: May 2017
Posts: 25
Finding out if an Addon is loaded

Trying to find code to identify if an addon is loaded, so when a certain screen is up on that addon it will hide my addon. Specifically when using the craftstore addon to craft food my addon always is on top of it, same with cookery wiz. My thought was to when it sees it open it will hide my addon.
  Reply With Quote
06/09/17, 07:45 PM   #2
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
CS is in the local scope (open the main lua file, it's literally the first line). If you remove the "local" then you can check for it like this in your addon:

lua Code:
  1. function test()
  2.     if CS then
  3.         d("CraftStore loaded.")
  4.     else
  5.         d("CraftStore not loaded.")
  6.     end
  7. end

To hide your addon, you'd add an event for EVENT_CRAFTING_STATION_INTERACT, ensure the craft skill is CRAFTING_TYPE_PROVISIONING and then you'd add an event for EVENT_END_CRAFTING_STATION_INTERACT to bring your addon back.

Last edited by Rhyono : 06/09/17 at 07:50 PM.
  Reply With Quote
06/09/17, 11:13 PM   #3
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
I'm not sure if there are any functions you can use to see if an addon is loaded. However, in general, when an addon is loaded, the EVENT_ON_ADDON_LOADED is fired, and it passes the name of the addon in question. You can use this to compile a list of the addons that are active. Another option would be to check the addon list in the escape menu, but if there's no API function then that's kind of roundabout.
  Reply With Quote
06/10/17, 01:29 AM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
I'd say the best way to check for an addon is to look for global variables it sets. Other than that you can either listen to EVENT_ADD_ON_LOADED and check the passed name (might fire too late for some cases though), or you asked the all-mighty ADDON_MANAGER to spill the secret:

Lua Code:
  1. local manager = GetAddOnManager()
  2. local function IsAddonRunning(addonName)
  3.     for i = 1, manager:GetNumAddOns() do
  4.         local name, _, _, _, _, state = manager:GetAddOnInfo(i)
  5.         if name == addonName and state == ADDON_STATE_ENABLED then
  6.             return true
  7.         end
  8.     end
  9.     return false
  10. end
  Reply With Quote
06/10/17, 10:52 AM   #5
DesertDwellers
AddOn Author - Click to view addons
Join Date: May 2017
Posts: 25
Thanks everyone that was very helpful.

I will put on my coding hat soon.
  Reply With Quote
06/10/17, 02:50 PM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
If your addon depends on the other addon (or optionally depends on it as it needs functions from it, if the other addon is loaded), you can achieve that your addon gets loaded AFTER the other addon by using the addon manifest .txt file.

If you want your addon be optionally depending on other addons:
Code:
## OptionalDependsOn: LibAddonMenu-2.0 AnotherAddonName
If you want your addon be depending on other addons:
Code:
## DependsOn: LibAddonMenu-2.0 AnotherAddonName
-> Warning: If you use "DependsOn" your addon will not load if the other addon is not found (afaik).


As example:
LibAddonmenu-2.0 is a common addon menu library.
AnotherAddonName is the name of another addon, like e.g. CookeryWiz

You need to check the correct addon name of the other addon by checking the lua/txt file name of the other addon.
  Reply With Quote
06/11/17, 05:09 PM   #7
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
As another example, I tend to add pChat as an optional dependency. That way, I can place d() messages and have them show up even if they're called before the chat loads. Another optional dependency in one of my addons is MasterMerchant - that allows me to make sure I can ask MM for price checks. Finally, to see an example of a non optional dependency, check out Master Merchant. It has MM00-MM15 as dependencies, and the addon won't load without those active.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Finding out if an Addon is loaded

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