WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Mount drop message & sound (https://www.wowinterface.com/forums/showthread.php?t=52781)

ramzax 09-30-15 09:40 AM

Mount drop message & sound
 
Hello, I'm trying to make an addon to announce when a rare mount drops, since I almost never pay attention when looting the corpses and I'm using a fast loot addon so I don't see the loot window.

Code:

-- Mount drop message & sound

local mounts = {
        [71665] = true,                -- Flametalon of Alysrazor
        [69224] = true,                -- Smoldering Egg of Millagazor
        [68824] = true,                -- Swift Zulian Panther
        [43959] = true,                -- Grand Black War Mammoth
        [63041] = true,                -- Drake of the South Wind
        [78919] = true,                -- Experiment 12-B
        [77067] = true,                -- Blazing Drake
        [77069] = true,                -- Life-Binder's Handmaiden
        [50818] = true,                -- Invincible
        [45693] = true                -- Mimiron's Head
}

local function OnEvent(self, event, ...)
        for i = 0, GetNumLootItems(), 1 do
                local _, mountID = C_MountJournal.GetMountInfo(i)
                    if mounts[mountID] then
                            SendChatMessage("Mount dropped!", RAID_WARNING)
                            PlaySoundFile("Sound\\Creature\\Ragnaros\\RagnarosSpecialAttack01.wav")
                    end
    end
end

local mountDrop = CreateFrame("Frame")
mountDrop:RegisterEvent("LOOT_OPENED")
mountDrop:SetScript("OnEvent", OnEvent)
mountDrop:UnregisterEvent("LOOT_OPENED")


Lombra 09-30-15 10:28 AM

You didn't mention what the problem was! But I'm guessing that the mount ID returned from C_MountJournal.GetMountInfo is not the same as the item ID.

semlar 09-30-15 12:44 PM

Quote:

Originally Posted by Lombra (Post 311248)
I'm guessing that the mount ID returned from C_MountJournal.GetMountInfo is not the same as the item ID.

He's not even getting the item id, he's just making a loop from 0 to GetNumLootItems and calling C_MountJournal.GetMountInfo on the iteration.

The loop should be starting at 1, not 0.

You can get the hyperlink for the item in the loot window via GetLootSlotLink(i), pull the item ID out of that with strsplit(':', link) or something and compare them to a table of item IDs for the mounts.

The event is also being unregistered, so the OnEvent script is never going to run.

Phanx 10-02-15 05:29 AM

There's no way to get item IDs from the mount journal. C_MountJournal.GetMountInfo takes an index (eg. 1 is the 1st mount listed, 52 is that 52nd mount listed, and so on), not an itemID, item name, mount name, or loot slot index (which is what you're passing it). Searching by name would not be effective either, since many mount items have different names than the mounts they teach.

It would be way more efficient to just check if any mount dropped. Are there even any mounts that drop from mobs that aren't rare?

lua Code:
  1. local c = { r = 1, g = 1, b = 1 } -- change values to use some color other than white
  2.  
  3. local f = CreateFrame("Frame")
  4. f:RegisterEvent("LOOT_OPENED")
  5. f:SetScript("OnEvent", function()
  6.     for i = 1, GetNumLootItems() do
  7.         local link = GetLootSlotLink(i)
  8.         local _, _, _, _, _, _, subtype, _, _, icon = GetItemInfo(link)
  9.         if subtype == "Mount" then -- change if you're not playing in English
  10.             PlaySoundFile("Sound\\Creature\\Ragnaros\\RagnarosSpecialAttack01.wav")
  11.             RaidNotice_AddMessage(RaidWarningFrame, "|T"..icon..":0|t "..link.." mount dropped!", c)
  12.             return -- no need to keep looking
  13.         end
  14.     end
  15. end)


All times are GMT -6. The time now is 11:02 AM.

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