ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Only show addon msg when player login (https://www.esoui.com/forums/showthread.php?t=1176)

Saucy 04/25/14 06:40 PM

Only show addon msg when player login
 
Hello everyone,

I wish to only print that the addon has been loaded in the chat when the player just had logged in. My current code prints every time the player logs in, /reloadui or changes zone.

As it is right now, it's a bit spammy for my taste. Is it possible to only show the "addon: loaded" message once?

Lua Code:
  1. local addon = ZO_Object:Subclass()
  2. local EM    = GetEventManager();
  3.  
  4. function addon:New()
  5.   EM:RegisterForEvent('addon_OnLoad', EVENT_ADD_ON_LOADED,    function(...) self:OnLoad(...) end)
  6.   EM:RegisterForEvent('addon_OnInit', EVENT_PLAYER_ACTIVATED, function(...) self:OnInit(...) end)
  7. end
  8.  
  9. function addon:OnLoad(eventCode, addonName)
  10.   if ('addon' ~= addonName) then return end
  11. end
  12.  
  13. function addon:OnInit()
  14.   d('addon: loaded')
  15. end
  16.  
  17. addon:New()

LilBudyWizer 04/25/14 10:25 PM

Just set a variable while processing the addon loaded event. You can't avoid on /reloadui unless you want to avoid the initial load as well and never show the message. You can avoid displaying it after the initial player activation though.

Lua Code:
  1. local function onAddonLoaded()
  2.     addon.firstActivation = true
  3. end
  4.  
  5. local function onPlayerActivated()
  6.     if (addon.firstActivation) then
  7.         addon.firstActivation = false
  8.         Print("Hello World!")
  9.     end
  10. end

ins 04/26/14 02:36 AM

Unregister the event in onInit.

Iyanga 04/26/14 05:34 AM

Quote:

Originally Posted by Saucy (Post 5909)
Hello everyone,

I wish to only print that the addon has been loaded in the chat when the player just had logged in. My current code prints every time the player logs in, /reloadui or changes zone.


That's not possible, the addon can't see the difference whether a new "gaming session" was started or he just switched characters. You can only get rid of the zone change message.


For my addons, I don't print a message, but just supply a slash command, even if they have no settings. The slash command prints the "Addon: Running" message for people to verify that it was loaded.

Stormknight 04/26/14 06:23 AM

Please please please do NOT output a line to chat on load.

Does it really need it? What does it accomplish? Most addons I have seen do this, it's just a vanity statement to let the user know the addon has loaded.

Imagine if all addons did this.... I have 16 addons running currently.

That said, if you have a real need .... There doesn't seem to be an event you can catch, so I have currently seen two ways:

1. Have your initialisation function create a callback timer for 2 seconds later and use that to output the message.

2. Use the zone in event you're probably catching currently, but have a variable that you set to say you've done the output and check the value of that variable each event.

Saucy 04/26/14 09:24 AM

Quote:

Originally Posted by LilBudyWizer (Post 5930)
Just set a variable while processing the addon loaded event. You can't avoid on /reloadui unless you want to avoid the initial load as well and never show the message. You can avoid displaying it after the initial player activation though.

Lua Code:
  1. local function onAddonLoaded()
  2.     addon.firstActivation = true
  3. end
  4.  
  5. local function onPlayerActivated()
  6.     if (addon.firstActivation) then
  7.         addon.firstActivation = false
  8.         Print("Hello World!")
  9.     end
  10. end

Quote:

Originally Posted by ins (Post 5941)
Unregister the event in onInit.

Thanks, both of your suggestions worked.

Quote:

Originally Posted by Iyanga (Post 5951)
That's not possible, the addon can't see the difference whether a new "gaming session" was started or he just switched characters. You can only get rid of the zone change message.


For my addons, I don't print a message, but just supply a slash command, even if they have no settings. The slash command prints the "Addon: Running" message for people to verify that it was loaded.

Hmm, okay. I'm guessing the response from LilBudyWizer and ins are the next best thing.

Quote:

Originally Posted by Stormknight (Post 5956)
Please please please do NOT output a line to chat on load.

Does it really need it? What does it accomplish? Most addons I have seen do this, it's just a vanity statement to let the user know the addon has loaded.

Imagine if all addons did this.... I have 16 addons running currently.

That said, if you have a real need .... There doesn't seem to be an event you can catch, so I have currently seen two ways:

1. Have your initialisation function create a callback timer for 2 seconds later and use that to output the message.

2. Use the zone in event you're probably catching currently, but have a variable that you set to say you've done the output and check the value of that variable each event.

Sometimes I think it's great to know that the addon you just downloaded is working, compared to it being completely silent and there's no menu settings or slash commands. Nor being able to turn off the chat message.

I'm building my addon that only one of them prints to the chat (which can be turned on/off via menu settings or slash command). So my other addons will never print anything to the chat. I'm also building it to have all modules in a single menu setting where the user can find all the settings for the addons.

LilBudyWizer 04/26/14 11:28 AM

It can be useful, but mostly as a debugging aid. Rather than an option the user can turn on and off you might consider just making it a debug option. I use:

Lua Code:
  1. addon =
  2. {
  3.     ...
  4.     debug =
  5.     {
  6.     }
  7.     ...
  8. }

The debug variable acts as a switch for general debugging. Specific parts of debugging, like logging events and such, are controlled with variables within that table. I then just change it to nodebug when I want to turn it off for release. I can always turn it back on at the command line with addon.debug = addon.nodebug. The actual check in the code for suboptions is:

Lua Code:
  1. if (addon.debug and addon.debug.option) then
  2. end

where addon is the global for the addon, i.e. the addon name.

Vuelhering 04/26/14 12:14 PM

Quote:

Originally Posted by Stormknight (Post 5956)
Please please please do NOT output a line to chat on load.

Does it really need it? What does it accomplish? Most addons I have seen do this, it's just a vanity statement to let the user know the addon has loaded.

Imagine if all addons did this.... I have 16 addons running currently.

That said, if you have a real need .... There doesn't seem to be an event you can catch, so I have currently seen two ways:

There's an event PLAYER_ACTIVATED when you can print it out.

I was going to do this for noting the CLI slash command, but you've convinced me that it is not necessary more than once. So I'll do it on the first login of a character only.


All times are GMT -6. The time now is 03:32 PM.

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