Hi,
I suppose that if you want to write a multiplayer compatible mod, you have to do a lot of
"for _, player in ipairs(game.players) do" everywhere instead of just working on the game.player (working only in single player mode)
but if I want to identify the player who is really local, in front of the PC running the game/mod, how can I do this ?
I thought that player.has_game_view() was the good function, but it does not seem to work.
An idea ?
Mod multiplayer, identify local player ?
Mod multiplayer, identify local player ?
My mods on the Factorio Mod Portal
Re: Mod multiplayer, identify local player ?
When you write a mod, all the players are local,binbinhfr wrote:Hi,
I suppose that if you want to write a multiplayer compatible mod, you have to do a lot of
"for _, player in ipairs(game.players) do" everywhere instead of just working on the game.player (working only in single player mode)
but if I want to identify the player who is really local, in front of the PC running the game/mod, how can I do this ?
I thought that player.has_game_view() was the good function, but it does not seem to work.
An idea ?
They are each assigned an index. and you can call individual players like
Code: Select all
game.players[i]
Unless you're doing some really tricky ,awkward, or downright incorrect scripting, your mod should be MP compatible regardless of what you're doing
Re: Mod multiplayer, identify local player ?
I understood the players list, but correct me if i'm wrong :
each user runs one instance of factorio on his own machine, with the exact same configuration than other players, and only GUI commands are exchanged over the network, and you expect that every local client computes the same things as the others and stays in sync ?
So you say that all players are local, but considering one user in front of his PC : he is running his instance of factorio, computing his own player and every other players, but his own player is a little more "local", no ?
So I wonder if there was a way to know whose player is really in front of the client.
I thought that has_game_view() was the purpose of the function : telling which player has really the GUI on this particular PC, running this particular client.
each user runs one instance of factorio on his own machine, with the exact same configuration than other players, and only GUI commands are exchanged over the network, and you expect that every local client computes the same things as the others and stays in sync ?
So you say that all players are local, but considering one user in front of his PC : he is running his instance of factorio, computing his own player and every other players, but his own player is a little more "local", no ?
So I wonder if there was a way to know whose player is really in front of the client.
I thought that has_game_view() was the purpose of the function : telling which player has really the GUI on this particular PC, running this particular client.
My mods on the Factorio Mod Portal
Re: Mod multiplayer, identify local player ?
Each player isnt running his own instance, but they all run the same instance, and only players inputs/actions are sent to eachother.binbinhfr wrote:I understood the players list, but correct me if i'm wrong :
each user runs one instance of factorio on his own machine, with the exact same configuration than other players, and only GUI commands are exchanged over the network, and you expect that every local client computes the same things as the others and stays in sync ?
So you say that all players are local, but considering one user in front of his PC : he is running his instance of factorio, computing his own player and every other players, but his own player is a little more "local", no ?
So I wonder if there was a way to know whose player is really in front of the client.
I thought that has_game_view() was the purpose of the function : telling which player has really the GUI on this particular PC, running this particular client.
When you write a mod you don't need to know which player in the 'local' player, because any action must be scripted as if all other clients are running the same code.
This is why you can only call the players using the players system
If you can give an example of what you're trying to do, i can better give advice
Re: Mod multiplayer, identify local player ?
Klonan, one application I can think of from his questions is, say, you wanted to display a # on the screen of the # of copper in your personal inventory. Not all players inventories or other people, just your own. That'd require a player where i is the player currently playing. Each player would have the same mod/script loaded of course, but each see a different result on their screen.
Re: Mod multiplayer, identify local player ?
roy7 wrote:Klonan, one application I can think of from his questions is, say, you wanted to display a # on the screen of the # of copper in your personal inventory. Not all players inventories or other people, just your own. That'd require a player where i is the player currently playing. Each player would have the same mod/script loaded of course, but each see a different result on their screen.
But for that you would use a function based on the individual player, so you wouldnt show all players the specific inventory count for a single player, but instead base each players screen on their own inventory.
The way its done is when a gui function is called, it shows which player pressed it. With this you can update the gui and run a script for that player only, without having to update anything else for the other players
Re: Mod multiplayer, identify local player ?
ok , thanks Klonan, I understand better.Klonan wrote:But for that you would use a function based on the individual player, so you wouldnt show all players the specific inventory count for a single player, but instead base each players screen on their own inventory.
The way its done is when a gui function is called, it shows which player pressed it. With this you can update the gui and run a script for that player only, without having to update anything else for the other players
I wrote a singleplayer mod, and I understand that it's a big work to go in MP.
Every single variable that I store in global for one single player must be transformed into an array for all players.
As roy said, I thought that for some features that does not involve desync like giving informations in one way only (stats, etc...), there should be any use to duplicate heavy calculations, GUI, messages, etc... So, for such an "info" only mod, I could identify and store the ID of the local player, and only deal with him (assuming that the mod will do the same thing on every other client).
But still, you did not answer my bonus question : what is the has_game_view() function ?
it seems to return true if i'm in single player, but false on all players in MP.
My mods on the Factorio Mod Portal