Sell by item IDs

I need a macro, or more perferably the code to add a button to a vendor to sell items based on a range of item IDs.
Reply Quote
local ID_MIN = 999 -- The minimum value of the range
local ID_MAX = 9001 -- The maximum value of the range

local function IsIDInRange(id)
return id < ID_MAX and id > ID_MIN
end

local button = CreateFrame("Button", "SellByIDButton", MerchantFrame, "UIPanelButtonTemplate")
button:SetWidth(100)
button:SetHeight(19.5)
button:SetPoint("BOTTOM", "MerchantFrameTab1", "TOP", 10, 4)
button:SetText("Sell by ItemID")
button:SetScript("OnClick", function()
for bag = 0, 4 do
for slot = 1, GetContainerNumSlots(bag) do
local l = GetContainerItemLink(bag, slot)
local id = (l or ""):match("|c%x+|Hitem:(%d+):.+")
if id and IsIDInRange(id) then
UseContainerItem(bag, slot)
end
end
end
end)
Edited by Choonster on 9/25/2011 10:48 AM PDT
Reply Quote
Coonster, I'd want you to have my babies, if I wasn't so sure you'd eat them.

Can I give you a pet/mount/game time? You've helped me so much.
Reply Quote
Coonster, I'd want you to have my babies, if I wasn't so sure you'd eat them.

Can I give you a pet/mount/game time? You've helped me so much.
lol, thanks for the offer but there's no need to pay me.
Reply Quote
How about a baby then? Can I get you a nice delisious baby to eat? Forsaken eat babies, right?
Reply Quote
09/25/2011 12:21 PMPosted by Ieatsouls
How about a baby then? Can I get you a nice delisious baby to eat? Forsaken eat babies, right?
Only on special occasions.
Reply Quote
100 Night Elf Hunter
15620
Upon further inspection, it looks like what I'm trying to do is going to require a bit more work. I'm trying to sell all of the common white Fortune cards. There's a range for most of them, but some have an ID outside that range, and there's a gap between the 50s cards and the 1g cards. 62552 to 62591 will work for most of the 10s and 50s cards, with the exception of 62247 and 62246 that are outside the range. The range for the 1g and 5g cards is 62598 to 62605, with 60839 and 60841 outside the range.

if itemId == 62247 or IDInRange(itemId, 62552, 62576) then
return '10s'
elseif itemId == 62246 or IDInRange(itemId, 62577, 62591) then
return '50s'
elseif itemId == 60839 or IDInRange(itemId, 62598, 62601) then
return '1g'
elseif itemId == 60841 or IDInRange(itemId, 62602, 62605) then
return '5g'
elseif itemId == 60842 then
return '20g'
elseif itemId == 60843 or itemId == 62606 then
return '50g'
elseif itemId == 60845 then
return '200g'
elseif itemId == 60840 then
return '1000g'
elseif itemId == 60844 then
return '5000g'


That's from the probability addon, with all the item IDs for the cards. I'm not too concerned with the green 20g card and up, but the white cards are better off vendored than taking up bag space.
Reply Quote
local function IDInRange(id , minimum, maximum)
return id < maximum and id > mininmum
end

local function IsValidID(id)
if id == 62247 or IDInRange(id, 62552, 62576) then
return '10s'
elseif id == 62246 or IDInRange(id, 62577, 62591) then
return '50s'
elseif id == 60839 or IDInRange(id, 62598, 62601) then
return '1g'
elseif id == 60841 or IDInRange(id, 62602, 62605) then
return '5g'
elseif id == 60842 then
return '20g'
elseif id == 60843 or id == 62606 then
return '50g'
elseif id == 60845 then
return '200g'
elseif id == 60840 then
return '1000g'
elseif id == 60844 then
return '5000g'
end
end

local button = CreateFrame("Button", "SellByIDButton", MerchantFrame, "UIPanelButtonTemplate")
button:SetWidth(100)
button:SetHeight(19.5)
button:SetPoint("BOTTOM", "MerchantFrameTab1", "TOP", 10, 4)
button:SetText("Sell by ItemID")
button:SetScript("OnClick", function()
for bag = 0, 4 do
for slot = 1, GetContainerNumSlots(bag) do
local link = GetContainerItemLink(bag, slot)
local id = (link or ""):match("|c%x+|Hitem:(%d+):.+")
if id and IsValidID(id) then
UseContainerItem(bag, slot)
end
end
end
end)


This uses the vendor pricing code above instead of simply checking if the ID is in a single range.
Reply Quote
100 Night Elf Hunter
15620
I commented out the old section, and added in this. I had to change a variable name in the message handler to match the new variable name. When flipping a card od clicking the vendor button it throws an error though. Attempting to compare number with string. It says it starts with defining the IDInRange function, and trickles down to every other use of it.
Reply Quote
When flipping a card od clicking the vendor button it throws an error though. Attempting to compare number with string. It says it starts with defining the IDInRange function, and trickles down to every other use of it.
Ah, change this:local id = (link or ""):match("|c%x+|Hitem:(%d+):.+")
if id and IsValidID(id) then


To this:local id = (link or ""):match("|c%x+|Hitem:(%d+):.+")
id = tonumber(id)
if id and IsValidID(id) then
Reply Quote
100 Night Elf Hunter
15620
Hm... Now it says it's trying to compare nil with number when I click the sell button, and string with number when I loot.
Reply Quote
09/26/2011 09:44 AMPosted by Rubyheart
Hm... Now it says it's trying to compare nil with number when I click the sell button, and string with number when I loot.
Can you post the entire code with the lines from the error highlighted?
Reply Quote
100 Night Elf Hunter
15620
local FortuneCookieChance = ...

local function IDInRange(id , minimum, maximum)
return id < maximum and id > minimum

end

local function IsValidID(id)
if id == 62247 or IDInRange(id, 62552, 62576) then

return '10s'
elseif id == 62246 or IDInRange(id, 62577, 62591) then
return '50s'
elseif id == 60839 or IDInRange(id, 62598, 62601) then
return '1g'
elseif id == 60841 or IDInRange(id, 62602, 62605) then
return '5g'
elseif id == 60842 then
return '20g'
elseif id == 60843 or id == 62606 then
return '50g'
elseif id == 60845 then
return '200g'
elseif id == 60840 then
return '1000g'
elseif id == 60844 then
return '5000g'
end
end

local button = CreateFrame("Button", "SellByIDButton", MerchantFrame, "UIPanelButtonTemplate")
button:SetWidth(100)
button:SetHeight(19.5)
button:SetPoint("BOTTOM", "MerchantFrameTab1", "TOP", 10, 4)
button:SetText("Sell by ItemID")
button:SetScript("OnClick", function()
for bag = 0, 4 do
for slot = 1, GetContainerNumSlots(bag) do
local link = GetContainerItemLink(bag, slot)
local id = (link or ""):match("|c%x+|Hitem:(%d+):.+")
id = tonumber(id)
if id and IsValidID(id) then
UseContainerItem(bag, slot)
end
end
end
end)

-- local IDInRange = function(itemId, min, max)
-- return itemId >= min and itemId <= max
-- end

-- local GetCardValue = function(itemId)
-- itemId = tonumber(itemId)

-- if itemId == 62247 or IDInRange(itemId, 62552, 62576) then
-- return '10s'
-- elseif itemId == 62246 or IDInRange(itemId, 62577, 62591) then
-- return '50s'
-- elseif itemId == 60839 or IDInRange(itemId, 62598, 62601) then
-- return '1g'
-- elseif itemId == 60841 or IDInRange(itemId, 62602, 62605) then
-- return '5g'
-- elseif itemId == 60842 then
-- return '20g'
-- elseif itemId == 60843 or itemId == 62606 then
-- return '50g'
-- elseif itemId == 60845 then
-- return '200g'
-- elseif itemId == 60840 then
-- return '1000g'
-- elseif itemId == 60844 then
-- return '5000g'
-- end
-- end

-- -- local ID_MIN = 999 -- The minimum value of the range
-- -- local ID_MAX = 9001 -- The maximum value of the range

-- -- local function IsIDInRange(id)
-- -- return id < ID_MAX and id > ID_MIN
-- -- end

-- -- local button = CreateFrame("Button", "SellByIDButton", MerchantFrame, "UIPanelButtonTemplate")
-- -- button:SetWidth(100)
-- -- button:SetHeight(19.5)
-- -- button:SetPoint("BOTTOM", "MerchantFrameTab1", "TOP", 10, 4)
-- -- button:SetText("Sell by ItemID")
-- -- button:SetScript("OnClick", function()
-- -- for bag = 0, 4 do
-- -- for slot = 1, GetContainerNumSlots(bag) do
-- -- local l = GetContainerItemLink(bag, slot)
-- -- local id = (l or ""):match("|c%x+|Hitem:(%d+):.+")
-- -- if id and IsIDInRange(id) then
-- -- UseContainerItem(bag, slot)
-- -- end
-- -- end
-- -- end
-- -- end)

