How to track players?

I have searched this arround for quite some time without any luck…

I need a simple and quick way of player tracking so that I can just use for example a " Player[0] " and then assign commands to that specific player, like a CloseConnection or similar. How can I achive this? Is there a integrated way of doing it?

I tryed creating this using an array, but whithout much luck.

Here is my code if needed.

var players = new Array();

function Start () {

	if( Network.isServer ){
		player = Network.player;
		networkView.RPC( "AddToList" , RPCMode.AllBuffered );
	}
}

function Update () {
	
	if(Network.isServer ){
		if(Input.GetKeyDown(KeyCode.H))
			Network.CloseConnection( players[0] , true );
	}
}

@RPC
function AddToList () {
	
	players.Add( player );
	Debug.Log( player );
}

@RPC
function RemoveFromList () {
	
	players.RemoveAt( System.Convert.ToInt16(player) );
	Debug.Log( "Player " + player + " has disconnected!" );
}

function OnPlayerConnected ( networkPlayer : NetworkPlayer ) {
	
	player = networkPlayer;
	networkView.RPC( "AddToList" , RPCMode.AllBuffered );
}

function OnPlayerDisconnected ( networkPlayer : NetworkPlayer ){

	player = networkPlayer;
	networkView.RPC( "RemoveFromList" , RPCMode.AllBuffered );
}

Your halfway there.
On the server, add all connecting NetworkPlayers to the array.
If you want the clients also to have them, send an RPC with the NetworkPlayer as a param ( which you aren’t doing ).
And have them also add them to a list.
Then if you want to reach a player directly you can send the RPC to it:

networkView.RPC("MyMethod", NetworkPlayer, params);

I tryed using this way, and it actually works, the only problem is , when a player disconnects, a it prints “Player 1 Has disconnected!” and when I reconnect and then again disconnect, instead of having it shown “Player 1 Has disconnected!” It shows " Player 2 Has disconnected!" , I assume this is because of the fact that the array is not actually removing am I right?

No, that is not necessarily true.
Check Network.connections on the server to see if they disconnect.

They do correctly disconnect. Yet the array is not updated.