Local player information on multiplayer

Place to get help with not working mods / modding interface.
Post Reply
lyravega
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Mon Jan 06, 2014 4:41 pm
Contact:

Local player information on multiplayer

Post by lyravega »

Is there a way to get access to local player information on multiplayer? Like, your player name so the player array can be sifted through, and the local player index can be found?

Another thing I tried is using "on_player_created" event. I thought I can use this as some sort of initializer; register this event, on the handler get the event.player_index and save it, then unregister the event right after saving it in the handler so it won't be fired in the future.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Local player information on multiplayer

Post by DaveMcW »

Code: Select all

local local_player = game.players[event.player_index]
I'm not sure why you want to save it... every interesting event should provide its own player_index.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13219
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Local player information on multiplayer

Post by Rseding91 »

DaveMcW wrote:

Code: Select all

local local_player = game.players[event.player_index]
I'm not sure why you want to save it... every interesting event should provide its own player_index.
That's not the local player though :P

From a mod perspective there's no reason to ever want to know which player is "local". From the console perspective you can use local_player to reference your self.
If you want to get ahold of me I'm almost always on Discord.

lyravega
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Mon Jan 06, 2014 4:41 pm
Contact:

Re: Local player information on multiplayer

Post by lyravega »

I had a brain fart the other day. To simply put it, I needed such a thing to filter events based on a player.

In short, in my mod, some variables are held in a table. However on multiplayer, this table will get overwritten when other players do stuff that fires the events that my mod listens to as well, and I was trying to avoid such a thing. Instead I adapted my stuff to create a table for each connected player. It should be more healthy on the long run.

Question: the desync issues are generally caused by the same code producing different results, is this correct? In addition, will having a table that has different sizes for each player cause any issues at all?

A table that'll fit the additional question is something like this for example: player names are keys, and all the values are true. When you connect to a server, all the connected players are added to this table. When someone joins to the server, on_player_created event adds to this table. However, when someone lefts the server, and then someone else connects to it, this table will be different for the player who joined the last (because as far as I can tell, there is no event to use when a player leaves the server). Will this cause an issue, so to speak?

If it can cause desync errors, can we get some events such as these:

player_joined: contains event.player - LuaPlayer
player_left: contains event.player - LuaPlayer, and reason - such as losing connection or leaving the game

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Local player information on multiplayer

Post by Choumiko »

lyravega wrote:However, when someone lefts the server, and then someone else connects to it, this table will be different for the player who joined the last (because as far as I can tell, there is no event to use when a player leaves the server). Will this cause an issue, so to speak?

If it can cause desync errors, can we get some events such as these:

player_joined: contains event.player - LuaPlayer
player_left: contains event.player - LuaPlayer, and reason - such as losing connection or leaving the game
If the table is stored in global (e.g. global.playerdata) it won't cause a desync, since the connecting player downloads the save and therefore the latest global too.
These 2 events (and others) are coming in 0.13

lyravega
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Mon Jan 06, 2014 4:41 pm
Contact:

Re: Local player information on multiplayer

Post by lyravega »

Hmm, I see. I should move it to global then. I didn't know global was saved with the save. Thanks!

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Local player information on multiplayer

Post by Adil »

Hm, this gets me now: is the player_index specific unique identifier, or is it just counter game assigns as the new player connects?
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Local player information on multiplayer

Post by orzelek »

Adil wrote:Hm, this gets me now: is the player_index specific unique identifier, or is it just counter game assigns as the new player connects?
It's a save based unique player identifier.

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Local player information on multiplayer

Post by Choumiko »

orzelek wrote:It's a save based unique player identifier.
It get's wierd in multiplayer though, if you change your name to one of another player and join while he is offline you join as him (i believe) :D 0.13 will solve that i think

Post Reply

Return to “Modding help”