How to get multiplayer name?

Place to get help with not working mods / modding interface.
User avatar
MisterBrownZA
Burner Inserter
Burner Inserter
Posts: 8
Joined: Mon Nov 02, 2015 7:10 am
Contact:

How to get multiplayer name?

Post by MisterBrownZA »

Greetings everyone,

I eventually decided to join the forum - as I can't find any questions/answers relating to my problem.

I'd like to access game.players - multiplayer name for each player who has joined.

I hope someone can help me with this
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to get multiplayer name?

Post by prg »

MisterBrownZA wrote:Greetings everyone,

I eventually decided to join the forum - as I can't find any questions/answers relating to my problem.

I'd like to access game.players - multiplayer name for each player who has joined.

I hope someone can help me with this

Code: Select all

for _, v in pairs(game.players) do game.local_player.print(v.name) end
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
MisterBrownZA
Burner Inserter
Burner Inserter
Posts: 8
Joined: Mon Nov 02, 2015 7:10 am
Contact:

Re: How to get multiplayer name?

Post by MisterBrownZA »

prg wrote:

Code: Select all

for _, v in pairs(game.players) do game.local_player.print(v.name) end
Amazing! So easy!

Quick question. I couldn't find local_player.print() method in the wiki, so wasn't sure how I was supposed to do this.

I'll try this when I get home tonight.

I'm guessing v.name returns the player's "get_localised_entity_name"
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: How to get multiplayer name?

Post by prg »

MisterBrownZA wrote:Quick question. I couldn't find local_player.print() method in the wiki, so wasn't sure how I was supposed to do this.
Lua/Game#local_player
Lua/Player#print
MisterBrownZA wrote:I'm guessing v.name returns the player's "get_localised_entity_name"
That contains whatever the player entered in options -> other -> multiplayer username. localised_name is only a thing for entities, like the player's character, but that only ever says "player" so it's not very interesting.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
User avatar
MisterBrownZA
Burner Inserter
Burner Inserter
Posts: 8
Joined: Mon Nov 02, 2015 7:10 am
Contact:

Re: How to get multiplayer name?

Post by MisterBrownZA »

prg wrote:
MisterBrownZA wrote:Quick question. I couldn't find local_player.print() method in the wiki, so wasn't sure how I was supposed to do this.
Lua/Game#local_player
Lua/Player#print
MisterBrownZA wrote:I'm guessing v.name returns the player's "get_localised_entity_name"
That contains whatever the player entered in options -> other -> multiplayer username. localised_name is only a thing for entities, like the player's character, but that only ever says "player" so it's not very interesting.
Bravo. Everything worked perfectly!

Thanks a lot prg!
Post Reply

Return to “Modding help”