I'm trying to write an addon to allow user's to select some items (their Best in slot items) and track how far they are from that equipment.
The problem I'm facing is how can the user configure that list. I mean, the addon needs to allow them to select an item the user don't have, so they can't drag it into the addon, they won't know the item's link...
It would be great for the user to only write the items name, but I would need the addon to get that item's link from it's name. Is this possbile?
Would I need to have a table with ALL the items, with their name and their link to find a match?
WoWEquip is a great addon, and contains some of the functions that my addon needs, but it's intended for a different use. Also it's far more complex that I want my addon to be.
What my addon does is:
- User configure their BiS equipment (choosed by using WoWEquipment, Rawr...)
- Shows a frame where user can see "Current equipment-BiS Equipment" (no stats comparison or whatever.
- Shows a status text like "You got yourself 12/17 BiS items"
- Allow you to auto-whisper yourself, master looter, raid lider when looting in raid with "Loot item xxxx is BiS for yyyy" (in my guild we give items to those who will take better proffit instead of those with better roles, and we encourage people to give to the raid lider a list of their BiS so they can get it asap).
As you can see is a pretty simple addon, and I got everything covered but the "choose BiS items" thing. How does WoWEquip does it? My guess is it stores the whole table of items, but it just seems not right for suche a light addon as mine. But I would do it if is the only way, of course.
Since I wrote WoWEquip, I'll explain how it works.
WoW stores a cache of every item you have seen in the game since the last patch you installed. "Seen" here means if someone is wearing it near you (visible range), if you looted it, the item appears in a loot box/roll, the item exists in your bank or bags, you visited the guild bank and its in the tab you viewed, etc. "Seen" does NOT include people pasting itemlinks in chat, unless you actually clicked on the link to open the tooltip.
All WoWEquip does is loop from itemIDs 55000 to 0 and check if your cache contains the item (by using GetItemInfo(itemID) and seeing if it returns nil). Then I find the eligible items for a particular paper doll slot you are trying to equip by applying the user's filters and display the final list.
WoWEquip includes a very obvious message that says ... well see the bottom right corner of this screenshot:
To put it simply, you can't get an itemlink that isn't in the user's local cache unless you know the itemID of that item - the name doesn't help. With the itemID, you can query the server for the item's tooltip (by calling sometooltipofyouraddon:SetHyperlink("itemid:1234")) and then waiting a couple of seconds for the server to reply.
There is no event or guarantee that the server will even reply with the itemlink to populate your itemcache. If the server hasn't seen the item before since its last server reboot, seen here in this case meaning a vendor spawns it, a corpse dropped it, or someone with the item logged in since server reboot). If you query for too many invalid itemlinks (validity is based on whether the server has seen it before since reboot), typically more than 6 per minute, the server will disconnect you offline for spamming the server.