Thread Tools Display Modes
01-29-13, 07:34 PM   #1
A_Nolan
A Deviate Faerie Dragon
 
A_Nolan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 16
Question GetDungeonDifficultyID and PLAYER_DIFFICULTY_CHANGED do they go together?

function FIZ_OnLoad(self)
-- Events monitored by Event Handler
FIZ_Main = self
self:RegisterEvent("ADDON_LOADED")
self:RegisterEvent("VARIABLES_LOADED")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_LOGIN")
self:RegisterEvent("GUILD_PERK_UPDATE")
self:RegisterEvent("PLAYER_DIFFICULTY_CHANGED")
end

function FIZ_OnEvent(self, event, ...)
local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 = ...
if (event == "ADDON_LOADED") and (arg1 == FIZ_NAME) then
FIZ_Main:UnregisterEvent("ADDON_LOADED")
FIZ_InitStages = FIZ_InitStages + 1
FIZ_Init()
elseif (event == "VARIABLES_LOADED") then
filler
elseif (event == "PLAYER_LOGIN") then
filler
elseif (event == "PLAYER_ENTERING_WORLD") then
filler
--elseif( event == "PLAYER_LEAVING_WORLD" ) then
filler
elseif (event == "UPDATE_FACTION" or
event == "QUEST_COMPLETE" or
event == "QUEST_WATCH_UPDATE") then
filler
elseif ( event == "BAG_UPDATE") then
filler
--elseif ( event == "UNIT_INVENTORY_CHANGED") then
filler
elseif ( event == "BANKFRAME_OPENED") then
filler
elseif ( event == "BANKFRAME_CLOSED") then
filler
elseif ( event == "CHAT_MSG_SKILL") or
filler
elseif ( event == "GUILD_PERK_UPDATE") then
filler
elseif ( event == "PLAYER_DIFFICULTY_CHANGED") then
FIZ_difficultyID = GetDungeonDifficultyID()
if (FIZ_difficultyID == 2) then
FIZ_IsHeroic = true
else
FIZ_IsHeroic = false
end
end

ok the sticky said to enter the entire code so i'v put in the main part. Is PLAYER_DIFFICULTY_CHANGED the correct event to pull when the dungeon difficulty (normal/heroic) is toggled. I have the correct setup to get the difficulty but can't get the thing to fire when i toggle it.
__________________
w.w.J.d. read the book and find out (J 3:16)
  Reply With Quote
01-29-13, 08:01 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Did you double-check that it's firing by putting in a print() statement or watching the event trace (/eventtrace)?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-30-13, 03:09 AM   #3
A_Nolan
A Deviate Faerie Dragon
 
A_Nolan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 16
thank you

well it didn't fire but now that iv figured out print (i am i still haven't learned lua fully but i am trying ) now i am shoving in prints everywhere to find out its flow chart. but event trace didn't find an event when i changed from normal to heroic (arrg). so i still need to find out what it shows up as.
__________________
w.w.J.d. read the book and find out (J 3:16)
  Reply With Quote
01-30-13, 11:00 AM   #4
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
I'm not sure when PLAYER_DIFFICULTY_CHANGED is triggered...

AFAIK you can not change dungeon difficulty while inside a heroic/instance, so logic-wise one would use CHAT_MSG_SYSTEM event to scan the message for DUNGEON_DIFFICULTY or RAID_DIFFICULTY.

The correct message is formatted with ERR_DUNGEON_DIFFICULTY_CHANGED_S. I can't give a code example as I forgot how to do sscanf-like(php) function call in lua.

Another event which might be helpful is PLAYER_ENTERING_WORLD. This triggers if the player is entering an instance.

Last edited by ravagernl : 01-30-13 at 11:22 AM.
  Reply With Quote
01-30-13, 12:05 PM   #5
Farmbuyer
A Cyclonian
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 43
Originally Posted by A_Nolan View Post
ok the sticky said to enter the entire code so i'v put in the main part. Is PLAYER_DIFFICULTY_CHANGED the correct event to pull when the dungeon difficulty (normal/heroic) is toggled. I have the correct setup to get the difficulty but can't get the thing to fire when i toggle it.
I remember that the only thing Blizzard registers to listen for that event is the minimap, to change the little icon cluster. If you haven't already, extract their code and take a look at FrameXML/Minimap.* to see what they're doing.

Next, some random tips for Lua addons:

Code:
function FIZ_OnEvent(self, event, ...)
    local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13 = ...
You can also just capture the arguments that you know you'll need later, and then give them meaningful names. Easier to maintain and saves a little memory:

Code:
-- Nothing I'm listening for uses arg3/4/5 or 7+
function FarmForum_OnEvent (self, event, arg1, arg2, _, _, _, arg6)
    ......
    elseif event == "STUFF_WITH_SPELLS" then
        local partymember, spellname = arg2, arg6
        do_Foo (me, him, partymember, the_thing, spellname)

    elseif event == "CHEESE_GOING_BAD" then
        local bagslot, flavor = arg1, arg2
        expiringCheese (bagslot, flavor, stuff)
Eventually, you'll almost certainly want to split out each event handler into its own function, so that your OnEvent doesn't become gigantic and hard to maintain. An event dispatcher like this is quite common:

Code:
function FarmForum_OnEvent (self, event, ...)
    local handler = self[event]
    if type(handler) == "function" then
        -- passing the event name is a little redundant for this example but is useful in the general case
        return handler (self, event, ...)
    end
end
Then your individual handler functions are named after the event, and can also name their arguments directly:

Code:
local MyFrame = Global_Name_of_FarmForum_Frame_From_Wherever_I_Declared_It

function MyFrame:ADDON_LOADED (event, addon_name)
    -- addon_name is arg1 here but is also a more self-explanatory name
end

function MyFrame:PLAYER_ENTERING_WORLD()
    -- doesn't take any args
end

function MyFrame:CHEESE_GOING_BAD (event, bagslot, flavor)
    print("Dammit!  The", flavor, "cheese in slot", bagslot, "is turning green!")
end
  Reply With Quote
01-30-13, 01:18 PM   #6
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by Farmbuyer View Post
I remember that the only thing Blizzard registers to listen for that event is the minimap, to change the little icon cluster. If you haven't already, extract their code and take a look at FrameXML/Minimap.* to see what they're doing.
Doh, I totally forgot about the little icon. PLAYER_DIFFICULTY_CHANGED seems to indeed be the right event according to Minimap.lua (do a search on MiniMapInstanceDifficulty_OnEvent()): https://github.com/tekkub/wow-ui-sou...ML/Minimap.lua

Using GetInstanceInfo() seems to provide the correct info about what difficulty is used.

lua Code:
  1. local isHeroic
  2. function eventFrame:PLAYER_DIFFICULTY_CHANGED ()
  3.     local _, type, difficulty, _, _, dynamicDifficulty, isDynamicInstance = GetInstanceInfo()
  4.     -- type == 'party' part is optional.
  5.     isHeroic = (isDynamicInstance and dynamicDifficulty == 1 or difficulty = 2) --[[ and type == 'party' ]]
  6.  
  7.     print("isHeroic: ", isHeroic and 'yes' or 'no')
  8. end
  9.  
  10. eventFrame.PLAYER_ENTERING_WORLD = eventFrame.PLAYER_DIFFICULTY_CHANGED

Last edited by ravagernl : 01-30-13 at 01:22 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » GetDungeonDifficultyID and PLAYER_DIFFICULTY_CHANGED do they go together?

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