Jump to content

Selecting amount of item


Dr_Cox1911

Recommended Posts

  • 1 month later...

Still not sure if I understand correctly, but if you want to access the items the player has selected you'll need to do something like this:

 

----- Creates a context menu entry when the player selects-- an inventory container (e.g. hiking bag).-- @param _player - The player who clicked the menu.-- @param _context - The context menu to add a new option to.-- @param _items - A table containing the clicked items / stack.--local function createMenu(_player, _context, _items)	local itemTable = _items; -- The table containing the clicked items.	local context = _context;	local player = getSpecificPlayer(_player);	-- We iterate through the table of clicked items. We have	-- to seperate between single items, stacks and expanded	-- stacks.	for i1 = 1, #itemTable do		local item = itemTable[i1];		if instanceof(item, "InventoryItem") and instanceof(item, "InventoryContainer") then			doAwesomeStuff()		elseif type(itemTable[i1]) == "table" then			-- We start to iterate at the second index to jump over the dummy			-- item that is contained in the item-table.			for i2 = 2, #itemTable[i1].items do				local item = itemTable[i1].items[i2];				if instanceof(item, "InventoryItem") and instanceof(item, "InventoryContainer") then					doAwesomeStuff()				end			end		end	endend-- -------------------------------------------------- Game Hooks-- ------------------------------------------------Events.OnPreFillInventoryObjectContextMenu.Add(createMenu);

It is a bit complicated, but this is every possible situation for the item selection (afaik):

local function table()	-- One item	local clickedItems = {		[1] = Inventory.Item;	}	-- Stack (folded)	local clickedItems = {		table = {			[1] = DummyItem;			[2] = Inventory.Item;			[3] = Inventory.Item;			[4] = Inventory.Item;			[5] = "..."		}	}	-- Stack (unfolded)	local clickedItems = {		[1] = DummyItem;		[2] = Inventory.Item;		[3] = Inventory.Item;		[4] = Inventory.Item;		[5] = "...";	}	-- Multiple Stacks selected	local clickedItems = {		table1 = {			[1] = DummyItem;			[2] = Inventory.Item;			[3] = Inventory.Item;			[4] = Inventory.Item;			[5] = "..."		},		table2 = {			[1] = DummyItem;			[2] = Inventory.Item;			[3] = Inventory.Item;			[4] = Inventory.Item;			[5] = "..."		},		table3 = {			"..."		},		"..."	}end
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...