How to make MP-compatible mod?

Place to post guides, observations, things related to modding that are not mods themselves.
Eliont
Burner Inserter
Burner Inserter
Posts: 19
Joined: Thu Feb 16, 2017 3:48 pm
Contact:

How to make MP-compatible mod?

Post by Eliont »

Hello and good time of day.

How to ensure that (existing, my own) mod work well in multiplayer?
Many scripting, many new entities.

Is there some recomedndations somewhere?

Thanks in advance.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14363
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: How to make MP-compatible mod?

Post by Rseding91 »

Just a few things:
  • Store all of your mutable variables in the "global" table. If you don't know what mutable means - just store all of your variables in the "global" table.
  • Only run code in reaction to a event
  • Make sure you don't mutate things in the on_load event. If you don't know what that means just avoid the on_load event.
Past that, it should 'just work'.
If you want to get ahold of me I'm almost always on Discord.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: How to make MP-compatible mod?

Post by bobingabout »

use game.players[#]. instead of game.player.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
Bilka
Factorio Staff
Factorio Staff
Posts: 3310
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How to make MP-compatible mod?

Post by Bilka »

bobingabout wrote:use game.players[#]. instead of game.player.
game.player also doesn't work in singleplayer... it's only available from the console, nowhere else
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: How to make MP-compatible mod?

Post by bobingabout »

Bilka wrote:
bobingabout wrote:use game.players[#]. instead of game.player.
game.player also doesn't work in singleplayer... it's only available from the console, nowhere else
you'd be surprised how many mods fail to work because they've used game.player in their scripting.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.
ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: How to make MP-compatible mod?

Post by ratchetfreak »

bobingabout wrote:use game.players[#]. instead of game.player.
but don't ever hardcode game.players[1], instead either loop over all players or use the player involved in whatever event that triggered the code
Post Reply

Return to “Modding discussion”