Thread Tools Display Modes
05-17-09, 07:41 AM   #1
Exawatt
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Feb 2009
Posts: 36
Mounting event

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:
  1. --Determine Correct Mount
  2. local ground, flying
  3. for i=1,GetNumCompanions("MOUNT") do
  4.     local _, creatureName = GetCompanionInfo("MOUNT", i)
  5.     if( creatureName == "Dreadsteed" ) then
  6.         ground = i
  7.     end
  8.     if( creatureName == "Green Wind Rider" ) then
  9.         flying = i
  10.     end
  11. end
  12.  
  13. --Ground Mounting Function
  14. local function MountGround()
  15.     CallCompanion("MOUNT", ground)
  16.     FollowHelper:Hide()
  17. end
  18.  
  19. --Flying Mounting Button
  20. local function MountFlying()
  21.     CallCompanion("MOUNT", flying)
  22.     FollowHelper:Hide()
  23. end
  24.  
  25. --Boolean "Following" flag
  26. local FH_isFollowing = false
  27.  
  28. --Event function
  29. local function FollowHelper_EventHandler(self, event, ...)
  30.     if( event == "UNIT_SPELLCAST_START" and arg1 == "Chillah" ) then
  31.         if( arg2 == "Swift Zhevra" ) then
  32.             mountButton:SetScript("OnClick", MountGround)
  33.             FollowHelper:Show()
  34.         elseif( arg2 == "Blue Wind Rider" ) then
  35.             mountButton:SetScript("OnClick", MountFlying)
  36.             FollowHelper:Show()
  37.         end
  38.  
  39.     elseif( event == "AUTOFOLLOW_BEGIN" and arg1 == "Chillah" ) then
  40.         FH_isFollowing = true
  41.        
  42.     elseif( event == "AUTOFOLLOW_END" ) then
  43.         FH_isFollowing = false
  44.     end
  45. end
  46.  
  47. --Create frames and such
  48. local frame = CreateFrame("Frame", "FollowHelper")
  49. frame:SetFrameStrata("HIGH")
  50. frame:ClearAllPoints()
  51. frame:SetPoint("CENTER", UIParent, "CENTER")
  52. frame:SetWidth(75)
  53. frame:SetHeight(50)
  54. frame:RegisterEvent("UNIT_SPELLCAST_START")
  55. frame:RegisterEvent("AUTOFOLLOW_BEGIN")
  56. frame:RegisterEvent("AUTOFOLLOW_END")
  57. frame:SetScript("OnEvent", FollowHelper_EventHandler)
  58. frame:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
  59.                    edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  60.                    tile = true, tileSize = 16, edgeSize = 16,
  61.                    insets = { left = 4, right = 4, top = 4, bottom = 4 }})
  62.  
  63. --Create "Mount Me!" button
  64. local mountButton = CreateFrame("Button", "FH_MountButton", FollowHelper, "UIPanelButtonTemplate")
  65. mountButton:SetWidth(75)
  66. mountButton:SetHeight(25)
  67. mountButton:ClearAllPoints()
  68. mountButton:SetPoint("TOPLEFT", FollowHelper, "TOPLEFT")
  69. mountButton:SetText("Mount me!")
  70.  
  71. --Create "Do Nothing." button
  72. local cancelButton = CreateFrame("Button", "FH_CancelButton", FollowHelper, "UIPanelButtonTemplate")
  73. cancelButton:SetWidth(75)
  74. cancelButton:SetHeight(25)
  75. cancelButton:ClearAllPoints()
  76. cancelButton:SetPoint("TOPLEFT", FollowHelper, "TOPLEFT", 0, -25)
  77. cancelButton:SetText("Do Nothing.")
  78. cancelButton:SetScript("OnClick", function() FollowHelper:Hide() end)
  Reply With Quote
05-17-09, 08:31 AM   #2
kraftman
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 63
I think all gf's should have a "Mount Me!" button

More seriously though, have you printed arg1 and arg2 to check they are what you think they are? I think the first argument is the unit ("target") rather than the unitname.

Also its better to use the variables passed in ... than the globals.

eg

local arg1, arg2 = ...

Hope this helps!

Last edited by kraftman : 05-17-09 at 10:43 AM.
  Reply With Quote
05-17-09, 09:25 AM   #3
tsadok
An Aku'mai Servant
 
tsadok's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 32
I got my troll a hawkstrider and wanted him to say stuff when he mounted. I registered a frame to all events and got nothing when I mounted, so I suspect there isn't a specific mounting event, strange as that may seem. One thing I didn’t get round to trying was periodically testing for the mount buff (or these days, events).

If it's just between you two, you could attach a script to your mount macro like:

/script SendAddonMessage("Gf&me", "Ground", "WHISPER", "Gfsname")
and her client could pick that up.
  Reply With Quote
