WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   GetDungeonDifficultyID and PLAYER_DIFFICULTY_CHANGED do they go together? (https://www.wowinterface.com/forums/showthread.php?t=45757)

A_Nolan 01-29-13 07:34 PM

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
Quote:

filler
elseif (event == "PLAYER_LOGIN") then
Quote:

filler
elseif (event == "PLAYER_ENTERING_WORLD") then
Quote:

filler
--elseif( event == "PLAYER_LEAVING_WORLD" ) then
Quote:

filler
elseif (event == "UPDATE_FACTION" or
event == "QUEST_COMPLETE" or
event == "QUEST_WATCH_UPDATE") then
Quote:

filler
elseif ( event == "BAG_UPDATE") then
Quote:

filler
--elseif ( event == "UNIT_INVENTORY_CHANGED") then
Quote:

filler
elseif ( event == "BANKFRAME_OPENED") then
Quote:

filler
elseif ( event == "BANKFRAME_CLOSED") then
Quote:

filler
elseif ( event == "CHAT_MSG_SKILL") or
Quote:

filler
elseif ( event == "GUILD_PERK_UPDATE") then
Quote:

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.

Seerah 01-29-13 08:01 PM

Did you double-check that it's firing by putting in a print() statement or watching the event trace (/eventtrace)?

A_Nolan 01-30-13 03:09 AM

thank you
 
well it didn't fire but now that iv figured out print (i am :o 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:mad:). so i still need to find out what it shows up as.

ravagernl 01-30-13 11:00 AM

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.

Farmbuyer 01-30-13 12:05 PM

Quote:

Originally Posted by A_Nolan (Post 272575)
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:

Quote:

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


ravagernl 01-30-13 01:18 PM

Quote:

Originally Posted by Farmbuyer (Post 272591)
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


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

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