Detect if multiplayer or singleplayer

Place to get help with not working mods / modding interface.
AntiElitz
Filter Inserter
Filter Inserter
Posts: 458
Joined: Sat Aug 29, 2015 11:37 pm
Contact:

Detect if multiplayer or singleplayer

Post by AntiElitz »

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.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Detect if multiplayer or singleplayer

Post by aubergine18 »

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.
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.
credomane
Filter Inserter
Filter Inserter
Posts: 311
Joined: Tue Apr 12, 2016 6:21 pm
Contact:

Re: Detect if multiplayer or singleplayer

Post by credomane »

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.
Post Reply

Return to “Modding help”