Thread Tools Display Modes
05-19-24, 12:50 PM   #1
Emasym
A Murloc Raider
Join Date: Dec 2006
Posts: 5
[Cata] C_MountJournal.SummonByID

Code:
print("Summoning Mount: " .. companion.name .. " " .. companion.id)
C_MountJournal.SummonByID(companion.id)


Hello!

Anyone have any idea by C_MountJournal.SummonById randomly summons Swift Gray Ram even though that's totally not the argument it's getting?

Happens truly sporadically and I can't make sense of it
  Reply With Quote
05-19-24, 03:02 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,953
Where is your companion info coming from ?

Is companion.id the mountID ?

My dragonriding addon had no issues using SummonByID so unless something has messed up since then, maybe you are using the wrong id, or using it or getting the info at the wrong time ?
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
05-19-24, 03:51 PM   #3
Emasym
A Murloc Raider
Join Date: Dec 2006
Posts: 5
I'm ghetto-updating an existing addon from WotLK so it's possible something goes amiss.

Code:
local mountIDs = C_MountJournal.GetMountIDs()
for i, mountID in ipairs(mountIDs) do
   local name, spellId, _, _, _, _, _, _, faction, hideOnChar, isCollected = C_MountJournal.GetMountInfoByID(mountID)
   if (isCollected and hideOnChar ~= true) then
      if faction == nil then
         faction = playerFaction
      end
      if faction == playerFaction then
         needsCacheUpdate = needsCacheUpdate or (name == nil)
         local info = MountSpellIds[spellId]
         if info ~= nil then
            local creatureId = C_MountJournal.GetMountInfoExtraByID(mountID) or 0
            local e = {name = name, spellId = spellId, id = mountID, type = info, creatureId = creatureId}
            table.insert(allMounts, e)
         end
      end
   end
end
Later their ids get normalised to spellID
(I've added prints here and it doesn't ever seem to do anything)
Code:
for k, v in pairs(self.allMounts) do
   if v.spellId == spellId and v.id ~= i then
      v.id = i
      break
   end
end
While it's possible Ids get retrieved / stored incorrectly, the bug happen utterly at random, with different expected mounts each time.

Every now and then it will just randomly decide "we're not doing this mount - we're doing the ram instead".
It is not populated in the table.

In the below screenshot, after doing the blue dragonhawk correctly a couple of times, suddenly it's the ram again.
The table only gets modified on load.


Code:
/script C_MountJournal.SummonByID(291)
This will always pull out the Blue Dragonhawk and I can't get it to bug

"MountSpellIds" is a local hardcoded list of mounts and their ids, all mounts are present and while shitty code it shouldn't affect this.

Last edited by Emasym : 05-19-24 at 04:03 PM.
  Reply With Quote
05-19-24, 05:34 PM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,953
What is i in this block of code ?
Where did you put the print statements and are you saying they didn't show ? Or didn't show anything unexpected ?
What version of wow are you using this in ? In case that is a factor.

Lua Code:
  1. for k, v in pairs(self.allMounts) do
  2.    if v.spellId == spellId and v.id ~= i then
  3.       v.id = i
  4.       break
  5.    end
  6. end

The reason why I ask is because if this is a step between setting up the table and using the table it might be setting the id to the wrong value.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 05-19-24 at 05:41 PM.
  Reply With Quote
05-19-24, 06:34 PM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,953
As an example.. my Dragonflight Mount addon calls the below function once on PLAYER_LOGIN
I've made an adjustment for testing purposes to see whether there is a problem with other mounts.
But, adding valid mounts to the list for use in the random mount selection criteria part of my addon consistently summoned the right mount.

The only difference between mine and yours is that you are making changes to the mountID for some reason ( see my previous response ). Depending on what your addon is aimed to do, is whether it needs to change it.


Lua Code:
  1. local function BuildDynamicFlightMountsList()
  2.    
  3.     local mountIDs = C_MountJournal.GetMountIDs()
  4.     --local mountIDs = C_MountJournal.GetCollectedDragonridingMounts()
  5.     local englishFaction, localizedFaction = UnitFactionGroup("player")
  6.     addonNS.mountList = {}
  7.    
  8.     for i,v in ipairs(mountIDs) do
  9.         local name, spellID, icon, isActive, isUsable, sourceType, isFavorite, isFactionSpecific, faction, shouldHideOnChar, isCollected, mountID, isForDragonriding = C_MountJournal.GetMountInfoByID(v)
  10.  
  11.         local isWrongFaction = isFactionSpecific and ( faction ~= englishFaction)
  12.        
  13.         if isCollected and (not isWrongFaction) and isUsable then
  14.        
  15.             table.insert(addonNS.mountList,
  16.             {
  17.                 ["index"] = i,
  18.                 ["mountID"] = mountID,
  19.                 ["name"] = name,
  20.                 ["spellID"] = spellID,
  21.                 ["icon"] = icon,
  22.                 ["isActive"] = isActive,
  23.                 ["isUsable"] = isUsable,
  24.                 ["isCollected"] = isCollected,
  25.                 ["isForDragonriding"] = isForDragonriding,
  26.             })
  27.         end
  28.     end
  29.    
  30. end
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
05-20-24, 02:19 AM   #6
Emasym
A Murloc Raider
Join Date: Dec 2006
Posts: 5
Thank you very much for your replies.

