My girlfriend and I quest together all the time, and she's quite fond of /follow. This addon I'm making for her is supposed to display a "Mount Me" button when I begin to mount up while she's following me. It also selects the correct mount (i.e. flying or ground). For some reason I can't seem to get the UNIT_SPELLCAST_START to fire, and I can't figure out why. I've tried UNIT_SPELLCAST_SEND as well, with no luck. I do manage to get the UNIT_SPELLCAST_SUCCEEDED event to fire, but it comes three seconds after I want this addon to display itself.
The window displays fine, and the mounts are selected properly. The only problem is the event notification.
lua Code:
--Determine Correct Mount
local ground, flying
for i=1,GetNumCompanions("MOUNT") do
local _, creatureName = GetCompanionInfo("MOUNT", i)
if( creatureName == "Dreadsteed" ) then
ground = i
end
if( creatureName == "Green Wind Rider" ) then
flying = i
end
end
--Ground Mounting Function
local function MountGround()
CallCompanion("MOUNT", ground)
FollowHelper:Hide()
end
--Flying Mounting Button
local function MountFlying()
CallCompanion("MOUNT", flying)
FollowHelper:Hide()
end
--Boolean "Following" flag
local FH_isFollowing = false
--Event function
local function FollowHelper_EventHandler(self, event, ...)
if( event == "UNIT_SPELLCAST_START" and arg1 == "Chillah" ) then
if( arg2 == "Swift Zhevra" ) then
mountButton:SetScript("OnClick", MountGround)
FollowHelper:Show()
elseif( arg2 == "Blue Wind Rider" ) then
mountButton:SetScript("OnClick", MountFlying)
FollowHelper:Show()
end
elseif( event == "AUTOFOLLOW_BEGIN" and arg1 == "Chillah" ) then
FH_isFollowing = true
elseif( event == "AUTOFOLLOW_END" ) then
FH_isFollowing = false
end
end
--Create frames and such
local frame = CreateFrame("Frame", "FollowHelper")
frame:SetFrameStrata("HIGH")
frame:ClearAllPoints()
frame:SetPoint("CENTER", UIParent, "CENTER")
frame:SetWidth(75)
frame:SetHeight(50)
frame:RegisterEvent("UNIT_SPELLCAST_START")
frame:RegisterEvent("AUTOFOLLOW_BEGIN")
frame:RegisterEvent("AUTOFOLLOW_END")
frame:SetScript("OnEvent", FollowHelper_EventHandler)
frame:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }})
--Create "Mount Me!" button
local mountButton = CreateFrame("Button", "FH_MountButton", FollowHelper, "UIPanelButtonTemplate")
mountButton:SetWidth(75)
mountButton:SetHeight(25)
mountButton:ClearAllPoints()
mountButton:SetPoint("TOPLEFT", FollowHelper, "TOPLEFT")
mountButton:SetText("Mount me!")
--Create "Do Nothing." button
local cancelButton = CreateFrame("Button", "FH_CancelButton", FollowHelper, "UIPanelButtonTemplate")
cancelButton:SetWidth(75)
cancelButton:SetHeight(25)
cancelButton:ClearAllPoints()
cancelButton:SetPoint("TOPLEFT", FollowHelper, "TOPLEFT", 0, -25)
cancelButton:SetText("Do Nothing.")
cancelButton:SetScript("OnClick", function() FollowHelper:Hide() end)