I want to detect when a player starts a new playing session, so that session specific variables can be set.
on_player_joined_game seems to do the job for multi-player, but there is no event when a single player save is loaded.
As an illustrative example: How would I be able to print "Welcome back" when a save is loaded?
Equivalent event to on_player.joined_game in single player?
Equivalent event to on_player.joined_game in single player?
Attila's QuickBar Mod - Auto-links hand crafted item to first free quickbar slot if not already linked.
Attila's Signals Mod - Alternate signals to use in same circuit as standard signals.
Attila's Zoom Mod - Modifies zoom functionality.
Attila's Signals Mod - Alternate signals to use in same circuit as standard signals.
Attila's Zoom Mod - Modifies zoom functionality.
Re: Equivalent event to on_player.joined_game in single player?
There is no event that allows this.How would I be able to print "Welcome back" when a save is loaded?
In general, "I want to detect when a player starts a new playing session, so that session specific variables can be set." is not possible because it would not be save-load stable, but save-load stability is required for multiplayer, so we do not allow Lua to break it.
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: Equivalent event to on_player.joined_game in single player?
Well, this obviously makes sense to you, but I don't get it.
A player can generate an event by clicking something. On this event I can print "Welcome back", but I can't do this in an event handler automatically when a save is loaded in single player mode?
Why not just send the player_joined_game event when a new session is started by a player - single or mp? The event would be handled the same way in both cases.
A player can generate an event by clicking something. On this event I can print "Welcome back", but I can't do this in an event handler automatically when a save is loaded in single player mode?
Why not just send the player_joined_game event when a new session is started by a player - single or mp? The event would be handled the same way in both cases.
Attila's QuickBar Mod - Auto-links hand crafted item to first free quickbar slot if not already linked.
Attila's Signals Mod - Alternate signals to use in same circuit as standard signals.
Attila's Zoom Mod - Modifies zoom functionality.
Attila's Signals Mod - Alternate signals to use in same circuit as standard signals.
Attila's Zoom Mod - Modifies zoom functionality.
Re: Equivalent event to on_player.joined_game in single player?
I maintain a global.is_multiplayer. You can check that in on_load, if it's off I set a self-cancelling on_tick, otherwise on_player_joined_game, either way I update global.is_multiplayer from game.is_multiplayer() when the selected event fires. So if a saved singleplayer map's being reloaded multiplayer for the first time, the server will do a one-off on_tick when there's no players yet, no desync there, and all players joining will see the updated value and do opjg correctly; if a saved multiplayer map's being loaded singleplayer I don't see how to do the right thing cleanly. You show up as a saved player, the only way I can figure to do it would be to check global.is_multiplayer against game.is_multiplayer() pretty much everywhere and fire the sp-join code on a mismatch. I guess a permanent 5-second nth_tick would be negligible enough overhead.
Re: Equivalent event to on_player.joined_game in single player?
Thanks for the info, I will try this.
Attila's QuickBar Mod - Auto-links hand crafted item to first free quickbar slot if not already linked.
Attila's Signals Mod - Alternate signals to use in same circuit as standard signals.
Attila's Zoom Mod - Modifies zoom functionality.
Attila's Signals Mod - Alternate signals to use in same circuit as standard signals.
Attila's Zoom Mod - Modifies zoom functionality.