Thread Tools Display Modes
04-15-19, 07:33 PM   #1
Nightness
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Feb 2009
Posts: 32
Summon Random Favorite Mount [Improved]

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

Last edited by Nightness : 04-16-19 at 02:41 AM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Summon Random Favorite Mount [Improved]

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