WoW Classic (1.13) 插件事件: COMBAT_TEXT_UPDATE。如何修复我的代码?

我最近开始学习 LUA 和 WoW 的插件。我想在聊天框中显示魔法类型和伤害量,但我的代码不起作用。请看看我哪里做错了。

local Congrats_EventFrame = CreateFrame("Frame")
CombatTextSetActiveUnit("player")
Congrats_EventFrame:RegisterEvent("COMBAT_TEXT_UPDATE")
Congrats_EventFrame:SetScript("OnEvent",
    function(arg1, arg2, arg3)
        print(arg1 .. ' - ' .. arg2 .. ' - ' .. arg3)
    end)
点赞
用户1297035
用户1297035

查看https://wow.gamepedia.com/COMBAT_LOG_EVENT下的SPELL_DAMAGE的“amount”参数。

local playerGUID = UnitGUID("player")
local MSG_SPELL_DAMAGE = "你的 %s(%s)对 %s 造成 %d 伤害!"

local f = CreateFrame("Frame")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
f:SetScript("OnEvent", function(self, event)
    self:OnEvent(event, CombatLogGetCurrentEventInfo())
end)

function f:OnEvent(event, ...)
    local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = ...
    local spellId, spellName, spellSchool
    local amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing, isOffHand

    if subevent == "SPELL_DAMAGE" then
        spellId, spellName, spellSchool, amount = select(12, ...)
    end

    if amount and sourceGUID == playerGUID then
        local spell = spellId and GetSpellLink(spellId)
        print(MSG_SPELL_DAMAGE:format(spell, GetSchoolString(spellSchool), destName, amount))
    end
end

示例

2019-10-11 17:39:50