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.
Local player information on multiplayer
Re: Local player information on multiplayer
Code: Select all
local local_player = game.players[event.player_index]
Re: Local player information on multiplayer
That's not the local player thoughDaveMcW wrote:I'm not sure why you want to save it... every interesting event should provide its own player_index.Code: Select all
local local_player = game.players[event.player_index]

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.
Re: Local player information on multiplayer
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
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
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.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
These 2 events (and others) are coming in 0.13
Re: Local player information on multiplayer
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
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.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: Local player information on multiplayer
It's a save based unique player identifier.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?
Re: Local player information on multiplayer
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)orzelek wrote:It's a save based unique player identifier.
