View Single Post
11-21-20, 01:23 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
I suspect you're trying to do two different things that need different approaches

Updating the menu requires the Blizzard Collection addon to be loaded so that needs to be tracked.

If you're not hooking the summon function until the collection is loaded then any call to summon won't have your "extra" bits until the Collections have been loaded (either by opened the collection UI or loading the addon yourself).

This will require you to track ADDON_LOADED for when the Blizzard Collection loads and update the menu then, but also hook the Summon function when "your" addon loads (as your character is entering the world).

Something like:
(remove the LoadOnDemand and LoadWith lines from the .toc if you have them)
Lua Code:
  1. DMU = {
  2.     MaxSourceFilters = 10,
  3.     MountGroundExceptions = {},
  4.     MountTypeToTravelType = {},
  5.     ZoneToExpansion = {},
  6.     TravelType = {
  7.         GROUND = 1,
  8.         FLYING = 2,
  9.         SWIMMING = 4,
  10.     },
  11.     Exp = {
  12.        BASE = 0,
  13.        BC = 1,
  14.        WRATH = 2,
  15.        CATA = 3,
  16.        PANDA = 4,
  17.        WOD = 5,
  18.        LEGION = 6,
  19.        BFA = 7,
  20.        SL = 8
  21.     },
  22. }
  23.  
  24. DMU.MountTypeToTravelType = {
  25.     [230] = DMU.TravelType.GROUND,
  26.     [231] = DMU.TravelType.SWIMMING,
  27.     [232] = DMU.TravelType.SWIMMING,
  28.     [241] = DMU.TravelType.GROUND,
  29.     [247] = DMU.TravelType.FLYING,
  30.     [248] = DMU.TravelType.FLYING,
  31.     [254] = DMU.TravelType.SWIMMING,
  32.     [269] = DMU.TravelType.GROUND,
  33.     [284] = DMU.TravelType.GROUND,
  34.     [398] = DMU.TravelType.FLYING
  35. }
  36.  
  37. DMU.ZoneToExpansion = {
  38.     [13]    = DMU.Exp.BASE, --- EasternKingdoms
  39.     [12]    = DMU.Exp.BASE, --- Kalimdor
  40.     [101]   = DMU.Exp.BC,   --- Outland
  41.     [113]   = DMU.Exp.WRATH,    --- Northrend
  42.     [424]   = DMU.Exp.PANDA,    --- Pandaria
  43.     [572]   = DMU.Exp.WOD,  --- Draenor
  44.     [619]   = DMU.Exp.LEGION,   --- BrokenIsles
  45.     [875]   = DMU.Exp.BFA,  --- Zandalar
  46.     [876]   = DMU.Exp.BFA,  --- KulTiras
  47.     [905]   = DMU.Exp.LEGION,   --- Argus
  48.     [948]   = DMU.Exp.CATA, --- TheMaelstrom
  49.     [985]   = DMU.Exp.BASE, --- EasternKingdoms
  50.     [986]   = DMU.Exp.BASE, --- Kalimdor
  51.     [987]   = DMU.Exp.BC,   --- Outland
  52.     [988]   = DMU.Exp.WRATH,    --- Northrend
  53.     [989]   = DMU.Exp.PANDA,    --- Pandaria
  54.     [990]   = DMU.Exp.WOD,  --- Draenor
  55.     [991]   = DMU.Exp.BFA,  --- Zandalar
  56.     [992]   = DMU.Exp.BFA,  --- KulTiras
  57.     [993]   = DMU.Exp.LEGION,   --- BrokenIsles
  58.     [994]   = DMU.Exp.LEGION,   --- Argus
  59.     [1011]  = DMU.Exp.BFA,  --- Zandalar
  60.     [1014]  = DMU.Exp.BFA,  --- KulTiras
  61.     [1208]  = DMU.Exp.BASE, --- EasternKingdoms
  62.     [1209]  = DMU.Exp.BASE, --- Kalimdor
  63.     [1384]  = DMU.Exp.WRATH,    --- Northrend
  64.     [1467]  = DMU.Exp.BC,   --- Outland
  65.     [1504]  = DMU.Exp.BFA,  --- Nazjatar
  66.     [1550]  = DMU.Exp.SL,   --- TheShadowlands
  67.     [1645]  = DMU.Exp.SL,   --- Torghast
  68.     [1647]  = DMU.Exp.SL    --- TheShadowlands
  69. }
  70. --------------------------------- file 2 --------------------------------------------------
  71. local panel = CreateFrame("FRAME")
  72. panel.name = "Draugor's Mount Up"
  73. panel:RegisterEvent("ADDON_LOADED")
  74. InterfaceOptions_AddCategory(panel)
  75. panel:SetScript("OnEvent", function(self, event, arg1)  
  76.     if event == "ADDON_LOADED" and arg1 == "Blizzard_Collections" then  
  77. -- This section loads when the Blizzard Collection does
  78.         local function MenuInt(self, level)
  79.             if not MountJournal.menuMountIndex then return; end
  80.             if C_MountJournal.NeedsFanfare(MountJournal.menuMountID) then return; end
  81.             --- local isFavorite, canFavorite = C_MountJournal.GetIsFavorite(MountJournal.menuMountIndex);
  82.             local mountTypeID = select(5,C_MountJournal.GetMountInfoExtraByID(MountJournal.menuMountID));
  83.             if DMU.MountTypeToTravelType[mountTypeID] == DMU.TravelType.GROUND then return; end
  84.             local info = UIDropDownMenu_CreateInfo();  
  85.             info.text = "Exception";
  86.             info.checked = DMU.MountGroundExceptions[MountJournal.menuMountID];
  87.             info.func = function()
  88.             DMU.MountGroundExceptions[MountJournal.menuMountID] = not DMU.MountGroundExceptions[MountJournal.menuMountID]
  89.             for i,v in pairs(DMU.MountGroundExceptions) do
  90.                 print(i,v)
  91.                 -- printresult = printresult .. tostring(i) .. ": " .. tostring(v) .. "\n"
  92.             end
  93.             end
  94.             UIDropDownMenu_AddButton(info, level)
  95.             MountOptionsMenu_Init(self, level)
  96.         end
  97.         MenuInt(MountJournal, 1)
  98.         UIDropDownMenu_Initialize(MountJournal.mountOptionsMenu, MenuInt, "MENU");
  99. -- This section might need to move to the PLAYER_LOGIN event?
  100.         if DMU.MountGroundExceptions == nil then
  101.             -- This is the first time this addon is loaded; set SVs to default values
  102.             DMU.MountGroundExceptions = {
  103.                 [1011] = true   -- Shu zen
  104.             }
  105.         end
  106.     end
  107. end)
  108.  
  109. -- This section loaded when your addon does (when the character is logging in)
  110. hooksecurefunc(C_MountJournal, "SummonByID", function(summonID)
  111.     print("Mount Up !", summonID)
  112.     if summonID == 0 then
  113.         C_MountJournal.Dismiss() -- Cancel the current random summon
  114.         DMU.MountUp ();
  115.     end
  116.  end)
  117.  
  118.  
  119.  DMU.MountUp = function()
  120.  --- deactivate all filters
  121.  
  122.  local tmp_filter1 = C_MountJournal.GetCollectedFilterSetting(1)
  123.  local tmp_filter2 = C_MountJournal.GetCollectedFilterSetting(2)
  124.  local SourceSet = {}
  125.  for i = 0, DMU.MaxSourceFilters do
  126.     if C_MountJournal.IsValidSourceFilter(i) then
  127.         SourceSet[i] =  C_MountJournal.IsSourceChecked(i)
  128.     end
  129.  end
  130.  
  131.  C_MountJournal.SetSearch("")
  132.  C_MountJournal.SetAllSourceFilters(true)
  133.  C_MountJournal.SetCollectedFilterSetting(1, true)
  134.  C_MountJournal.SetCollectedFilterSetting(2, false)
  135.  
  136. --- C_MountJournal.SummonByID(0)
  137. --- /script print(IsSpellKnown(233368))
  138. --- /script cn, si, i, a, iu, st, iF, iFS, f, hoc, iC, mi =C_MountJournal.GetDisplayedMountInfo(1) print(mi)
  139. --- /script a,b,c,d,mountTypeID,e,f,g,h = C_MountJournal.GetDisplayedMountInfoExtra(1) print(mountTypeID)
  140. --- /script print(C_Map.GetMapInfo(C_Map.GetBestMapForUnit("player")))
  141.  
  142. ---1011 --- Shu zen
  143.  
  144.     local canFlyAtAll = IsSpellKnown(90265) or IsSpellKnown(34090) or IsSpellKnown(34091)
  145.     local canFlyInArea = IsFlyableArea()
  146.  
  147.  
  148.     local underWater = IsSubmerged()
  149.     local summonType = DMU.TravelType.FLYING
  150.     if not(canFlyInArea) then
  151.         summonType = DMU.TravelType.GROUND
  152.     elseif underWater then
  153.         summonType = DMU.TravelType.SWIMMING
  154.     else
  155.         local currentZoneID = C_Map.GetBestMapForUnit("player")
  156.         local currentZoneInfo = C_Map.GetMapInfo(currentZoneID)  
  157.         while currentZoneInfo.mapType > 2 do
  158.             currentZoneID = currentZoneInfo.parentMapID
  159.             currentZoneInfo = C_Map.GetMapInfo(currentZoneID)
  160.         end
  161.         if  currentZoneInfo.mapType == 2 then
  162.             local currentExpansion = DMU.ZoneToExpansion[currentZoneID]
  163.             local canFlyBFA = IsSpellKnown(278833) and canFlyAtAll
  164.             -- local canFlySL = IsSpellKnown(278833)// ToDo Spell ID
  165.             if ((currentExpansion == DMU.Exp.BFA) and not(canFlyBFA)) or (currentExpansion == DMU.Exp.SL ) or false then
  166.                 summonType = DMU.TravelType.GROUND
  167.             else
  168.                 if(canFlyAtAll and canFlyInArea) then
  169.                     summonType = DMU.TravelType.FLYING
  170.                 else
  171.                     summonType = DMU.TravelType.GROUND
  172.                 end
  173.             end
  174.         end
  175.     end
  176.     local summonID = 0
  177.         local ids = {}
  178.         local counter = 0
  179.         local numMounts = C_MountJournal.GetNumDisplayedMounts()
  180.         for i= 1, numMounts do
  181.             local name, spellID, icon, isActive, isUsable, sourceType, isFavorite, isFactionSpecific, faction, shouldHideOnChar, isCollected, mountID = C_MountJournal.GetDisplayedMountInfo(i)
  182.             if isUsable and isFavorite then
  183.                 local mountTypeID = select(5,C_MountJournal.GetMountInfoExtraByID(mountID))
  184.                 if (summonType == DMU.MountTypeToTravelType[mountTypeID]) or (DMU.MountGroundExceptions[mountID] and (summonType ~= DMU.TravelType.SWIMMING)) then
  185.                     print(summonType, DMU.MountGroundExceptions[mountID], DMU.MountTypeToTravelType[mountTypeID])
  186.                     table.insert(ids, mountID)
  187.                     counter = counter + 1
  188.                 end
  189.                
  190.             end
  191.         end
  192.        
  193.  
  194.         if counter>0 then
  195.             local rand = random(counter)
  196.             summonID = ids[rand]
  197.         end
  198.     if IsMounted() then
  199.         Dismount()
  200.     end
  201.  
  202.     for i = 0, DMU.MaxSourceFilters do
  203.         if C_MountJournal.IsValidSourceFilter(i) then
  204.             C_MountJournal.SetSourceFilter(i, SourceSet[i])
  205.         end
  206.     end
  207.     C_MountJournal.SetCollectedFilterSetting(1, tmp_filter1)
  208.     C_MountJournal.SetCollectedFilterSetting(2, tmp_filter2)
  209.     C_MountJournal.SummonByID(summonID)
  210. end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 11-22-20 at 12:57 AM.
  Reply With Quote