Page 1 of 1

Detect if multiplayer or singleplayer

Posted: Fri Sep 23, 2016 1:44 pm
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.

Re: Detect if multiplayer or singleplayer

Posted: Fri Sep 23, 2016 1:52 pm
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.

Re: Detect if multiplayer or singleplayer

Posted: Fri Sep 23, 2016 4:18 pm
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.