Page 1 of 1
Q: How to get item's bag-slot-number?
Posted: Tue Nov 08, 2011 6:22 am
by kkulesza
I know i have an item my backpack.
I know its name and ID.
I need the backpack slot number of this item to use it in the PickupItem(slotID) function.
Can i do it in rombot or ingame macro easily?
I didn't find any existing function that returns items slot.
So i wrote my own (edited some existing func)
I put it in the userfunctions folder and it works fine.
But is this userfunction neccessary?
Is there a simpler way?
Code: Select all
function CInventory:findItemSlot( itemNameOrId, range)
local first, last = getInventoryRange(range) -- get bag slot range
if first == nil then
first , last = 1, 240 -- default, search all
end
local smallestStack = nil
local itemslot = nil
self:update()
for slot = first, last do
item = inventory.BagSlot[slot]
if item.Available and (item.Name == itemNameOrId or item.Id == itemNameOrId) then
if item.ItemCount > 1 then
-- find smallest stack
if smallestStack == nil or smallestStack.ItemCount > item.ItemCount then
smallestStack = item
itemslot = slot
end
else
return slot
end
end;
end;
return itemslot
end
Re: Q: How to get item's bag-slot-number?
Posted: Tue Nov 08, 2011 6:37 am
by lisa
Something like this will work
Code: Select all
local item = inventory:findItem("itemname")
if item ~= nil then
RoMScript("PickupItem("..item.SlotNumber..")")
end
Obviously change "itemname" to the actual item name or id
Something to remember is the game has a messed up system and uses 1-30 for bag 1 and also uses 61-90 for bag 1, depending which in game function you are using.
So you may need to play around with it to get the correct values for what you are doing.
I can never remember which is which for that, it's just a stupid system.
Re: Q: How to get item's bag-slot-number?
Posted: Tue Nov 08, 2011 6:49 am
by kkulesza
I did my homework earlier

I've tried the inventory:findItem() func, but it doesnt return a slot number.
It returns some table instead of integer
Re: Q: How to get item's bag-slot-number?
Posted: Tue Nov 08, 2011 7:04 am
by Nero
Similar problem, so I thought I'd post it here instead of opening up a new topic.
I need to use cleanbag in a few of my WP's, and would like to activate it if I have less than, say, 10 spaces left. I assume that it's fairly easy, but I'm not sure how to do it. Something percent-based would also work (there's the same thing in XBar addon - shows you how much spaces you have filled, your max slot count, and then shows how much % is filled with items).
Any hint would be appeciated.
Re: Q: How to get item's bag-slot-number?
Posted: Tue Nov 08, 2011 8:07 am
by rock5
kkulesza wrote:I did my homework earlier

I've tried the inventory:findItem() func, but it doesnt return a slot number.
It returns some table instead of integer
If you look at Lisas example it uses "item.SlotNumber". Yes "item" is a table, of values of information about the item returned. ".SlotNumber" is one of the bits of information about that item.
Re: Q: How to get item's bag-slot-number?
Posted: Tue Nov 08, 2011 8:33 am
by kkulesza
rock5 wrote:
If you look at Lisas example it uses "item.SlotNumber"...
My mistake.
Thx for pointig it rock5.
Thx for help lisa.
Re: Q: How to get item's bag-slot-number?
Posted: Tue Nov 08, 2011 8:38 am
by kkulesza
Nero wrote:Similar problem, so I thought I'd post it here instead of opening up a new topic.
Nope. That is totaly different problem. I was looking for Slot number-ID. You are looking for a number of free slots.
Hint 4 U: search the forum for this phrase: "inventory:itemTotalCount"
Re: Q: How to get item's bag-slot-number?
Posted: Tue Nov 08, 2011 9:59 am
by lisa
kkulesza wrote:I've tried the inventory:findItem() func, but it doesnt return a slot number.
Get yourself a programme like notepad++
Anytime I want to use anything I do a search in files for the function and look at the existing code as an example.
A search for "inventory:findItem(" reveals eggpet.lua
Code: Select all
local foodItem = inventory:findItem(foodNameOrId)
a couple of lines later it has
Code: Select all
RoMScript("PickupBagItem("..foodItem.BagId..")")
You can look at classes/item.lua for what information you can get from the table.
Code: Select all
self.BaseItemAddress = nil;
self.Empty = true;
self.Id = 0;
--self.BagId = bagId;
self.Name = "<EMPTY>";
self.ItemCount = 0;
self.Color = "ffffff";
self.SlotNumber = slotnumber
self.Icon = "";
self.ItemLink = "|Hitem:33BF1|h|cff0000ff[Empty]|r|h";
self.Durability = 0;
self.MaxDurability = 0;
self.Quality = 0; -- 0 = white / 1 = green / 2 = blue / 3 = purple / 4 = orange / 5 = gold
self.Value = 0;
self.Worth = 0;
self.InUse = false;
self.BoundStatus = 1; -- 0 = bound on pickup, 1 = not bound, 2 = binds on equip 3 = binds on equip and bound
self.RequiredLvl = 0;
self.CoolDownTime = 0;
self.LastTimeUsed = 0;
self.MaxStack = 0;
self.ObjType = 0;
self.ObjSubType = 0;
self.ObjSubSubType = 0;
self.Stats = {}; -- list of named stats and their ids.
self.* is all that matters
so
self.Worth
self.Stats
self.Name
self.SlotNumber
and so on.
So with the code I posted earlier you can take it further and do
item.Worth
item.Stats
item.Name
item.SlotNumber
and so on.
Hope that clears things up for you =)
Re: Q: How to get item's bag-slot-number?
Posted: Tue Nov 08, 2011 12:12 pm
by kkulesza
Great advice. Thx a lot lisa