Thread Tools Display Modes
08-29-19, 04:14 PM   #1
Motanum
A Murloc Raider
Join Date: Aug 2019
Posts: 5
Question how do I get a spellID from when I mouse over a spell in game?

Hey guys, newbie to addons developing here. So, with wow classic just getting started, and realizing I have to keep track of what rank of spells to use. SO I wrote a CPP project to simply calculate the mana efficiency of my spells. For example, rank 2 of fireball has a stat of 0.9 Damage per Mana, so I know that of all spells I have I should use that to get the most damage out of my mana pool.

But I am super lazy to have to input the values manually into my console application, so I thought, maybe I could make an AddOn that will tell me extra spell stats, like Damage Per Mana, when I simply moiuse over my spells, either from the Action Bar, or from the spellbook. So I thought, that it could be a simple enough project I could proabably make and then expand upon with other info I thought could be usefull.

I started the tutorial Creating WoW AddOns from Mayron, and I got to a stage where I have a simple message window with the name of my addon showing up.



But now I am quite lost as to where to go from here? I figured maybe have some kind of event listener so that when the player mouses over a spell, I could maybe get the SpellID, which then I could have a function check for Min Damage, Max Damage, Mana cost, and just do some math.

So for now, how do I get a spellID from when I mouse over a spell in game?
  Reply With Quote
08-29-19, 06:43 PM   #2
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Try

Lua Code:
  1. GameTooltip:HookScript("OnTooltipSetSpell", function(self)
  2.     local name, id = self:GetSpell()
  3.     if id then
  4.         self:AddLine("    ")
  5.         self:AddLine("ID: " .. tostring(id), 1, 1, 1)
  6.     end
  7. end)
  Reply With Quote
08-30-19, 08:39 AM   #3
Motanum
A Murloc Raider
Join Date: Aug 2019
Posts: 5
Thanks for the reply!

Could you send me or link me instructions on how to use that? Like I said, I only started really learning addon dev 2 days ago. So far, I got progress in getting the spell power cost and min and max damage given a spell ID So your hook seems to be the last bit of the puzzle, but I don't know how to use it.

Thanks so much!
  Reply With Quote
08-30-19, 08:59 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
The code snippet is showing you how you can access the tooltip information on mouseover.

You should be able to just copy that code block into your addon file and whenever you mouseover it should allow you to access that spell's spellID and then do what you need to do within that code block.


Lua Code:
  1. GameTooltip:HookScript("OnTooltipSetSpell", function(self)
  2.     local name, id = self:GetSpell()
  3.     if id then
  4.        -- Work with the spell ID you now have access to
  5.     end
  6. end)
__________________
  Reply With Quote
08-30-19, 05:05 PM   #5
Motanum
A Murloc Raider
Join Date: Aug 2019
Posts: 5
Hi!

Thanks again for the reply! I added your line of code into my addon, and added in the function where you specified. It is compiling properly so that is good, but the issue is that when I mouse over a spell nothing happens. I expect to at least get a print message out into chat for me to see.

Here is the relevant lua file.
https://pastebin.com/W4HWh8dJ

And a screenshot of the game with the chat output from the print messages in the lua file.


And I am using this addon as a base for my own. Where I pretty much only kept my toc file, and only added new stuff (your code snippet) to the init.lua file, which is the one on paste bin.
https://github.com/Mayron/CreatingWo...07/AuraTracker

Cheers!
  Reply With Quote
08-30-19, 05:21 PM   #6
Motanum
A Murloc Raider
Join Date: Aug 2019
Posts: 5
I GOT IT WORKING!



It was an issue with the function calling, I am new to lua and had to add a myFunction(self, SpellID) which I wasn't aware, but I got find by adding print messages here and there.

It outputs to chat at the moment! And the way I got the 2 damage values is by looking for the first 2 damage values in the description, which for some spells, which lack a description will break the code. IS there a way to get the spell min and max damage cleanly? I tried looking at the API but I didn't find anything as obvious as with SpellPowerCost.

Now, I wish to create a frame, or display one that the base AddOnI have already instead of spamming my own chat.
  Reply With Quote
08-30-19, 05:22 PM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
hmm .. (Edit: Nevermind) rofl I'll leave this just in case you hit this problem later

Test the value of ResultString before you leave the function it is set in.

As long as that has a value it should work after it has left the function as ResultString wasn't defined as a local variable.

However, I thought Blizzard had changed how Spell data was accessed, so if ResultString or SpellName and SpellDescription come up with nothing that could be the reason.

What I seemed to see happening is that after a period of time, the spell information was cleared from memory so I made a point of storing what I needed for the addon to work. There is an event I use in one of my addons called "SPELL_DATA_LOAD_RESULT" which I use to store any spell information I need to keep after making a call to C_Spell.RequestLoadSpellData(spellID).
__________________
  Reply With Quote
08-30-19, 05:30 PM   #8
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
As far as I know most people just 'scan' the tooltip information and extract the data it shows that they need. I have never needed to do that so can't help you there.

As to creating a frame this might point you in the right direction.

https://wow.gamepedia.com/HOWTOs

If you haven't been visiting that site for your wowapi information you may find it useful overall.
__________________
  Reply With Quote
09-11-19, 12:29 PM   #9
Motanum
A Murloc Raider
Join Date: Aug 2019
Posts: 5
I used the StaticPopUp to display the messages! I nolonger have to spam my chat!

Now the only thing that triggers me is the sound that plays everytime the frame comes on, but I think in the documentation is something to change that. Or if someone else knows how to, thanks!

With that change, I think I will be happy to upload it so everyone else can know which spells are their most efficient spells.



Thanks for the huge help!

I solved the sound thing. I went over to StaticPop.lua, and overloaded the function StaticPopup_OnShow and StaticPopup_OnHide to change the play sound when it loaded in my addon folder below from where I create my StaticPopupDialogs

--Override StaticPopup_OnShow()
function StaticPopup_OnShow(self)
--PlaySound(SOUNDKIT.IG_MAINMENU_OPEN);
PlaySound(SOUNDKIT.IG_CHAT_SCROLL_UP);
...
end

Last edited by Motanum : 09-11-19 at 12:46 PM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » how do I get a spellID from when I mouse over a spell in game?

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