Page 1 of 1

Local player information on multiplayer

Posted: Thu Mar 31, 2016 10:19 pm
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.

Re: Local player information on multiplayer

Posted: Fri Apr 01, 2016 12:06 am
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.

Re: Local player information on multiplayer

Posted: Fri Apr 01, 2016 7:11 am
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.

Re: Local player information on multiplayer

Posted: Sat Apr 02, 2016 1:24 pm
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

Re: Local player information on multiplayer

Posted: Sat Apr 02, 2016 2:01 pm
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

Re: Local player information on multiplayer

Posted: Sat Apr 02, 2016 2:50 pm
by lyravega
Hmm, I see. I should move it to global then. I didn't know global was saved with the save. Thanks!

Re: Local player information on multiplayer

Posted: Sun Apr 03, 2016 12:04 am
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?

Re: Local player information on multiplayer

Posted: Sun Apr 03, 2016 12:03 pm
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.

Re: Local player information on multiplayer

Posted: Sun Apr 03, 2016 12:28 pm
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