Quantcast
Identify items that can be traded to other players in the same instance. - WoWInterface
Thread Tools Display Modes
10-08-20, 10:40 PM   #1
Walkerbo
A Theradrim Guardian
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 63
Identify items that can be traded to other players in the same instance.

Hi all

I am the author of a small addon Aardvark.

I am trying to find a way to identify those items in my bags that can be traded to other players in the same instance.



Right now my addon sells items listed on the player curated sell list.

The issue is that items that can be traded to other players in the same instance starts an addon breaking loop.

When the item is to be sold it brings up the confirmation that selling will make it non-tradable.

With items that have a refund cooldown I can filter them out so it will not sell until the time runs out; I test each item for a refund cooldown;
Lua Code:
  1. local money, itemCount, refundSec = GetContainerItemPurchaseInfo(bag, slot)
I have been unable to find a similar function to test for the trade cooldown.

I would like to be able to identify and filter those items that are still on the trade cooldown.
It would also be helpful to have the confirmation button could be avoided and have the item sell even though it is still on trade cooldown.

Cheers
__________________
"As someone once told me, frames are just special types of tables."
Fizzlemizz
  Reply With Quote
10-09-20, 02:08 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,534
Possibly a combination of these two functions will help you

https://wow.gamepedia.com/API_GetItemInfo
https://wow.gamepedia.com/API_C_Item.IsBound

ItemLocation Info
https://www.townlong-yak.com/framexm...emLocation.lua
__________________
  Reply With Quote
10-10-20, 01:59 AM   #3
Urtgard
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 25
I scan the tooltip for the BIND_TRADE_TIME_REMAINING string

Code:
local tip = CreateFrame("GameTooltip","Tooltip",nil,"GameTooltipTemplate")

local function isTradable(itemLocation)
	local itemLink = C_Item.GetItemLink(itemLocation)
	tip:SetOwner(UIParent, "ANCHOR_NONE")
	tip:SetBagItem(itemLocation:GetBagAndSlot())
	tip:Show()
	for i = 1,tip:NumLines() do
		if(string.find(_G["TooltipTextLeft"..i]:GetText(), string.format(BIND_TRADE_TIME_REMAINING, ".*"))) then
			return true
		end
	end
	
	tip:Hide()
    return false
end
  Reply With Quote
10-18-20, 08:28 PM   #4
Walkerbo
A Theradrim Guardian
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 63
Hi all

Sorry for the delayed reply.

Thanks for the links and code chunk.

Here is the current code;
Lua Code:
  1. local tip = CreateFrame("GameTooltip","Tooltip",nil,"GameTooltipTemplate")
  2.  
  3. local function isTradable(itemLocation)
  4.    local itemLink = C_Item.GetItemLink(itemLocation)
  5.    tip:SetOwner(UIParent, "ANCHOR_NONE")
  6.    tip:SetBagItem(itemLocation:GetBagAndSlot())
  7.    for i = 1,tip:NumLines() do
  8.       if(string.find(_G["TooltipTextLeft"..i]:GetText(), string.format(BIND_TRADE_TIME_REMAINING, ".*"))) then
  9.         return true
  10.       end
  11.    end
  12. end
  13.    
  14. for bag = 0, 4 do
  15.     for slot = 0, GetContainerNumSlots(bag) do
  16.         local itemID = GetContainerItemID(bag, slot)
  17.         if itemID then
  18.             local _, itemLink = GetItemInfo(itemID)
  19.             itemLocation = ItemLocation:CreateFromBagAndSlot(bag, slot)            
  20.             if isTradable(itemLocation) then
  21.             print("found",itemLink,isTradable(itemLocation))
  22.             end
  23.         end
  24.     end
  25. end

This works perfectly.

What I am wondering is I also want to be able to idently those items that can be sold back to the venror for a full refund.
The string I have to look for is REFUND_TIME_REMAINING yet when I try to find the string I get no matches.

