WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Identify items that can be traded to other players in the same instance. (https://www.wowinterface.com/forums/showthread.php?t=58260)

Walkerbo 10-08-20 10:40 PM

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

Xrystal 10-09-20 02:08 AM

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

Urtgard 10-10-20 01:59 AM

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


Walkerbo 10-18-20 08:28 PM

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?

Urtgard 10-24-20 02:32 AM

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.

Walkerbo 10-25-20 09:05 PM

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.

Urtgard 10-27-20 04:08 PM

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.

Walkerbo 11-01-20 11:27 PM

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.


All times are GMT -6. The time now is 04:00 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI