Quantcast Is this the correct event for instances? - WoWInterface
Thread Tools Display Modes
10-26-18, 05:22 PM   #1
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 949
Is this the correct event for instances?

I am looking at ZONE_CHANGED_NEW_AREA to see if the player has zoned into an instance. Any instance, scenario, raid, dungeon, arena, battleground, or whatever else, so long as it is an instance.

I know I can use IsInInstance() once there, but I'm wondering if I have the correct event in the first place.
  Reply With Quote
10-26-18, 05:34 PM   #2
Terenna
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 44
I just use PLAYER_ENTERING_WORLD. always fires, there's no event specific for loading into an instance, so if you only want something while in an instance, you have to do IsInInstance()

edit: here's some relevant code I use for a minimap addon that shows various texts based on instance difficulty:

Lua Code:
  1. --This block of code controls the text in the bottom right of the minimap that confers to the difficulty you're currently on
  2. local tMinimapDifficultyTextFrame = CreateFrame('frame', nil, Minimap)
  3. tMinimapDifficultyTextFrame:SetSize(24, 12)
  4. tMinimapDifficultyTextFrame:SetPoint('BOTTOMRIGHT', Minimap, 'BOTTOMRIGHT', -1, 1)
  5. tMinimapDifficultyTextFrame:RegisterEvent('PLAYER_ENTERING_WORLD')
  6. tMinimapDifficultyTextFrame:RegisterEvent('CHALLENGE_MODE_START')
  7. tMinimapDifficultyTextFrame:RegisterEvent('CHALLENGE_MODE_COMPLETED')
  8. tMinimapDifficultyTextFrame:RegisterEvent('CHALLENGE_MODE_RESET')
  9. tMinimapDifficultyTextFrame:RegisterEvent('PLAYER_DIFFICULTY_CHANGED')
  10. tMinimapDifficultyTextFrame:RegisterEvent('GUILD_PARTY_STATE_UPDATED')
  11.  
  12. local instanceDifficultyTable = {
  13.     [1]     = '5N',
  14.     [2]     = '5H',
  15.     [3]     = '10',
  16.     [4]     = '25',
  17.     [5]     = '10H',
  18.     [6]     = '25H',
  19.     [7]     = 'LFR',
  20.     [8]     = 'M+',
  21.     [9]     = '40',
  22.     [11]    = 'HS',
  23.     [12]    = 'NS',
  24.     [14]    = 'N',
  25.     [15]    = 'H',
  26.     [16]    = 'M',
  27.     [17]    = 'LFR',
  28.     [23]    = '5M',
  29.     [24]    = 'TW',
  30.     [33]    = 'TW',
  31.     [38]    = 'N',
  32.     [39]    = 'H',
  33.     [40]    = 'M',
  34.     [147]   = 'WF'
  35. }
  36.  
  37. tMinimapDifficultyTextFrame.text = tMinimapDifficultyTextFrame:CreateFontString(nil, 'OVERLAY')
  38. tMinimapDifficultyTextFrame.text:SetPoint('BOTTOMRIGHT', tMinimapDifficultyTextFrame, 'BOTTOMRIGHT')
  39. tMinimapDifficultyTextFrame.text:SetFont('Interface\\AddOns\\tMinimap\\Font.ttf', 12, 'THINOUTLINE')
  40. tMinimapDifficultyTextFrame.text:SetJustifyH('RIGHT')
  41. tMinimapDifficultyTextFrame.text:SetTextColor(1, 1, 1, 1)
  42. tMinimapDifficultyTextFrame:SetScript('OnEvent', function(self, event, isGuildGroup)
  43.     local _, _, instanceDifficulty, _, _, _, _, _, numPlayers = GetInstanceInfo()
  44.     local mythicPlusDifficulty = C_ChallengeMode.GetActiveKeystoneInfo() or ''
  45.     local text = instanceDifficultyTable[instanceDifficulty] or ''
  46.  
  47.     if (isGuildGroup and type(isGuildGroup) == boolean) then --this argument can be a number when you start mythic plus for some reason
  48.         text = 'G'..text
  49.     end
  50.  
  51.     if numPlayers < 6 then
  52.         numPlayers = ''
  53.     end
  54.  
  55.     if mythicPlusDifficulty < 1 then
  56.         mythicPlusDifficulty = ''
  57.     end
  58.  
  59.     if IsInInstance() then --hack to fix a weird bug where if you get to your WoD garrison, it says you're in in a 5N zone, but also says that all of shadowmoon/frostfire ridge is also a 5N zone until you leave that zone; this is probably related to garrison invasions
  60.         tMinimapDifficultyTextFrame.text:SetText(text..numPlayers..mythicPlusDifficulty)
  61.         tMinimapDifficultyTextFrame.text:Show()
  62.     else
  63.         tMinimapDifficultyTextFrame.text:Hide()
  64.     end
  65. end)
  Reply With Quote
10-26-18, 06:11 PM   #3
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 949
Thanks! I thought PEW might work as well, which nicely covers if someone crashes during an instance and zones back in.
  Reply With Quote
10-27-18, 11:47 AM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,557
PEW fires whenever you see a loading screen.
__________________
"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

WoWInterface » Developer Discussions » Lua/XML Help » Is this the correct event for instances?

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