Mods and Multiplayer

Place to get help with not working mods / modding interface.
Kexík
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Dec 01, 2014 12:52 pm
Contact:

Mods and Multiplayer

Post by Kexík »

Hi, i have question about current state of modding in general. How are mods and multiplayer right now? Will still mods that doing stuff in OnTick event cause desyc or is only thing (except rare situations) that mod can do is lagging? From brief search almost no mod stating if its MP compatible is there somewhere list of MP compatible mods?
SirRichie
Fast Inserter
Fast Inserter
Posts: 244
Joined: Wed Feb 25, 2015 4:50 pm
Contact:

Re: Mods and Multiplayer

Post by SirRichie »

I think there are multiple questions in one post here, I am trying to address each of them:

MP compatibility and de-syncs:
You can do stuff in OnTick in your mod. The important thing to keep in mind is that when one player does something that triggers the logic of your mod (e.g., build something, or cause an ontick event (which the player cannot prevent, but you get the idea)), then the mod logic will be executed on all client machines independently. If this execution leads to different game states, this will cause a desync. Example:
- If you make a mod that places 100 copper plates into the inventory of a player who places a building, your mod will be MP compatible.
- If you make a mod that places a random amount of copper plates into the inventory of a player who places a building, it depends:
-- if you initialize your RNG with a seed that is your system's current microseconds (the default way), it is very likely that players have different seeds and therefore generate different random number sequences --> desync
-- if you use lua's default RNG but ensure that the seed is the same for all players (e.g., by letting it depend on say the number of trees in a certain area), it is very likely that you will get a desync. The reason is that lua's default RNG uses the standard C RNG, which behaves differently across versions, processor architectures, operating systems, etc.
-- if you use a lua-only implementation of an RNG and ensure that the seed is the same for all players, it is likely that you will not get desyncs

Other sources for desyncs are a different iteration order through lists (e.g., (k,v) in pairs(...)). Where iteration order may change the result, you should use ipairs(...)


The reason why almost no mod states that it is MP compatible is the high testing overhead for ensuring that it truly is. Which is also why there is currently no list of MP compatible mods.
Kexík
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Dec 01, 2014 12:52 pm
Contact:

Re: Mods and Multiplayer

Post by Kexík »

Ok thank you
User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: Mods and Multiplayer

Post by L0771 »

A big part of MP compatibility is change all "game.player", this sentence isn't compatible with MP.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14281
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Mods and Multiplayer

Post by Rseding91 »

SirRichie wrote:I think there are multiple questions in one post here, I am trying to address each of them:

MP compatibility and de-syncs:
You can do stuff in OnTick in your mod. The important thing to keep in mind is that when one player does something that triggers the logic of your mod (e.g., build something, or cause an ontick event (which the player cannot prevent, but you get the idea)), then the mod logic will be executed on all client machines independently. If this execution leads to different game states, this will cause a desync. Example:
- If you make a mod that places 100 copper plates into the inventory of a player who places a building, your mod will be MP compatible.
- If you make a mod that places a random amount of copper plates into the inventory of a player who places a building, it depends:
-- if you initialize your RNG with a seed that is your system's current microseconds (the default way), it is very likely that players have different seeds and therefore generate different random number sequences --> desync
-- if you use lua's default RNG but ensure that the seed is the same for all players (e.g., by letting it depend on say the number of trees in a certain area), it is very likely that you will get a desync. The reason is that lua's default RNG uses the standard C RNG, which behaves differently across versions, processor architectures, operating systems, etc.
-- if you use a lua-only implementation of an RNG and ensure that the seed is the same for all players, it is likely that you will not get desyncs

Other sources for desyncs are a different iteration order through lists (e.g., (k,v) in pairs(...)). Where iteration order may change the result, you should use ipairs(...)


The reason why almost no mod states that it is MP compatible is the high testing overhead for ensuring that it truly is. Which is also why there is currently no list of MP compatible mods.
Factorio doesn't allow you to read system time and the math.random uses the determistic Factorio random based off the save game. That means you can use math.random all you want and it won't break the game or cause desyncs.

Also, pairs and ipairs are all fine in Factorio - Factorio uses a custom version of pairs and ipairs that is determistic so the iteration order is guaranteed.

Really the only things that break mods in MP is local-to-script-scope variables being misused and not properly storing information in glob so it gets serialized between saves.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding help”