Getting player number/index

Hi,

I have been struggling to make a blueprint graph which could let me access the player’s number in a multiplayer LAN RTS game. What I am basically aiming for is a functionality making the actors distinguish which actions are done by which players. For example, a red actor should only listen to a Move Command given by Player 2 and Attack Command given by Player 3, whereas a green actor should only listen to Move Commands from Player 3 and Attack Commands from Player 1. What is the easiest way for the actors’ BPs to properly execute such idea?

As I haven’t managed to find a straightforward node of doing that I thought of some workarounds which do not work unfortunately.

One supposed solution I tried was to get the PlayerID with PlayerState on EventPostLogin in the GameMode BP and as each player that joins the server gets an ID=ID of previous player +1, I tweaked those values to get the players’ numbers. It somehow did not work and maybe that is a good thing since the ID method is not very reliable.

Any other ideas?

As far as I know you have to manually keep the list somewhere … first player is 0 … second is 1 … etc. It is 0 based.

Then you would simply use that index in getPlayerController … which I think you have already figured out.

Basically drive this from when a player joins your server … and allocate the ID … not sure the best way to go about doing this … haven’t gotten this far in my project yet.

Could you tell me why this blueprint does not work?
In Game Mode:


I draw the player number on HUD:

The HUD draws that all of the player numbers are 0.