Quantcast
Addon Development Help Request - WoWInterface
Thread Tools Display Modes
12-19-16, 08:29 PM   #1
briskman3000
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 75
Addon Development Help Request

So I had the over-zealous idea to create an addon that would do the very basic function that most people miss from the old RatingsBuster addon, which is convert the amount of a combat rating on an item into a percentage.



I was able to gather all of the mathematical information that I would need to create such an addon, only to realize that my extremely limited knowledge of Lua and the WoW API stops me dead in my tracks.



I pulled my code and dumped it into a GitHub Convert Ratings



If anyone with actual knowledge of Lua and the API can assist in completing this addon, or at least give me some pointers in the right direction, it would be greatly appreciated

FYI ... I did also post this request on the addon subreddit, just incase anyone here browses both
  Reply With Quote
12-19-16, 09:45 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Should be fairly straightforward. Assuming you want to add the info to the game tooltip, you need to hook for example the OnTooltipSetItem script, parse all tooltip lines and edit the text accordingly.

Something like this:
Code:
GameTooltip:HookScript("OnTooltipSetItem", function(self)
	for i = 1, self:NumLines()
		local line = _G["GameTooltipTextLeft"..i]
		if line then
			local text = line:GetText()
			if textContainsRatingValues() then
				line:SetText("Replace text with this")
			end
		end
	end
end)
__________________
Grab your sword and fight the Horde!
  Reply With Quote
12-20-16, 12:48 PM   #3
briskman3000
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 75
Originally Posted by Lombra View Post
Should be fairly straightforward. Assuming you want to add the info to the game tooltip, you need to hook for example the OnTooltipSetItem script, parse all tooltip lines and edit the text accordingly.

Something like this:
Code:
GameTooltip:HookScript("OnTooltipSetItem", function(self)
	for i = 1, self:NumLines()
		local line = _G["GameTooltipTextLeft"..i]
		if line then
			local text = line:GetText()
			if textContainsRatingValues() then
				line:SetText("Replace text with this")
			end
		end
	end
end)
So from how I'm reading the code you wrote, the first line is the event that fires when you mouse-over an item and then it runs the function(self) code, which is below that line.

The code then basically does a foreach() on each line of text to see if that line has a combat rating value, and then would add the output that is set in that last line.

What I don't see is how it would determine which combat rating the line of text actually contains in order to put the appropriate converted value in each line.

Would something like this work?

Note: This below assumes that the tooltip text is parsed as actual text, and not as the internal stat variable name for example "Critical Strike" vs ITEM_MOD_CRIT_RATING_SHORT

