WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   getting bagslots from the tooltip (https://www.wowinterface.com/forums/showthread.php?t=56221)

saxitoxin 05-15-18 06:17 AM

getting bagslots from the tooltip
 
Unless there is a function where I can get the total number of slots in a bag that is in my inventory (not equipped)

My guess is that I have to scan the tooltip, but I have no idea how to do that

I know that
Code:

CONTAINER_SLOTS = "%d Slot %s";
is the line in the tooltip

but not how to get %d as a value from that line in the tooltip

I would appreciate a sample code

Xrystal 05-15-18 07:05 AM

I couldn't see anything specific, so hopefully someone better versed in this area will pipe in at some point, but this might be one way of getting the info you need.

Get the item in the tooltip
https://wow.gamepedia.com/API_GameTooltip_GetItem

Use the item link return value
https://wow.gamepedia.com/ItemLink

Then see what the different values are in the itemString relating to the item
https://wow.gamepedia.com/ItemString

Hopefully one of those values will be the bag quantity, trial and error will obviously be the key

d87 05-15-18 07:06 AM

Lua Code:
  1. -- Construct your saarch pattern based on the existing global string:
  2. local S_ITEM_LEVEL   = "^" .. gsub(ITEM_LEVEL, "%%d", "(%%d+)")
  3. local strmatch = string.match
  4.  
  5. -- Create the tooltip:
  6. local scantip = CreateFrame("GameTooltip", "MyScanningTooltip", nil, "GameTooltipTemplate")
  7. scantip:SetOwner(UIParent, "ANCHOR_NONE")
  8.  
  9. local function GetItemLevelFromTooltip(itemLink)
  10.     -- Pass the item link to the tooltip:
  11.     scantip:SetHyperlink(itemLink)
  12.  
  13.     -- Scan the tooltip:
  14.     for i = 2, scantip:NumLines() do -- Line 1 is always the name so you can skip it.
  15.         local text = _G["MyScanningTooltipTextLeft"..i]:GetText()
  16.         if text and text ~= "" then
  17.         local itemLevel = strmatch(text, S_ITEM_LEVEL)
  18.             if itemLevel then
  19.                 return itemLevel
  20.             end
  21.         end
  22.     end
  23. end

saxitoxin 05-15-18 07:33 AM

I might get some of the info i need from getItemString

--

Yes d87 i was thinking of a function like this but for bagslots and not Ilvl but i have no idea what the gsub is suppose to look like

d87 05-15-18 07:45 AM

local pattern = "^" .. CONTAINER_SLOTS:gsub("%%d", "(%%d+)"):gsub("%%s", ".+")

saxitoxin 05-15-18 08:53 AM

I can't test this yet, but can you please eli5 what this means?
From what i have read %d is number, %s is string but why use %%d?

runamonk 05-15-18 09:00 AM

Quote:

Originally Posted by saxitoxin (Post 328000)
I can't test this yet, but can you please eli5 what this means?
From what i have read %d is number, %s is string but why use %%d?

If you want to output/match a literal % you need to double it up so that the interpreter knows, otherwise it assumes you want to format that character or string.

Check this out

saxitoxin 05-15-18 03:37 PM

Thank you!
 
Got it working!


Guess I have to read up on stringformating and those stuffs now :p

Xrystal 05-15-18 04:58 PM

Congratulations ... because Grats isn't long enough

JDoubleU00 05-15-18 05:42 PM

Quote:

Originally Posted by Xrystal (Post 328009)
Congratulations ... because Grats isn't long enough

Congo Rats!

runamonk 05-16-18 12:46 AM

Congrats! Always awesome when a plan comes together. ;) :banana:

Kakjens 05-19-18 01:04 PM

Before printing you might want to sort the suggestions in, for example, descending benefit.
How should your addon treat profession bags? What about bags that are in (or for) bank?

saxitoxin 05-21-18 12:56 AM

thank you all!

I really appreciate suggestions :)
This is only meant for personal use now. The addon tells me if I have gotten any better gear, a bigger bag or new transmog gear
As of now it only check the 0-4 slots of the inventory, and only for the subtype "Bag"
But I might add this in if/after a public release
I have no idea how the addon will work with other languages than English either


All times are GMT -6. The time now is 09:07 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI