Q: How to get item's bag-slot-number?

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
kkulesza
Posts: 150
Joined: Fri May 27, 2011 9:00 pm
Location: Poland

Q: How to get item's bag-slot-number?

#1 Post by kkulesza » Tue Nov 08, 2011 6:22 am

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

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Q: How to get item's bag-slot-number?

#2 Post by lisa » Tue Nov 08, 2011 6:37 am

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.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

kkulesza
Posts: 150
Joined: Fri May 27, 2011 9:00 pm
Location: Poland

Re: Q: How to get item's bag-slot-number?

#3 Post by kkulesza » Tue Nov 08, 2011 6:49 am

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

User avatar
Nero
Posts: 98
Joined: Wed Aug 10, 2011 9:07 am

Re: Q: How to get item's bag-slot-number?

#4 Post by Nero » Tue Nov 08, 2011 7:04 am

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.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Q: How to get item's bag-slot-number?

#5 Post by rock5 » Tue Nov 08, 2011 8:07 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

kkulesza
Posts: 150
Joined: Fri May 27, 2011 9:00 pm
Location: Poland

Re: Q: How to get item's bag-slot-number?

#6 Post by kkulesza » Tue Nov 08, 2011 8:33 am

rock5 wrote: If you look at Lisas example it uses "item.SlotNumber"...
My mistake.
Thx for pointig it rock5.
Thx for help lisa.

kkulesza
Posts: 150
Joined: Fri May 27, 2011 9:00 pm
Location: Poland

Re: Q: How to get item's bag-slot-number?

#7 Post by kkulesza » Tue Nov 08, 2011 8:38 am

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"

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Q: How to get item's bag-slot-number?

#8 Post by lisa » Tue Nov 08, 2011 9:59 am

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 =)
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

kkulesza
Posts: 150
Joined: Fri May 27, 2011 9:00 pm
Location: Poland

Re: Q: How to get item's bag-slot-number?

#9 Post by kkulesza » Tue Nov 08, 2011 12:12 pm

Great advice. Thx a lot lisa

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 0 guests