View Single Post
10-26-18, 05:34 PM   #2
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
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