Is it possible to search for either or both of the strings in the same loop?
__________________
"As someone once told me, frames are just special types of tables."
Fizzlemizz
  Reply With Quote
10-24-20, 02:32 AM   #5
Urtgard
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 25
How did you search for REFUND_TIME_REMAINING?

If you just search for REFUND_TIME_REMAINING it can't work.
Becuase REFUND_TIME_REMAINING contains %s. If you use string.format %s is a placeholder where we can put the time string.
But if you use REFUND_TIME_REMAINING as a argument for string.find it is now a regex string. And %s matches just one space char.

That's why I used string.format(BIND_TRADE_TIME_REMAINING, ".*"). That replaces %s with .* and .* matches with any string.
  Reply With Quote
10-25-20, 09:05 PM   #6
Walkerbo
A Theradrim Guardian
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 63
Hi Urtgard

I used the same code and added an or as follows;
Lua Code:
  1. if(string.find(_G["TooltipTextLeft"..i]:GetText(), string.format(BIND_TRADE_TIME_REMAINING, ".*"))) or
  2.  (string.find(_G["TooltipTextLeft"..i]:GetText(), string.format(REFUND_TIME_REMAINING, ".*"))) then
  3.         return true
  4. end
and an elseif;
Lua Code:
  1. if(string.find(_G["TooltipTextLeft"..i]:GetText(), string.format(BIND_TRADE_TIME_REMAINING, ".*"))) then
  2.         return true
  3.       elseif(string.find(_G["TooltipTextLeft"..i]:GetText(), string.format(REFUND_TIME_REMAINING, ".*"))) then
  4.         return true
  5.       end
I also tried an elseif, but for some reason, I was only getting true on items that could be traded.

Right now I am using a combination of your tooltip scan code and getting the refund seconds as follows,
Lua Code:
  1. local function isTradable(itemLocation)
  2.    local itemLink = C_Item.GetItemLink(itemLocation)
  3.    tip:SetOwner(UIParent, "ANCHOR_NONE")
  4.    tip:SetBagItem(itemLocation:GetBagAndSlot())
  5.    for i = 1,tip:NumLines() do
  6.       if(string.find(_G["TooltipTextLeft"..i]:GetText(), string.format(BIND_TRADE_TIME_REMAINING, ".*"))) then
  7.         return true
  8.       end
  9.    end
  10. end
  11.    
  12. for bag = 0, 4 do
  13.     for slot = 0, GetContainerNumSlots(bag) do
  14.         local itemID = GetContainerItemID(bag, slot)
  15.         if itemID then
  16.             local _, itemLink = GetItemInfo(itemID)
  17.             local money, itemCount, refundSec = GetContainerItemPurchaseInfo(bag, slot)
  18.             local itemLocation = ItemLocation:CreateFromBagAndSlot(bag, slot)            
  19.             if isTradable(itemLocation) or refundSec then
  20.                 print("found",itemLink)
  21.             end
  22.         end
  23.     end
  24. end

I just wish I could understand why scanning the tooltip works for one but not the other.
__________________
"As someone once told me, frames are just special types of tables."
Fizzlemizz
  Reply With Quote
10-27-20, 04:08 PM   #7
Urtgard
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 25
Have you checked with print(string.find(_G["TooltipTextLeft"..i]:GetText()) that one of the lines actually contains the refund message?

Maybe REFUND_TIME_REMAINING was changed in the pre patch.
  Reply With Quote
11-01-20, 11:27 PM   #8
Walkerbo
A Theradrim Guardian
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 63
Hi Urtgard

I did loop through the tooltip using your string, yet the translated strings were returned rather than the REFUND_TIME_REMAINING string that I need.

This is really confusing yet the double down method is working correctly.

Thanks for all the help.
__________________
"As someone once told me, frames are just special types of tables."
Fizzlemizz
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Identify items that can be traded to other players in the same instance.

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