如何捕捉瞬间或施放咒语的事件?
How to catch the event of a instant or casting spell?
我正在尝试实现一个脚本,当我的角色施放某个咒语时捕捉,例如 Chaos Bolt which has casting time or a Shadow Word: Pain(即时施法)。搜索我找到了 "channeling" 事件,但我还不太明白。
我希望在角色施放特定咒语时触发自定义消息或播放音频。
UNIT_SPELLCAST_SENT: "unit", "target", "castGUID", spellID
UNIT_SPELLCAST_SUCCEEDED: "target", "castGUID", spellID
每个施法者都有一个唯一的 castGUID。它是在您使用 UNIT_SPELLCAST_SENT 开始投射时创建的,它出现在 cast/channel 的末尾或立即出现在 UNIT_SPELLCAST_SUCCEEDED.
中
所以每当 unit == "player" 时,只需记录 castGUID 然后寻找用它完成的法术相同的值。这就是你如何知道这不是别人的咒语。
同时,您可以查询每个法术对应的法术ID。在下面的示例中,我使用了您 post 中的两个(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.
我正在尝试实现一个脚本,当我的角色施放某个咒语时捕捉,例如 Chaos Bolt which has casting time or a Shadow Word: Pain(即时施法)。搜索我找到了 "channeling" 事件,但我还不太明白。
我希望在角色施放特定咒语时触发自定义消息或播放音频。
UNIT_SPELLCAST_SENT: "unit", "target", "castGUID", spellID
UNIT_SPELLCAST_SUCCEEDED: "target", "castGUID", spellID
每个施法者都有一个唯一的 castGUID。它是在您使用 UNIT_SPELLCAST_SENT 开始投射时创建的,它出现在 cast/channel 的末尾或立即出现在 UNIT_SPELLCAST_SUCCEEDED.
中所以每当 unit == "player" 时,只需记录 castGUID 然后寻找用它完成的法术相同的值。这就是你如何知道这不是别人的咒语。
同时,您可以查询每个法术对应的法术ID。在下面的示例中,我使用了您 post 中的两个(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.