Page 1 of 1

game.multiplayer

Posted: Fri Sep 23, 2016 1:56 pm
by aubergine18
For mods, it would be useful if there was a `game.multiplayer` property to differentiate between MP and SP games.

Using #players <= 1 isn't reliable as MP games can potentially have periods where there's just one player. Likewise, the player.admin has some edge cases (like when loading an MP save in SP mode).

Background: viewtopic.php?f=25&t=33263

Re: game.multiplayer

Posted: Fri Sep 23, 2016 4:01 pm
by Klonan
I don't see why you would need to know whether the game is multiplayer or singleplayer

Re: game.multiplayer

Posted: Fri Sep 23, 2016 4:27 pm
by hoho
Klonan wrote:I don't see why you would need to know whether the game is multiplayer or singleplayer
An obvious case would be to turn off mods that enable in-game forces setup via some gui. Having less clutter on screen is never bad.

Fairly certain there are other mods out there that only make sense in MP.

[edit]

Another nice thing to have would be to be able to detect if it's freeplay or a scenario. E.g I'd prefer not to have mods that modify starting inventory to interfere with scenarios.

Re: game.multiplayer

Posted: Fri Sep 23, 2016 5:38 pm
by aubergine18
Looks like there's a way to determine if game is SP or MP via certain events: viewtopic.php?p=209277#p209277

Re: game.multiplayer

Posted: Fri Sep 23, 2016 10:04 pm
by aubergine18
BTW, reason I personally wanted to do it: In a mod I'm working on, I want player in SP game to have a lootable ship wreck, whereas if used in MP game that would be impractical and just get the lootable items immediately in their inventory.

Re: game.multiplayer

Posted: Fri Sep 23, 2016 10:07 pm
by DaveMcW
Seems easy enough to set a global.looted flag in on_player_created. Then give every other player the items in their inventory.

Re: game.multiplayer

Posted: Sat Sep 24, 2016 1:27 am
by AntiElitz
aubergine18 wrote:For mods, it would be useful if there was a `game.multiplayer` property to differentiate between MP and SP games.
Using #players <= 1 isn't reliable as MP games can potentially have periods where there's just one player. Likewise, the player.admin has some edge cases (like when loading an MP save in SP mode).
Background: viewtopic.php?f=25&t=33263

I need this as well, would appreciate it!

Re: game.multiplayer

Posted: Thu May 25, 2017 5:23 pm
by Mooncat
I have recently encountered a problem about a local save of a multiplayer game being loaded in singleplayer mode:
My custom permission system in Creative Mode determined the player as non-admin (not the first player in the game, player.index is 8 and player.admin is false), hence he cannot access some admin-only features.
I have also tried to check game.player.connected, but it is true.

The problem can be easily fixed if there is a way to determine if the current game is singleplayer mode, so I can grant the local player full access to all features. :)

Re: game.multiplayer

Posted: Fri May 26, 2017 8:02 pm
by Mooncat
2 new ideas to solve the problem:
1) player.admin always returns true in singleplayer mode, or
2) allow mods to change the value of player.admin (e.g. player.admin [RW], or LuaPlayer::promote_player(player) + LuaPlayer::demote_player(player), etc.)