The full code for the "updating id" thing and where i comes from:
Code:
for i = 1, GetNumCompanions("MOUNT") do
local _, name, spellId = GetCompanionInfo("MOUNT", i)
However, I've commented out every part of this code and the behavior is still the same.

The print() statements I added that didn't fire where right before setting
Code:
v.id = i
Which lead me to believe this part didn't do anything, anyway.

I've made a pastebin of the complete lua file
https://pastebin.com/b5iiDhbQ
  Reply With Quote
05-20-24, 06:21 AM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,953
Looking at the code it looks like this was written for the original Wrath of the Lich King. So, it is possible that some of the functionality is silently failing in the current versions of wow at the moment.

I couldn't test it fully as half the code doesn't execute because it is behind a custom frame ( likely in an xml file ).

Summonning a random pet worked fine ( if it was supposed to ignore the ones I had favourited in the blizzard pet journal).


Which version of wow are you using this on ?

Classic Era
Classic Cata
Retail Dragonflight

Seeing as a fair bunch of the API in Classic Cata is from Dragonflight, you might find it easier to rethink the project based on what is currently available in the game and API and add what's missing. Especially seeing as it looks like it was created before Blizzard added the PetJournal and MountJournal in game themselves.

For example: You might be able to utilise ( https://warcraft.wiki.gg/wiki/API_C_....SetTypeFilter ) to automatically filter specific types of mounts to generate a list that way. I did try to test this in my dragonriding addon but ended up breaking it in a different area for some reason. So might have to rig up a blank addon for that purpose.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
05-20-24, 07:16 AM   #8
Emasym
A Murloc Raider
Join Date: Dec 2006
Posts: 5
It was fully functional on wotlk classic (and does feature a couple "ifs" regarding game version).
I'm now attempting to use it on Cata classic (which, as you mentioned, should use the DF API). And it works! Except for the occassional ram!

The most striking thing to me is how I can fully print that the info is correct and well received, and the next thing is a wow lua api call using the printed argument, yet the result is inconsistent.
No amount of faulty code should cause this to happen, and it's really stumping me on a low-level level.
(Mind you, good point about using more C_MountJournal functionality, it definitely should).

Thank you very much for testing and helping so in depth.
If you're curious as well, and it's clear you have a better view of this than I have, I've uploaded the addon in its entirety (lua, xml, toc) on wetransfer https://we.tl/t-Rzci8I2wB9 .

The key of this, to me, is still in where it goes wrong in:
Code:
function RandomMount_SummonMount(companion)
   print("Summoning Mount: " .. companion.name .. " " .. companion.id)
   C_MountJournal.SummonByID(companion.id)
end
The printing is fine and consistent, but the SummonById is not.

Again, thank you very much for giving this your time. I'm aware there's potentially up-to-date addons out there that will do the same thing, and will do it without throwing a ram in there, but I'm still simply curious.

EDIT: I'm testing further, without the `UpdateCompanionIds` called, Violet Netherwing Drake does get id 95, and SummonByID(95) ís the ram. So you're correct that it's entirely possible it's fetching wrong info at some point. Argh!

EDIT2: I threw out Violet Netherwing Drake from my addon "favourites" and now it seems fine. Must be a data mismatch between wotlk & cata. I see the addon scans current list of mounts by number, and it's entirely possible the logic is screwed somewhere.
Again, thank you very much for your help.
Instead of an addon, I'll simply resort to C_MountJournal.SummonByID(0) :-)

Last edited by Emasym : 05-20-24 at 07:31 AM.
  Reply With Quote
05-20-24, 08:38 AM   #9
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,953
I'm giving the new functions a test ( never used them before ) but it seems like you can adjust the filters programmatically and then generate a list based on that ( probably best to see if you can store the players setup before doing so for public use ).

So, instead of a hard coded list, you might be able to generate a list based on type ( ground, flying, aquatic, dragonriding ) which you could then use in conjunction with the environment the player is in, at the time of summoning.

For quick access to the main api for the mount journal ( https://warcraft.wiki.gg/wiki/World_...#Mount_Journal )


But yes, it is quite annoying, but, maybe the issue is perhaps the hardcoded list has been slowly getting out of date so to speak.


There are two events which may be of use :
MOUNT_JOURNAL_USABILITY_CHANGED
MOUNT_JOURNAL_SEARCH_UPDATED

The first one triggers at least on login
The second one triggers every time you adjust the filters ( either manually or automatically ).

But .. I ended up not using those events... At player login I just filtered the journal and generated a filtered list of mounts and filled the appropriate table with the info I wanted.

Feel free to grab, test and utilise as needed

Lua Code:
  1. local function GenerateMountLists()
  2.    
  3.     C_MountJournal.SetAllSourceFilters(true)
  4.     C_MountJournal.SetAllTypeFilters(false)
  5.     C_MountJournal.SetCollectedFilterSetting(1, true) -- Collected
  6.     C_MountJournal.SetCollectedFilterSetting(2, true) -- Not Collected
  7.     C_MountJournal.SetCollectedFilterSetting(3, false) -- Unusable - setting this to false will remove the mounts that are for a different class/faction etc
  8.     -- None of these filters will filter out mounts you can't fly in a no fly zone ( because you haven't gained that ability yet in the area etc )
  9.  
  10.     -- Clear Saved Variable Tables used for Testing
  11.     XMount_Flying = {}
  12.     XMount_Ground = {}
  13.     XMount_Dragonriding = {}
  14.     XMount_Aquatic = {}
  15.    
  16.     for i = 1,4 do
  17.        
  18.         -- Set the type filter up
  19.         C_MountJournal.SetTypeFilter(i, true)
  20.        
  21.         -- Get the number of mounts that fit the filter
  22.         local numMounts = C_MountJournal.GetNumDisplayedMounts()
  23.        
  24.         for index = 1, numMounts do
  25.        
  26.             local name, spellID, icon, isActive, isUsable, sourceType, isFavorite, isFactionSpecific, faction, shouldHideOnChar, isCollected, mountID
  27.         = C_MountJournal.GetDisplayedMountInfo(index)
  28.  
  29. -- There might be more return values here including whether it is a dragonriding mount --
  30. -- I forgot to check that when I copied the function in --
  31.            
  32.             if i == 1 then
  33.                 XMount_Ground[mountID] = {
  34.                     ["Name"] = name,
  35.                     ["spellID"] = spellID,                    
  36.                 }
  37.             elseif i == 2 then
  38.                 XMount_Flying[mountID] = {
  39.                     ["Name"] = name,
  40.                     ["spellID"] = spellID,                    
  41.                 }
  42.             elseif i == 3 then
  43.                 XMount_Aquatic[mountID] = {
  44.                     ["Name"] = name,
  45.                     ["spellID"] = spellID,                    
  46.                 }
  47.             elseif i == 4 then
  48.                 XMount_Dragonriding[mountID] = {
  49.                     ["Name"] = name,
  50.                     ["spellID"] = spellID,                    
  51.                 }
  52.             end
  53.         end
  54.        
  55.         C_MountJournal.SetTypeFilter(i, false)
  56.     end
  57.    
  58. end

I didn't use them ( as this is just a fun project ) but, they do have these functions which I assume can be used to grab the various filter settings on login that the user may have set up
Lua Code:
  1. C_MountJournal.GetCollectedFilterSetting(filterIndex)
  2. C_MountJournal.IsSourceChecked(filterIndex)
  3. C_MountJournal.IsTypeChecked(filterIndex)
  4. -- Addon does stuff
  5. C_MountJournal.SetSourceFilter(filterIndex, isChecked)
  6. C_MountJournal.SetTypeFilter(filterIndex, isChecked)
  7. C_MountJournal.SetCollectedFilterSetting(filterIndex, isChecked)

You could check for this first though and use the appropriate setting afterwards and if they are not using the default filters then use the functions above to do the manual gets and sets.
Lua Code:
  1. C_MountJournal.IsUsingDefaultFilters()
  2. --- Addon does stuff
  3. C_MountJournal.SetDefaultFilters()
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 05-20-24 at 10:05 AM.
  Reply With Quote
05-20-24, 08:40 AM   #10
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,953
Yes, the built in one should work fine for what you need. That's the reason why I only created a dragonriding one, because they just wanted a button to randomise their dragonriding mounts instead.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
05-20-24, 10:31 AM   #11
Emasym
A Murloc Raider
Join Date: Dec 2006
Posts: 5
That is genius - thank you very much, very clean code :-)

I've never done an addon from scratch, just tinkering where required / interesting, so thank you very much for pointing me to the right direction.

You've been a scholar and a gentleman, thank you again.
  Reply With Quote
05-20-24, 02:47 PM   #12
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,953
No problem.

It could be a learning curve for you.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » [Cata] C_MountJournal.SummonByID


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