Page 1 of 1

on_pre_player_cursor_stack_changed

Posted: Sun Aug 30, 2020 9:45 pm
by Xorimuth
Similar to viewtopic.php?f=221&t=86422&p=500583

I'd like to change the item that a player is holding (triggered by `on_player_cursor_stack_changed` or some other event), but I want to be able to change it back again when the player returns it to their inventory _or any other inventory_. I can listen to `on_player_main_inventory_changed` for the player's inventory, but not for arbitrary inventories. I can't just look at LuaControl::cursor_stack because it doesn't exist at the point that `on_player_cursor_stack_changed` is triggered in this scenario.

The alternative is to let `on_player_cursor_stack_changed` also return the `LuaItemStack` of the replaced item.

Re: on_pre_player_cursor_stack_changed

Posted: Mon Aug 31, 2020 8:07 pm
by Rseding91
This isn't really possible. The event fires long after the item has been changed and any number of other things could have happened to the item. The game simply sets a flag that the cursor stack was changed this or last tick and when it next updates it sends the event.

Re: on_pre_player_cursor_stack_changed

Posted: Mon Aug 31, 2020 8:25 pm
by Xorimuth
Rseding91 wrote: Mon Aug 31, 2020 8:07 pm This isn't really possible. The event fires long after the item has been changed and any number of other things could have happened to the item. The game simply sets a flag that the cursor stack was changed this or last tick and when it next updates it sends the event.
Thanks for the response. Presumably `on_player_inserted_into_inventory -> player_index, inventory` wouldn't be possible either? That would pretty much solve the same problem for me.