Page 1 of 1

LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Posted: Wed Feb 27, 2019 12:48 am
by dewiniaid
Currently, there is no mechanism for a mod to select an item in the player's inventory using the exact same logic as a player clicking it. The current 'cleanest' method appears to be some variation upon:

Code: Select all

stack = player.get_inventory(defines.inventory.inventory_main)[index]
if player.clean_cursor() then
   player.cursor_stack.swap_stack(index)
end
However, this has a few problems:
  • There is no hand in the inventory, thus the space for the newly selected item is not reserved.
  • There is no guarantee the selected item will be returned to the same inventory slot after it is 'dropped'. (Mostly pertinent to manually-sorted inventories.)
  • It's far too easy for a mod author to accidentally destroy inventory contents (i.e. by forgetting to check if clean_cursor() actually succeeded.)

Note: I had previously requested a LuaPlayer::set_selected_index. There used to be a LuaPlayer::get_selected_index, but that appears to be gone as of 0.17

Re: LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Posted: Thu Feb 20, 2020 2:54 am
by raiguard
Bump. I'm working on inventory and cursor stack synchronization between the editor and normal play, and when the inventory gets transferred when you switch, the hand disappears. It would be nice if I could set a stack to be the "hand" so that parity is maintained when switching modes.

Re: LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Posted: Thu Feb 20, 2020 5:10 pm
by Rseding91
Raiguard wrote:
Thu Feb 20, 2020 2:54 am
Bump. I'm working on inventory and cursor stack synchronization between the editor and normal play, and when the inventory gets transferred when you switch, the hand disappears. It would be nice if I could set a stack to be the "hand" so that parity is maintained when switching modes.
Off topic, that made me chuckle :D The editor specifically goes out of its way to avoid having the "normal" gameplay and items be polluted by the "editor" version and vice versa.

Re: LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Posted: Fri Feb 21, 2020 5:44 pm
by raiguard
Rseding91 wrote:
Thu Feb 20, 2020 5:10 pm
Off topic, that made me chuckle :D The editor specifically goes out of its way to avoid having the "normal" gameplay and items be polluted by the "editor" version and vice versa.
Yeah, normally I agree that having the editor and normal play be separated is a good thing. But many people want to be able to use a character and only use the editor when needed, so I'm making that playstyle easier.

By default, the feature is off. It's only active if the player is in cheat mode.

Re: LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Posted: Fri Feb 21, 2020 6:03 pm
by eradicator
Huh, looks similar to my request (which was originally modding help): viewtopic.php?f=28&t=77097

+1

Re: LuaPlayer::get_hand_index / LuaPlayer::set_hand_index or similar

Posted: Wed Jul 15, 2020 1:35 pm
by Jorn86
From the changelog description, I was hoping this would give me a way to read the player's actual mouse cursor without them triggering an action (like use capsule).

Oh well.