【问题标题】:How to catch the event of a instant or casting spell?如何捕捉瞬间或施法事件?
【发布时间】:2020-03-04 09:40:21
【问题描述】:

我正在尝试实现一个脚本,当我的角色施放某种咒语时捕捉到,例如具有施法时间的 Chaos BoltShadow Word: Pain(即时施法)。搜索我发现了“通灵”事件,但我还不太明白。

我希望在角色施放特定咒语时触发自定义消息或播放音频。

【问题讨论】:

    标签: lua add-on world-of-warcraft


    【解决方案1】:

    UNIT_SPELLCAST_SENT: "单位", "目标", "castGUID", spellID"

    UNIT_SPELLCAST_SUCCEEDED: "target", "castGUID", spellID

    每个施法者都有一个独特的castGUID。它是在您开始使用 UNIT_SPELLCAST_SENT 施法时创建的,它出现在施法/频道的末尾或立即出现在 UNIT_SPELLCAST_SUCCEEDED 中。

    因此,每当 unit == "player" 时,只需记录 castGUID,然后查找以相同值完成的咒语。这样你就知道这不是别人的咒语。

    同时,您可以查找每个法术对应的spellID。在下面的示例中,我使用了您帖子中的两个(196670 和 589)。

    local myFrame = CreateFrame("Frame");
    local myCurrentCast;
    myFrame:RegisterEvent("UNIT_SPELLCAST_SENT");
    myFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
    myFrame:SetScript("OnEvent",
        function(self, event, arg1, arg2, arg3, arg4)
            if (event == "UNIT_SPELLCAST_SENT" and arg1 == "player") then
                print("I am casting something");
                myCurrentCast = arg3;
            elseif (event == "UNIT_SPELLCAST_SUCCEEDED" and arg2 == myCurrentCast) then
                if (arg3 == 196670) then
                    print("I just finished casting Chaos Bolt!");
                elseif (arg3 == 589) then
                    print("Look at my instant Shadow Word: Pain.  Isn't it cool?");
                end
            end
        end
    );
    

    此示例创建一个框架,注册两个事件,然后创建一个事件处理程序以在您施放两个示例咒语时打印出精美的文本。对于事件处理程序的教程,我推荐Wowpedia/Handling_events

    【讨论】:

    • 非常感谢您的解释,我只是有疑问,哪个参数对应于什么? arg1 = 单位 arg2 = 目标 arg3 = castGUID arg4 = spellID 是这个吗?您是从哪里验证 "player" 的?是不是像 and self == "player") 那么
    • @ImNightShadow 它记录在 Dahk 链接的 wiki 中,例如:wow.gamepedia.com/UNIT_SPELLCAST_SUCCEEDED,在这里逐个复制可能有点太多了。我假设此处示例中的and "player" 部分不完整,在这种情况下实际上什么都不做。
    • 已纠正错字。它应该读取 arg1 == "player"。 @ImNightShadow - 你是正确的,参数是 UNIT_SPELLCAST_SENT 事件的顺序。请注意它与 UNIT_SPELLCAST_SUCCEEDED 不同,这就是我链接两者的原因。
    猜你喜欢
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    相关资源
    最近更新 更多