Stat Weights Classic

Stat Weights Classic

228k Downloads

Reference the data in realtime from other addon

quetzalsly opened this issue ยท 4 comments

commented

Hey thanks for creating this wonderful addon, I am quite new to LUA and wow addon coding and wanted to create a small stats panel that shows some stuff like predicted next hit and then I realised how much effort it would be to calculate all the stuff including world buffs etc. Then I found this addon! so happy that someone already did this and implemented it very well.

Anyway my question is, is the main data stored in spells[id] array? Is there any way for me to somehow use this variable externally without including/importing the entire LUA file? In C++ it would be as simple as including a header or using 'extern' haha, but no idea how LUA handles this stuff.

Edit: I completly forgot that addons are isolated from each other so I would have to communicate through some hidden channel? maybe its possible to make some kinda super simple API? like RequestSpell(id) is sent to your addon and that returns an object with the relevant info?

commented

Hey thanks!

The spells[id] won't be able to tell you anything useful. It only gives me some basic information about a spell without any modification as provided by data from wowhead. This is being done because there is no good way of getting this information from the game itself. Even if you parse tooltips for spells, the game sometimes adds things from talents into the tooltip, and sometimes not...

I'm new to LUA as well as my first line ever was for this addon. I don't really know the best way to make an externally available API either :P As far as I know, the only thing that isolates addons is the keyword local which hides the scope from others. Otherwise everything goes into the same global environment, but naming conflicts obviously become problematic.

I have added three new global easy to use functions for this purpose, unlikely to have conflicting names, each of them using the chosen, active loadout from /sw loadouts at the time

  1. __sw__spell_info(spell_id)
    returns a table with two entries called
    stats (contains data like crit, hit, spell power, etc)
    info (contains data like damage, critical hit damage, DPS, etc)
  2. __sw__spell_evaluation(spell_id)
    returns a table with two entries called
    stats (contains data like crit, hit, spell power, etc)
    eval (contains stat weights for infinite spam cast scenarios)
  3. __sw__spell_race_to_bottom_evaluation(spell_id)
    returns a table with two entries called
    stats (contains data like crit, hit, spell power, etc)
    eval (contains stat weights for casts until oom scenarios)

I'll just paste code here that I quickly used to check if it was working, which prints out the fields/metrics available from each function which may be useful to you depending on which metrics you're interested in.

spell_id = 9889; -- healing touch

print("SPELL INFO")
x = __sw__spell_info(spell_id)

for k,v in pairs(x.stats) do
   print(k,v)
end
for k,v in pairs(x.info) do
   print(k,v)
end
print("STAT WEIGHTS FOR INFINITE SPAM CAST");

y = __sw__spell_evaluation(spell_id)
for k,v in pairs(y.stats) do
   print(k,v)
end
for k,v in pairs(y.eval) do
   print(k,v)
end

print("STAT WEIGHTS FOR CASTS UNTIL OOM")
z = __sw__spell_race_to_bottom_evaluation(spell_id)

for k,v in pairs(z.stats) do
   print(k,v)
end
for k,v in pairs(z.eval) do
   print(k,v)
end

It prints the key (string) to a value (usually a number). So if you want to know the crit chance for a spell with id: 1000
local x = __sw__spell_info(1000)
print(x.stats.crit)
-- equivalent to
print(x.stats["crit"])

If the addon doesn't recognize the spell id, i.e. not in the massive spells[...] array, it should return nil.

An important note I might add. If your addon is loaded before stat_weights_classic and uses these functions immediately, the functions will be undefined. If this is a problem, you can look into using
either
https://wowwiki.fandom.com/wiki/API_IsAddOnLoaded
or
be notified by an event when stat_weights_classic has been loaded which you can bind to a frame. The response in this thread should demonstrate
https://www.wowinterface.com/forums/showthread.php?t=39536

Let me know if these three functions are of any use :)

EDIT: I made this change in the most recent commit as of time of writing. This is not live via Twitch.

commented

Thanks a lot for adding these changes!
I tried in game for now with /run print(__sw__spell_info(id)) and it prints the table address. Didn't try the full code yet inside an addon.

Can you please tell me how to get the 'expected heal' and 'expected damage' in one line of code? not sure what keys they are, just want to test it quickly before writing the full code.

commented

I'd recommend this addon to play around with any lua code from in-game. https://www.curseforge.com/wow/addons/wowlua

For expectation metric, you can do
/run print(__sw__spell_info(9889).info.expectation)

commented

It works perfectly thanks very much for adding this so quickly! :)))