Changed slots for on_player_*_inventory_changed

Things that we aren't going to implement
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Changed slots for on_player_*_inventory_changed

Post by Pi-C »

We already have events that inform us if ammo, armor, gun, main, or trash inventory of a player have changed. Each event returns the index of the player whose inventory was changed. However, I'd like to be able to get some more precise information: the index of the changed slot, or an array of indexes of changed slots.

Reason: I've added a character selector to minime that allows players to change their character at any time during the game if mods providing alternative characters are active. Some mods provide characters with an extended or a reduced inventory. Switching from a character with a big inventory to one with a small inventory and back could lead to the loss of items. I therefore keep a hidden backup-character for each player, so I can restore the lost slots. If I could pinpoint what slots in an inventory have changed, I could keep the backup in sync with the character by responding to on_player_*_inventory_changed in an efficient way -- without having to copy the complete inventory.

Is there any chance that could be implemented, or would that be impossible for technical reasons?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13175
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Changed slots for on_player_*_inventory_changed

Post by Rseding91 »

Sorry but it's not known which slots changed by the time the Lua event is fired.
If you want to get ahold of me I'm almost always on Discord.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1639
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Changed slots for on_player_*_inventory_changed

Post by Pi-C »

Thanks for the answer! Too bad it doesn't work, it would have been a clean way for making inventory backups. I've found another way now: I only copy inventories now when on_pre_player_died or on_pre_player_left_game trigger.

Small question on the latter: When exactly does it trigger? I guess in multiplayer mode, players can decide to log off at any time. The game definitely would know a player is about to leave if it gets a command from that player. But how about if my Internet connection suddenly died? Would it really trigger as well then? If so, would only the server notice that I've been dropped from the game, or would the event be triggered for all the other players that were on a server on my local copy as well (so that I could save the current game locally)?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Won't implement”