MultiPlayer - NetworkPlayer Event


I’m working on the bits of my network game of when someone quits or leaves. Basically, the game is a ‘capture the flag’ type game, and I want to call a function when the player has the flag, and then quits… So the flag is ‘dropped’, instead of being destroyed with the player.

The function is attached to the actual character, and I’m struggling to talk to it.

So, when someone leaves, this function is called:

function OnPlayerDisconnected (player : NetworkPlayer){

This is on a game object on my root. I need to somehow use the ‘player’ as a reference to find the ‘character’ to then call the function attached to him.

The function is an RPC and is called DropFlag, and is on a script called ‘HealthSystem’, and is attached to my character:

networkView.RPC("DropFlag", RPCMode.AllBuffered, player.viewID);

So, what I really need to do is something like this:

var character = player.FindObject("Player");
var health = character.GetComponent(HealthSystem);
health.networkView.RPC("DropFlag", RPCMode.AllBuffered, player.viewID);

This ‘DropFlag’ works, its also called when you kill the player with the flag… He drops it, and spawns somewhere else, without the flag.

It could be that the game object/component has already been destroyed? Could you try calling it from the OnDestroy if the player has the flag?

OnPlayerDisconnected is only handled on the host.