05-17-09, 01:26 PM   #4
Exawatt
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Feb 2009
Posts: 36
Originally Posted by kraftman View Post
I think all gf's should have a "Mount Me!" button
It was originally going to say "Ryan is mounting" (then give options to mount), but now I'm going to have it toss in a randomly-occuring message to "Mount Ryan!", just for that gem.

Originally Posted by kraftman View Post
More seriously though, have you printed arg1 and arg2 to check they are what you think they are? I think the first argument is the unit ("target") rather than the unitname.

Also its better to use the variables passed in ... than the globals.
I had it as the variables previously, but it didn't really matter: The addon wasn't hitting that point, since the event wasn't firing (at all) when I mounted up. They were changed as a last resort to get it working

Originally Posted by tsadok View Post
If it's just between you two, you could attach a script to your mount macro like:

/script SendAddonMessage("Gf&me", "Ground", "WHISPER", "Gfsname")
and her client could pick that up.
Didn't think of that, but it makes it work all the same. Thanks.


Though my addon is working now, I'd still like to know why the original didn't work. If anyone could shed some light on the UNIT_SPELLCAST_START and/or UNIT_SPELLCAST_SEND events, that'd be appreciated.

[EDIT] Oh, and if anyone was interested; here's the finished addon (sans my own tweaks):

FollowMounter.lua
Code:
--Settings
local FH_FavGround = "Dreadsteed" --Ground mount to choose
local FH_FavFlying = "Green Wind Rider" --Flying mount to choose

--Determine Correct Mount Positions
local FH_ground, FH_flying
for i=1,GetNumCompanions("MOUNT") do
	local _, creatureName = GetCompanionInfo("MOUNT", i)
	if( creatureName == FH_FavGround ) then
		FH_ground = i
	end
	if( creatureName == FH_FavFlying ) then
		FH_flying = i
	end
end

--Ground Mounting Function
local function FH_MountGround()
	CallCompanion("MOUNT", FH_ground)
	FollowHelper:Hide()
end

--Flying Mounting Function
local function FH_MountFlying()
	CallCompanion("MOUNT", FH_flying)
	FollowHelper:Hide()
end

local FH_isFollowing = false --Boolean "Following" flag
FH_Who = "" --Player you will be following

--Event function
local function FollowHelper_EventHandler(self, event, ...)
	if( event == "CHAT_MSG_ADDON" ) then
		local prefix, message, channel, sender = ...
		if( FH_isFollowing and prefix == "FH" and channel == "WHISPER" and sender == FH_Who ) then
			if( message == "ground" ) then
				--CallCompanion("MOUNT", FH_ground) --uncomment for automount
					--will not work if the person you are following quickly stops moving and mounts,
					--since you will still be moving for a second
				--comment out next two lines for automount
				FH_MountButton:SetScript("OnClick", FH_MountGround)
				FollowHelper:Show()
			elseif( message == "flying" ) then
				--CallCompanion("MOUNT", FH_flying) --uncomment for automount (see note above)
				--comment out next two lines for automount
				FH_MountButton:SetScript("OnClick", FH_MountFlying)
				FollowHelper:Show()
			end
		end
		
	elseif( event == "AUTOFOLLOW_BEGIN" ) then
		FH_Who = (...)
		FH_isFollowing = true
		
	elseif( event == "AUTOFOLLOW_END" ) then
		FH_isFollowing = false
	end
end

--Create frames and such
local f = CreateFrame("Frame", "FollowHelper")
f:SetFrameStrata("HIGH")
f:ClearAllPoints()
f:SetPoint("CENTER", UIParent, "CENTER")
f:SetWidth(85)
f:SetHeight(60)
f:RegisterEvent("CHAT_MSG_ADDON")
f:RegisterEvent("AUTOFOLLOW_BEGIN")
f:RegisterEvent("AUTOFOLLOW_END")
f:SetScript("OnEvent", FollowHelper_EventHandler)
f: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 }})
f:Hide()

--Create "Mount Me!" button
local b = CreateFrame("Button", "FH_MountButton", FollowHelper, "UIPanelButtonTemplate")
b:SetWidth(75)
b:SetHeight(25)
b:ClearAllPoints()
b:SetPoint("TOPLEFT", FollowHelper, "TOPLEFT", 5, -5)
b:SetText("Mount me!")

