playerID increment when clients join

Hi i have a question here.
I am making a multiplayer game, using server and client.

playerID for server is 0, while other clients which join the game increases their playerID by 1. Is it necessary to send RPC function or is there any better methods? Thank You.

var playerID : int = 0;
function Spawn()
{

if(Network.isServer)
{
playerID = 0;
}
else if(Network.isClient)
{
playerID++;
}

}

every player that connections has a NetworkPlayer object automatically assigned with a unique id
you should use that one.

hi again, i have tried the code below. The playerID should sent back to server and update the playerID again. but it doesn’t work. any idea why is it so? thanks.

var currentPlayerID : int;
var networkPlayer : NetworkPlayer;

function OnConnectedToServer()
{
   networkView.RPC( "RequestOwner", RPCMode.Server );
}

@RPC
function RequestOwner( info : NetworkMessageInfo )
{
   networkView.RPC( "SetOwner", info.sender, info.sender );
}

@RPC
function SetOwner( a_owner : NetworkPlayer )
{
   networkPlayer = a_owner;
   currentPlayerID = parseInt( networkPlayer.ToString() );
}

But how?

@DIProgan: Check the script reference on class Network and check its fields. That will show you :slight_smile:

Only been doing that for x hours :stuck_out_tongue: Edit: Just maaybe this NetworkMessageInfo thingy can help out… Edit2: Yup finaly it seems ^^

@RPC
function DoneTyping(text : String, info : NetworkMessageInfo){

number=parseInt(info.sender);
Arr[number]=text;
}

How do I convert the info.sender to a usable int for my array?

Sollution was int.Parse(info.sender.ToString())

Any idea how to disconnect a player by referencing their NetworkPlayer object’s unique ID?

Network.CloseConnection actually expects that you hand it a NetworkPlayer
it does not accept anything else