azerothcore / mod-eluna

Eluna Lua Engine © for WoW Emulators
https://elunaluaengine.github.io/
GNU General Public License v3.0
96 stars 126 forks source link

Add Spell:GetReagentCost() function #165

Closed 3ster closed 6 months ago

3ster commented 7 months ago

Returns a table containing the reagent cost of the spell in the format

reagents = {
    [ItemTemplate] = amount,
    [ItemTemplate] = amount,
    ...
}

Example usage:

local function OnSpellCast(_, player, spell, _)
    local reagents = spell:GetReagentCost()
    player:SendBroadcastMessage("You just cast " .. spell:GetEntry() .. " with the following reagents:")
    for reagent, count in pairs(reagents) do
        player:SendBroadcastMessage(string.format("%d x %s", count, reagent:GetName()))
    end
    return false
end

RegisterPlayerEvent(PLAYER_EVENT_ON_SPELL_CAST, OnSpellCast)