The p"stat" variables are what should contain the rating number converted to a percentage in the code
Code:
GameTooltip:HookScript("OnTooltipSetItem", function(self)
	for i = 1, self:NumLines()
		local line = _G["GameTooltipTextLeft"..i]
		if line then
			local text = line:GetText()
			if textContainsRatingValues() then
                              if text = "Critical Strike" then
				line:SetText(tostring(pcrit) .. "%") else
                              if text = "Haste" then
                                line:SetText(tostring(phaste) .. "%") else
                              if text = "Mastery" then
                                line:SetText(tostring(pmastery) .. "%") else
                              if text = "Versatility" then
                                line:SetText(tostring(pversin) .. "%/" .. tostring(pversout) .. "%") 
                              end
			end
		end
	end

Last edited by briskman3000 : 12-20-16 at 12:50 PM.
  Reply With Quote
12-21-16, 08:27 AM   #4
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
You've got the jist of it. textContainsRatingValues is just a pseudo function. Replace with your own logic!

Yes, all the text is returned as plain text. Apart from not using == to test equality, the immediate error is that you're testing whether the whole string equals "Critical Strike", rather than merely includes it. You will need to use string.find or string.match, which can also be used to extract the relevant numerical value from the string.
You can read about it here and/or ask for more information.
http://wow.gamepedia.com/Pattern_matching

Couple more things. elseif needs to be one word, otherwise it's else with a nested if. When replacing the text on each line, you probably want to include the existing text as well.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
12-21-16, 12:32 PM   #5
briskman3000
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 75
I ended up not using the code that I had posted here, and instead changed up a bunch of things in the code using what you provided as a basis for how things are called and set, and from what I read from a few different sources.

I think I got the stats to calculate, as I am not getting any error output from the calculation lines ( was getting some nil errors because I had the table set up wrong and attempting to lookup values in a way that was impossible)

However, I am not getting any output into the tooltip anymore.


I've probably forgot some event that needs to be fired somewhere, but I don't see it.

Here is the code for the addon pulling the stats, converting them, and then attempting to output them to the tooltip:
Code:
local function getItemIdFromTooltip(self)
    local name, itemLink = self:GetItem();
    
    --Gets stats from item using itemLink - it's a table
    stats = GetItemStats(itemLink);

    --Gnor: pull individual stats from stats table since the way that it was being accomplished wouldn't allow for calculations to be done
    local rawmastery = stats["ITEM_MOD_MASTERY_RATING_SHORT"]
    local rawcrit = stats["ITEM_MOD_CRIT_RATING_SHORT"]
    local rawhaste = stats["ITEM_MOD_HASTE_RATING_SHORT"]
    local rawvers = stats["ITEM_MOD_VERSATILITY"]

    --convert raw stats into percentages so long as they are not nil
    --This seems to work, as I am not getting any error output
if rawcrit ~= nil
   then
       local pcrit = rawcrit / critamt
   else
   end

if rawhaste ~= nil
   then
       local phaste = rawhaste / hasteamt
   else
   end

if rawvers ~= nil
   then
       local pversin = rawvers / versinamt
       local pversout = rawvers / versoutamt
   else
   end

if rawmastery ~= nil
   then
       local pmastery = (rawmastery / masteryamt) * masterycf
   else
   end

--Convert percentages to strings
tostring(pcrit)
tostring(phaste)
tostring(pversin)
tostring(pversout)
tostring(pmastery)

--Send the converted stats to the tooltip if they are not nil
--This does not work atm
--temp see if they output to chat ... nope must be missing something

if pcrit ~= nil
   then
      GameTooltip:AddLine(pcrit .. "% Crit")
   else
   end

 if phaste ~= nil
   then
       GameTooltip:AddLine(phaste .. "% Haste")
   else
   end

 if pmastery ~= nil
   then
       GameTooltip:AddLine(pmastery .. "% Mastery")
   else
   end

if pversin ~= nil
   then
      GameTooltip:AddLine(pversin .. "%/" .. pversout .. "% Versatility")
   else
   end
end
GameTooltip:HookScript("OnTooltipSetItem", getItemIdFromTooltip);
  Reply With Quote
12-21-16, 03:45 PM   #6
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
I would not trust GetItemStats, unless it has been improved recently. It might not take into account things like upgraded items or warforged and instead just use the base stats.

Anyway, the problem is that your variables are immediately out of scope. pcrit etc only exists within their respective if - else scope. Declare the variables outside of the scope, and then assign values to them inside.

Also, if you want to use tostring you need to assign the new value to the variable. It doesn't replace the value in place. Numbers automatically get converted to strings when joining them with a string, however.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
12-21-16, 05:49 PM   #7
briskman3000
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 75
The pull request you put in the GitHub works for everything except your artifact, since I assume that info is stored a different way than the rest of your items.

I have some warforged/titanforged items equipped and it seems to pull those stats correctly, so your worries that the GetItemStats() was only pulling the base stats can be relieved.

I'll have to see if I can find the proper way to pull the artifact stats from the api.

Once I find that, it should only be a matter of putting in a conditional check against the item's rarity to determine which method of pulling to use by

Replace:
Code:
    --Gets stats from item using itemLink - it's a table
    stats = GetItemStats(itemLink);

With:
Code:
local itemRarity = select(3,GetItemInfo(itemlink))

local stats

if itemRarity == 6 then

stats = "insert new lookup here" else

stats = GetItemStats(itemLink); 

end

EDIT:

Also, I have deemed it "done enough" at this point to release it out into the wild. I

I was able to figure out how to get curse to pull releases from github, but for the life of me I can't figure out this website.

On Curse I have given you credit for all your help, in the description of the addon, and added you as an author. Also, I'm not sure what it is but I gave you most of the % of the rewards credits that will come from this addon on curse ... since you wrote most of the hard stuff.

Last edited by briskman3000 : 12-21-16 at 07:39 PM.
  Reply With Quote
12-21-16, 10:07 PM   #8
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
I just realised that was my 500th post, then. Wohoo! \o/

I have not submitted any pull requests, so make sure you're not crediting the wrong person. :P Either way, you're welcome! Feel free to return to ask for more help! I don't personally know the first thing about artifact APIs, however.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
12-21-16, 11:18 PM   #9
briskman3000
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 75
Yea i just realized that while looking at both here and reddit, both of you had names that start with an L ... and my brain just combined the two .....

I did give credit to the correct person however.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Addon Development Help Request

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