Sending info from MasterClient on player connection

Hello!
I've been learning some PUN lately, and I've gotten into some real problem (for a beginner of course). Im trying to make MasterClient send info about some spawn points, taken colours etc. to every player joining the room. I've written such code to archive it(in this case we just send index of a boolean array but i think if i'll understand it, i'll be fine):

[code2=csharp]void OnJoinedRoom()
{
GameLayout.SetActive(true);

GameObject newPlayer = PhotonNetwork.Instantiate("player", Vector3.zero, Quaternion.identity, 0);
newPlayer.name = newPlayer.GetComponent<PhotonView>().owner.ID.ToString();
Camera.main.transform.SetParent(newPlayer.transform);
Camera.main.GetComponent<cameraMovement>().target = newPlayer.transform;
newPlayer.GetComponent<PhotonView>().RPC("AskForNumber", PhotonTargets.MasterClient, newPlayer.name);
}[/code2]
And an RPC like that:
[code2=csharp][RPC]
void AskForNumber(string Name)
{
Debug.Log(Name);
GameObject np = GameObject.Find(Name);
SomeRandomScript p = np.GetComponent<SomeRandomScript>();
for (int i = 0; i < 6; i++)
{
if (!isPlaceTaken)
{
p.indexProvided = i.ToString();
isPlaceTaken = true;
break;
}
else if (i == 5)
p.indexProvided = "-1";
}
}[/code2]

It does work 'fine' on first player joining, so if i set isPlaceTaken to {true, true, false, false, false, false} he gets indexProvided 2 in his SomeRandomScript and in Debug.Log we get name of the object, but for every following player RPC doesn't work, it won't even Log.

Could anyone give me some kind of enlightment or at least a little hint how to make it work? I feel like working so much time on such little trouble made my brain vanish.
Thank you,
roiek

Comments

  • Hi,

    So RPC is not executed on master. Can you check also with log if RCP() called on sender site?
    Are you sure that script with OnJoinedRoom is attached to one of the objects in scene?
    Do you have any errors or warnings in log?
  • Hey!
    Thank you for your reply! I managed to make it work via OnPhotonPlayerConnect() callback, now the problem is how to free the array's position on MasterClient on player's Disconnect. at first i tried to do it like that:

    [code2=csharp]void OnPhotonPlayerDisconnect(PhotonPlayer pP)
    {
    bul[int.Parse(pP.customProperties["pos"].ToString())]=false;
    }[/code2]

    but it didn't work. then I just tried to Log anything via OnPhotonPlayerDisconnect() but I don't get anything. Is it possible that the cause of this problem is not having a proper Disconnect button, and I disconnect my players thru closing the tab of my WebPlayer? Or maybe I missunderstood something about that particulalr callback?
    EDIT:
    I put OnPhotonPlayerDisconnect() in NetworkManager script in NetworkManager object directly on the scene.

    roiek.
  • Did you try to disconnect clients with PhotonNetwork.leaveRoom?
    Form OnPhotonPlayerDisconnected documentation:
    /// When your client calls PhotonNetwork.leaveRoom, PUN will call this method on the remaining clients.
    /// When a remote client drops connection or gets closed, this callback gets executed. after a timeout
    /// of several seconds.