Is there a way to read weather the game is a Multiplayer or a Singleplayer game? eg. Are there any server options one can read that are not set in singleplayer?
In specific, I want my mod to only give permission for changes to admins in Multiplayer. But there are cases where you load a singleplayer save from someone alse and you are not an admin. So I want to detect Singleplayer to react to this. Counting the players doesn't help, since there could be 1 player on a Multiplayer server as well.
Detect if multiplayer or singleplayer
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Detect if multiplayer or singleplayer
As far as I know there is no guaranteed way to determine if the game is multiplayer.
Most mods I've seen just assume that if #game.players <=1 then single player, but as you pointed out an MP game can have just one player too.
It would be very useful if there was a new `game.multiplayer` property that mods could check, so we can avoid the .admin and #players woo woo.
Most mods I've seen just assume that if #game.players <=1 then single player, but as you pointed out an MP game can have just one player too.
It would be very useful if there was a new `game.multiplayer` property that mods could check, so we can avoid the .admin and #players woo woo.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Detect if multiplayer or singleplayer
Well...due to some changes in 0.14 it is possible to detect single-player from multiplayer with one player as a "one" time only thing.
A mod's on_init and on_configuration_changed will report player.connected as false in single player only. They will be true in multiplayer in on_init and on_configuration_changed with one-player however.
I reported it as a bug but it isn't a bug. 33208
Doubt it would be of any use to you but there's that.
A mod's on_init and on_configuration_changed will report player.connected as false in single player only. They will be true in multiplayer in on_init and on_configuration_changed with one-player however.
I reported it as a bug but it isn't a bug. 33208
Doubt it would be of any use to you but there's that.