Thread: 3.1 Update
View Single Post
08/16/17, 04:00 PM   #37
Weolo
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 79
Event_non_combat_bonus_changed

I have figured out what is bugged, I was not expecting this..
There is a problem with the new event EVENT_NON_COMBAT_BONUS_CHANGED, it fires on logout to character selection screen and I guess at quit game also.

I hope I am correct in assuming this event should only fire when playing on your character when the skills are changed and not when going to the character selection screen or quitting the game.

Brand new example addon and code:

Name: TestAddon
SavedVariables file: TestAddon
Test value: TestAddon.settings.test.something

Steps:
1. Pick a character and log in
2. /reloadui
3. Check SV file
4. TestAddon.settings.test.something = "First"
5. Log out to character selection screen
6. Check SV file
7. TestAddon.settings.test.something = "Non Combat"

TestAddon.lua:
Lua Code:
  1. local function OnNonCombatBonusChanged(eventCode, nonCombatBonusType)
  2.     TestAddon.settings.test.something = "Non Combat"
  3. end
  4. local function DefaultSettings()
  5.     local defaults = {
  6.         test = {}
  7.     }
  8.     return defaults
  9. end
  10. local function OnPlayerActivated()
  11.     if TestAddon.player_activated then return end
  12.     TestAddon.player_activated = true
  13.     EVENT_MANAGER:UnregisterForEvent("TestAddon", EVENT_PLAYER_ACTIVATED)
  14.    
  15.     TestAddon.settings.test.something = "First"
  16. end
  17. local function OnLoaded(eventType, addonName)
  18.     if addonName ~= "TestAddon" then return end
  19.     TestAddon.settings = ZO_SavedVars:NewAccountWide("TestAddonSettings", 1, nil, DefaultSettings())
  20.     EVENT_MANAGER:RegisterForEvent("TestAddon", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
  21.     EVENT_MANAGER:RegisterForEvent("TestAddon", EVENT_NON_COMBAT_BONUS_CHANGED, OnNonCombatBonusChanged)
  22. end
  23.  
  24. TestAddon = {
  25.     player_activated = false
  26. }
  27. EVENT_MANAGER:RegisterForEvent("TestAddon", EVENT_ADD_ON_LOADED, OnLoaded)

TestAddon.txt
Code:
## Title: TestAddon
## APIVersion: 100020
## SavedVariables: TestAddonSettings
## Version: 1.0

TestAddon.lua
SavedVariables File TestAddon.lua After reloadui
Lua Code:
  1. TestAddonSettings =
  2. {
  3.     ["Default"] =
  4.     {
  5.         ["@Weolo"] =
  6.         {
  7.             ["$AccountWide"] =
  8.             {
  9.                 ["version"] = 1,
  10.                 ["test"] =
  11.                 {
  12.                     ["something"] = "First",
  13.                 },
  14.             },
  15.         },
  16.     },
  17. }

SavedVariables File TestAddon.lua After log out to character selection screen
Lua Code:
  1. TestAddonSettings =
  2. {
  3.     ["Default"] =
  4.     {
  5.         ["@Weolo"] =
  6.         {
  7.             ["$AccountWide"] =
  8.             {
  9.                 ["version"] = 1,
  10.                 ["test"] =
  11.                 {
  12.                     ["something"] = "Non Combat",
  13.                 },
  14.             },
  15.         },
  16.     },
  17. }
  Reply With Quote