local f = CreateFrame'Frame'
f:SetScript('OnEvent', function(self, event, ...) f[event](f, ...) end)

f:RegisterEvent'ADDON_LOADED'
function f:ADDON_LOADED(addon)
if addon == FortuneCookieChance then
FortuneCookieChanceDB = FortuneCookieChanceDB or {}
end
end

f:RegisterEvent'CHAT_MSG_LOOT'
function f:CHAT_MSG_LOOT(message)
local id = message:match('item:(%d+):')
if id then
local value = IsValidID(id)
if value and not FortuneCookieChanceDB[value] then
print'adding new db'
FortuneCookieChanceDB[value] = 1
elseif value then
print'incrementing db'
FortuneCookieChanceDB[value] = FortuneCookieChanceDB[value] + 1
end
end
end

local order = {
'5000g',
'1000g',
'200g',
'50g',
'20g',
'5g',
'1g',
'50s',
'10s',
}

SlashCmdList['FORTUNE'] = function()
local totalCards = 0
for value, num in pairs(FortuneCookieChanceDB) do
totalCards = totalCards + num
end

print'-------------------------'
print('TOTAL CARDS SEEN: ' .. totalCards)
for _, value in pairs(order) do
local num = FortuneCookieChanceDB[value]
if num then
print(value, 'x', num, ('(%d%%)'):format(num / totalCards * 100))
end
end
end
SLASH_FORTUNE1 = '/fortune'


Underlined lines are the error lines given when clicking the sell button, but I think I see the problem already. I'll change the mininmum in line 4 to minimum.

EDIT: Changed "mininmum" to "minimum" on line 4 and now the sell button works, but when eating a cookie it throws another compare string to number error, the bolded lines are the ones in the new error.

I'm heading to work now, so I won't be able to test anything for a while, but I'll be able to post.
Edited by Rubyheart on 9/26/2011 10:57 AM PDT
Reply Quote
In the CHAT_MSG_LOOT method, change this:local id = message:match('item:(%d+):')
if id then

To this:local id = message:match('item:(%d+):')
id = tonumber(id)
if id then
Reply Quote
100 Night Elf Hunter
15620
Beautiful! Works perfectly now. Are you sure you don't want something for your trouble?
Reply Quote
09/26/2011 06:15 PMPosted by Rubyheart
Beautiful! Works perfectly now. Are you sure you don't want something for your trouble?
Thanks for the offer, but I'm fine.
Reply Quote
89 Blood Elf Priest
8495
Why not just search the itemlink for an appropriate string, namely the color code for "white" and "Fortune Card" ?

Edit: This is, for example, how most trash-vending addons do it. I made my own that has a button appearing whenever you open the vendor window; for the odd white item I don't want ( Shiny Fish Scales, anyone?)
Edited by Simpleton on 9/26/2011 10:46 PM PDT
Reply Quote
100 Night Elf Hunter
15620
I hate to be a nag but... It seems to be ignoring a few cards. Both recording when I loot them, and trying to sell them with the button. I'll get the IDs of the ignored cards, but I think I already know what they are.

EDIT: The IDs of the cards not being recorded are the ones at the ends of the ranges, I'm pretty sure this is a simple fix by changing line 4 from < and > to <= and >=.

EDIT2: That seems to have fixed it.
Edited by Rubyheart on 9/27/2011 12:06 AM PDT
Reply Quote
88 Blood Elf Paladin
9615
Wow my friend got the 5k card when we where doing DS right after we got killed on spine :( she was totally surprised
Reply Quote
100 Night Elf Hunter
15620
Were they using the Fortune Cookie Chance addon? If so, have them email me the saved variables file so I can update my odds website.
Reply Quote

Please report any Code of Conduct violations, including:

Threats of violence. We take these seriously and will alert the proper authorities.

Posts containing personal information about other players. This includes physical addresses, e-mail addresses, phone numbers, and inappropriate photos and/or videos.

Harassing or discriminatory language. This will not be tolerated.

Forums Code of Conduct

Report Post # written by

Reason
Explain (256 characters max)
Submit Cancel

Reported!

[Close]