I have created these global functions for my addon. "SummonRandomFavoriteMount()" has one difference from "C_MountJournal.SummonByID(0)"... Instead of only dismounting, if mounted (normal for that button); my function will dismount and mount the new mount in one command. I thought this might help others.
Also does anyone know of a good way to load an addon, followed by code execution involving that addon? That would be a nice tweak to this.
Edit: If this fails it's because the random mount chosen is the current mount.
Code:
-- Call after Blizzard's addon "Blizzard_Collections" is loaded
MountJournalSummonRandomFavoriteButton:SetScript("OnClick", SummonRandomFavoriteMount);
Code:
function GetOneFavoriteMount()
local mountIdTable = C_MountJournal.GetMountIDs();
local results = { };
for idx = 1, #mountIdTable, 1 do
local mountId = mountIdTable[idx];
local _, _, _, _, isUsable, _, isFavorite = C_MountJournal.GetMountInfoByID(mountId)
if (mountId and isFavorite and isUsable) then
table.insert(results, mountId);
end
end
if (#results > 0) then
local rand = results[math.random(1, #results)];
return C_MountJournal.GetMountInfoByID(rand);
end
end
function SummonRandomFavoriteMount()
local _, _, _, _, _, _, _, _, _, _, _, mountId = GetOneFavoriteMount();
C_MountJournal.SummonByID(mountId);
end