Page 1 of 1

Cleanly take item from the inventory into the cursor

Posted: Wed Mar 13, 2019 6:42 pm
by daydev
The idea is to look for a certain item in the player inventory and if it's there, place it into the cursor.

I figured out this:

Code: Select all

local stuff = inv.find_item_stack("item-name")
if stuff then
	player.clean_cursor()
	player.cursor_stack.set_stack(stuff)
	player.remove_item(stuff)
end 
And it seems to work fine, but it works the old way where the item disappears from the inventory. How do I do it the new nice way where the placeholder "hand" appears in place of the taken item? I looked in the API reference and I found how to set an item filter in place of the taken item, but not the special "hand" placeholder.

Re: Cleanly take item from the inventory into the cursor

Posted: Thu Mar 14, 2019 1:40 pm
by bobingabout
moving an item stack from one inventory to another is something I'd like to see cleanly. AFAIK, currently, there's no easy way to move items with their own inventory, like power armor etc. I may be mistaken though, your code might do just that.

Re: Cleanly take item from the inventory into the cursor

Posted: Thu Mar 14, 2019 2:11 pm
by Bilka
bobingabout wrote: Thu Mar 14, 2019 1:40 pm moving an item stack from one inventory to another is something I'd like to see cleanly. AFAIK, currently, there's no easy way to move items with their own inventory, like power armor etc. I may be mistaken though, your code might do just that.
That is what https://lua-api.factorio.com/latest/Lua ... swap_stack is for.

Re: Cleanly take item from the inventory into the cursor

Posted: Thu Mar 14, 2019 3:09 pm
by daydev
Bilka wrote: Thu Mar 14, 2019 2:11 pm That is what https://lua-api.factorio.com/latest/Lua ... swap_stack is for.
I tried swap_stack too, it still doesn't leave the "hand" placeholder in the player inventory if I do either

Code: Select all

local stuff = inv.find_item_stack("item-name")
if stuff then
	player.clean_cursor()
	player.cursor_stack.swap_stack(stuff)
end 
OR

Code: Select all

local stuff = inv.find_item_stack("item-name")
if stuff then
	player.clean_cursor()
	stuff.swap_stack(player.cursor_stack)
end 

Re: Cleanly take item from the inventory into the cursor

Posted: Thu Mar 14, 2019 3:15 pm
by Bilka
I was replying to bob, not you. I don't know of a way to make "the hand" work with lua item manipulation off the top of my head. You will probably have better luck in just making a modding interface request to be able to change things about the hand from lua.