Cleanly take item from the inventory into the cursor

Place to get help with not working mods / modding interface.
User avatar
daydev
Inserter
Inserter
Posts: 34
Joined: Sat Apr 18, 2015 5:32 pm
Contact:

Cleanly take item from the inventory into the cursor

Post 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.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Cleanly take item from the inventory into the cursor

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Bilka
Factorio Staff
Factorio Staff
Posts: 3318
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Cleanly take item from the inventory into the cursor

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
daydev
Inserter
Inserter
Posts: 34
Joined: Sat Apr 18, 2015 5:32 pm
Contact:

Re: Cleanly take item from the inventory into the cursor

Post 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 
Bilka
Factorio Staff
Factorio Staff
Posts: 3318
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Cleanly take item from the inventory into the cursor

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Post Reply

Return to “Modding help”