--Create "Do Nothing." button
b = CreateFrame("Button", "FH_CancelButton", FollowHelper, "UIPanelButtonTemplate")
b:SetWidth(75)
b:SetHeight(25)
b:ClearAllPoints()
b:SetPoint("TOPLEFT", FollowHelper, "TOPLEFT", 5, -30)
b:SetText("Do nothing.")
b:SetScript("OnClick", function() FollowHelper:Hide() end)
The person being followed uses this instead of their normal mounts:
Code:
/script if(not IsMounted()) then CallCompanion("MOUNT", MOUNT_POSITION_INT) SendAddonMessage("FH", ("flying" or "ground"), "WHISPER", ("PERSON_FOLLOWING_YOU") else Dismount() end

Last edited by Exawatt : 05-17-09 at 03:34 PM. Reason: Added completed AddOn
  Reply With Quote
05-17-09, 09:23 PM   #5
tsadok
An Aku'mai Servant
 
tsadok's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 32
I looked at UNIT_SPELLCAST_START and it returned "player" as the first argument when I mounted, so that could be your problem.

Also, using arg1 etc. is deprecated or obsolete. If it still works, arg1 may have been referring to the event frame, and arg3 might have been the unit.
  Reply With Quote
05-17-09, 10:47 PM   #6
Exawatt
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Feb 2009
Posts: 36
Originally Posted by tsadok View Post
I looked at UNIT_SPELLCAST_START and it returned "player" as the first argument when I mounted, so that could be your problem.
I wasn't getting it to fire at all. The code in the first post has another check made on "arg1" in the same if conditional, but it was separate in tests. The main problem was the event wasn't showing up (at all).

I wasn't looking for my own event, though. Rather, character A begins mounting, and character B is waiting for the event to fire.
  Reply With Quote
05-23-09, 11:57 AM   #7
Auren
An Aku'mai Servant
 
Auren's Avatar
Join Date: Sep 2006
Posts: 37
I've been trying to get a code similar to this to work.
I need it to detect when casting a mount on a char thats in my group and tell me.
Sadly I have the same problem as you.
Also cant get the addon you posted to work either
__________________
Rogue [Combat] - 80
Paladin [Protection] - 80
Death Knight [Blood] - 77
Shaman [Elemental] - 77
Mage [Frost] - 76
Priest [Shadow] - 75
Hunter [Beast] - 72
  Reply With Quote
05-23-09, 01:24 PM   #8
Exawatt
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Feb 2009
Posts: 36
Originally Posted by Auren View Post
Also cant get the addon you posted to work either
Well the version I'm using now uses method tsadok proposed. The person mounting up changes their mount action into a macro which includes sending an addon message, then the AddOn frame listens for that message. If you wanted it to work with a group, change a couple of things:

Code:
local function MyAddon_EventHandler(self, event, ...)
  local prefix, message, channel, sender = ...
  if( prefix == "MA" and channel == "PARTY" ) then
    DEFAULT_CHAT_FRAME:AddMessage(sender.." is summoning their "..message.." mount.")
  end
end

local f = CreateFrame("Frame", "MyAddon")
f:RegisterEvent("CHAT_MSG_ADDON")
f:SetScript("OnEvent", MyAddon_EventHandler)
Then have your party members use the following macro instead of their mounts:

Code:
/script if(not IsMounted()) then CallCompanion("MOUNT", %MOUNT_POSITION_INT%) SendAddonMessage("MA", %"flying" or "ground"%, "PARTY") else Dismount() end
That is, if you always play with the same people... Otherwise we're back at square 1.

Maybe the event is busted?
  Reply With Quote
06-04-09, 04:19 AM   #9
Amethyst
A Fallenroot Satyr
 
Amethyst's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 20
Maybe COMPANION_UPDATE might do it? It's new as of 3.0
  Reply With Quote
06-04-09, 12:07 PM   #10
Exawatt
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Feb 2009
Posts: 36
Originally Posted by Amethyst View Post
Maybe COMPANION_UPDATE might do it? It's new as of 3.0
That only has one argument (which only says "MOUNT") and it fires when the mount appears (end of casting), as well as when the mount is unsummoned (but does not differentiate between the two). There's no way to tell the difference between air and ground, or if the other person is mounting or unmounting.

It does seem to always fire, though, which is more than the others have been doing.
  Reply With Quote
06-06-09, 03:00 AM   #11
Crowfeather
A Fallenroot Satyr
 
Crowfeather's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2008
Posts: 28
Originally Posted by Exawatt View Post
That only has one argument (which only says "MOUNT") and it fires when the mount appears (end of casting), as well as when the mount is unsummoned (but does not differentiate between the two). There's no way to tell the difference between air and ground, or if the other person is mounting or unmounting.

It does seem to always fire, though, which is more than the others have been doing.
The problem for me wasn´t that it didn´t always fire (it did for me) but that it doesn´t seem to differentiate between yourself and others (dis)mounting (got spammed with the event in dalaran) and - even more important - it fires before IsMounted() registers the player as beeing mounted. In combination with the lack of knowledge if if fired because someone mounted or dismounted makes the event rather worthless. I solved my problem by just polling IsMounted() at every OnUpdate() which feels rather clumsy. If anyone knows a better solution I´m all ears.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Mounting event

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off