Thread Tools Display Modes
06-14-14, 10:21 PM   #1
Kriag
A Kobold Labourer
Join Date: Jun 2014
Posts: 1
Bit confused about a event...

Its been a long time since I made addons (since tbc) and now I am at a loss on things, at the moment making a small addon for a friend that keeps logs of what he does or casts...For some reason I cannot think of a way for the addon to check if player is casting hearthstone and to logg it :/ Trying to add a small ding sound during 1/2 way of cast of it which then logs the point at the chime....what is the simplest way to check if player is channeling the hearthstone? :s Does it involve UNIT_SPELLCAST_CHANNEL_START or is it something completely different? And how would I use it as a example? :/
  Reply With Quote
06-14-14, 11:24 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
This will play a sound file halfway through the cast, I don't know how you want to log it but you can insert the entry into a saved variables table to track it across sessions.
Lua Code:
  1. local f = CreateFrame('frame')
  2. f:Hide()
  3.  
  4. f:SetScript('OnUpdate', function(self, elapsed)
  5.     local name, _, _, _, startTime, endTime = UnitCastingInfo('player')
  6.     if name == 'Hearthstone' then
  7.         if GetTime() >= (startTime + endTime) / 2000 then
  8.             PlaySoundFile([[Sound\spells\SimonGame_Visual_GameTick.ogg]], 'Master')
  9.             print('half-done')
  10.             self:Hide()
  11.         end
  12.     else
  13.         self:Hide()
  14.     end
  15. end)
  16.  
  17. f:SetScript('OnEvent', function(self, event, unit, spellName, _, _, spellID)
  18.     self:SetShown(spellName == 'Hearthstone' and event == 'UNIT_SPELLCAST_START')
  19. end)
  20. f:RegisterUnitEvent('UNIT_SPELLCAST_START', 'player')
  21. f:RegisterUnitEvent('UNIT_SPELLCAST_STOP', 'player')
Basically when you start casting and the spell name is 'Hearthstone' it shows the frame which enables the OnUpdate script which runs every frame until the cast is halfway finished and hides itself.

Last edited by semlar : 06-14-14 at 11:29 PM.
  Reply With Quote
06-15-14, 04:34 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Rather than calling the same function to get the same values over and over in every OnUpdate, I'd get those values and calculate the halfway point just once, in your event handler, and then use the elapsed value passed to your OnUpdate script.

I'd also suggest using the spell ID, rather than the spell name; if you and your friend are the only people who will ever use the addon, it doesn't really matter, but if you plan to write any addons for the public, it's better to get in the habit of using locale-independent IDs now, so you don't have to un-learn bad habits later.

Code:
local f = CreateFrame('Frame')
f:Hide()

local countdown

f:SetScript('OnUpdate', function(self, elapsed)
	countdown = countdown - elapsed
	if countdown <= 0 then
		PlaySoundFile([[Sound\spells\SimonGame_Visual_GameTick.ogg]], 'Master')
		print('half-done')
		self:Hide()
	end
end)

f:SetScript('OnEvent', function(self, event, unit, spellName, _, _, spellID)
	if event == 'UNIT_SPELLCAST_START' and spellID == 8690 then
		local _, _, _, _, startTime, endTime = UnitCastingInfo('player')
		countdown = (endTime - startTime) / 2000
		return self:Show()
	end
	self:Hide()
end)

f:RegisterUnitEvent('UNIT_SPELLCAST_START', 'player')
f:RegisterUnitEvent('UNIT_SPELLCAST_STOP', 'player')
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 06-16-14 at 04:14 PM.
  Reply With Quote
06-15-14, 04:54 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Start and end times from UnitCastingInfo are in milliseconds, so you'll need to divide by 2000 instead of 2 to be compatible with OnUpdate's elapsed.

I only put the redundant code in OnUpdate because I wasn't sure how reliable the events were.

Cast time can also change mid-cast due to pushback, and while that isn't a problem for the hearthstone, I got the impression that they intended to track other spells as well.

Last edited by semlar : 06-15-14 at 05:16 PM.
  Reply With Quote
06-16-14, 04:15 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by semlar View Post
I only put the redundant code in OnUpdate because I wasn't sure how reliable the events were.
The values returned by UnitCastingInfo are up to date when UNIT_SPELLCAST_START fires. The event doesn't provide any information about the cast time, so addons and the default UI use the values from the API to show cast bars.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Bit confused about a event...


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