[Skip to Main Content]
此站点大量使用JavaScript。
请在您的浏览器中启用JavaScript。
正式服
PTR
Outfitter Script & Companions
发表回复
返回主列表
发布者
20383
This post was from a user who has deleted their account.
发布者
Wanderingfox
Not sure about #2 since I am not familiar with Outfitter's functions, but #1 could be done by doing something like the following:
-- Create a local frame to hold our events since they're frame driven
-- Note: You could use an already existing/recycled frame for this
local frame = CreateFrame("FRAME", "MyAddonFrame")
-- Register our frame to listen to the unit aura event which fires when a buff/debuff changes
frame:RegisterEvent("UNIT_AURA")
-- Create a function to handle our event
local function eventHandler(self, event, arg1)
-- Grab the information the event is passing to our function
-- arg1 contains the unitID that this specific event refers to
local unitID = arg1
-- Check to see if the event is related to a player buff/debuff
if unitID == "Player" then
-- Check to see if the player has stealth active
if UnitBuff("Player", "Stealth") then
-- Dismiss the non-combat pet
DismissCompanion("CRITTER")
end
end
-- Register our event handler function to the frame
frame:SetScript("OnEvent", eventHandler)
Note
: The above are snippets of very simple
DRY
code, so they probably will not work out of the box. I have, however, documented them (as you can see), so it should be possible to change them based on where and how you intend to use them.
Note 2
: I included the arg1 check for completeness sake, it is not technically required since the conditional is implied by the UnitBuff check on the player. It does, however, reduce the number of calls to UnitBuff by only ever continuing if a player buff/debuff has changed.
Note 3
: I would highly suggest using a framework like Ace to do something like this if you must do it through Lua as Ace can register throttled events (called buckets) that will only fire every X seconds, which will greatly reduce the amount of handler calls.
Edit:
It is probably worth saying that this would be
significantly
easier with a macro. Yes I know you said that you do not have the space for it, but I figured I'd include it anyway.
#showtooltip Stealth
/cast Stealth
/stopmacro
/run DismissCompanion("CRITTER")
发布者
409946
This post was from a user who has deleted their account.
发布者
Wanderingfox
Oh right! Knew I forgot something >_<
Thanks. Fixed the initial code.
发布者
20383
This post was from a user who has deleted their account.
发表回复
您没有登录。请
登录
发表回复或
注册
如果您还没有账号。