How to run code on exit save
-
- Inserter
- Posts: 22
- Joined: Mon Jun 27, 2016 4:20 pm
- Contact:
How to run code on exit save
Is there a way to run code to change the player's data before quitting the game? I would like to access the game.players[1].get_inventory(defines.inventory.player_armor) and edit it before quitting.
Re: How to run code on exit save
No, because that would not be deterministic.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: How to run code on exit save
In Multiplayer there is:
https://lua-api.factorio.com/latest/eve ... _left_game
However this does not work in single player
Code: Select all
on_pre_player_left_game
However this does not work in single player
Re: How to run code on exit save
Hey, we have solution for multiplayer, but here is no solution for single player while it is not detereministic and makes desync?Klonan wrote: ↑Sat Dec 29, 2018 12:36 pm In Multiplayer there is:https://lua-api.factorio.com/latest/eve ... _left_gameCode: Select all
on_pre_player_left_game
However this does not work in single player
Re: How to run code on exit save
I mean ... what is the point of changing inventory before the player quits singleplayer since the game is literally just about to wipe out the entire game state?
Re: How to run code on exit save
It's nice to get greetings on start or statistics about game session on the game ending today.
-
- Inserter
- Posts: 22
- Joined: Mon Jun 27, 2016 4:20 pm
- Contact:
Re: How to run code on exit save
I was going to do some clean up so that if the player removes the mod it doesn't cause equipment in armor to disappear. My mod mostly changes the equipment in armor dynamically with custom equipement with small modifications. So if the player exited the game I would just swap out the custom equipment with the vanilla equipment. When they load the game swap them back in. That way they won't have missing equipment in armor.
Re: How to run code on exit save
So you'd need to run script before saving starts and after saving finishes + after load. That's not possible in the current API.
-
- Inserter
- Posts: 22
- Joined: Mon Jun 27, 2016 4:20 pm
- Contact:
Re: How to run code on exit save
Now we have migration script that will be running one when the mod is installed. Here was another suggestion - make uninstall migration script, where you write what must be changed after mod was uninstalled.ProfoundDisputes wrote: ↑Sat Dec 29, 2018 10:03 pm I was going to do some clean up so that if the player removes the mod it doesn't cause equipment in armor to disappear. My mod mostly changes the equipment in armor dynamically with custom equipement with small modifications. So if the player exited the game I would just swap out the custom equipment with the vanilla equipment. When they load the game swap them back in. That way they won't have missing equipment in armor.