game.multiplayer

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

game.multiplayer

Post 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
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.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5304
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: game.multiplayer

Post by Klonan »

I don't see why you would need to know whether the game is multiplayer or singleplayer
hoho
Filter Inserter
Filter Inserter
Posts: 681
Joined: Sat Jan 18, 2014 11:23 am
Contact:

Re: game.multiplayer

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

Re: game.multiplayer

Post by aubergine18 »

Looks like there's a way to determine if game is SP or MP via certain events: viewtopic.php?p=209277#p209277
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.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: game.multiplayer

Post 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.
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.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3730
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: game.multiplayer

Post 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.
AntiElitz
Filter Inserter
Filter Inserter
Posts: 458
Joined: Sat Aug 29, 2015 11:37 pm
Contact:

Re: game.multiplayer

Post 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!
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: game.multiplayer

Post 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. :)
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1196
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: game.multiplayer

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

Return to “Implemented mod requests”