WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Summon Random Favorite Mount [Improved] (https://www.wowinterface.com/forums/showthread.php?t=57111)

Nightness 04-15-19 07:33 PM

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



All times are GMT -6. The time now is 12:04 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI