Thread Tools Display Modes
04/25/14, 06:40 PM   #1
Saucy
 
Saucy's Avatar
Join Date: Apr 2014
Posts: 20
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()
  Reply With Quote
04/25/14, 10:25 PM   #2
LilBudyWizer
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 32
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
  Reply With Quote
04/26/14, 02:36 AM   #3
ins
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 76
Unregister the event in onInit.
  Reply With Quote
04/26/14, 05:34 AM   #4
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Saucy View Post
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.
  Reply With Quote
04/26/14, 06:23 AM   #5
Stormknight
 
Stormknight's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 128
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.
  Reply With Quote
04/26/14, 09:24 AM   #6
Saucy
 
Saucy's Avatar
Join Date: Apr 2014
Posts: 20
Originally Posted by LilBudyWizer View Post
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
Originally Posted by ins View Post
Unregister the event in onInit.
Thanks, both of your suggestions worked.

Originally Posted by Iyanga View Post
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.

Originally Posted by Stormknight View Post
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.
  Reply With Quote
04/26/14, 11:28 AM   #7
LilBudyWizer
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 32
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.
  Reply With Quote
04/26/14, 12:14 PM   #8
Vuelhering
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 169
Originally Posted by Stormknight View Post
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.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Only show addon msg when player login


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