ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Finding out if an Addon is loaded (https://www.esoui.com/forums/showthread.php?t=7120)

DesertDwellers 06/09/17 04:41 PM

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.

Rhyono 06/09/17 07:45 PM

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.

Dolgubon 06/09/17 11:13 PM

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.

sirinsidiator 06/10/17 01:29 AM

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

DesertDwellers 06/10/17 10:52 AM

Thanks everyone that was very helpful.

I will put on my coding hat soon.

Baertram 06/10/17 02:50 PM

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.

Dolgubon 06/11/17 05:09 PM

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.


All times are GMT -6. The time now is 11:55 AM.

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