Master client can't scoring player kills

Options
Hi, I'm trying to make simple kill counter for my multiplayer project and i have some trouble about master client kill score. IIf I kill someone in a room while being a master client, the kill doesn't count, but everything works fine for the other clients. Can you tell me what I'm doing wrong in this case?

My code:

public void Die(Vector3 position, Vector3 force, GameObject attacker)
{
var attackerPhotonViewID = -1;
if (attacker != null) {
var attackerPhotonView = attacker.GetCachedComponent<PhotonView>();
if (attackerPhotonView == null) {
Debug.LogError("Error: The attacker " + attacker.name + " must have a PhotonView component.");
return;
}
attackerPhotonViewID = attackerPhotonView.ViewID;

killscore++;
attackerPhotonView.Owner.SetScore(killscore);

}

var attackerPV = attacker.GetCachedComponent<PhotonView>();
if (attackerPV.Owner.IsMasterClient)
{
m_PhotonView.RPC("DieRPC", RpcTarget.MasterClient, position, force, attackerPhotonViewID);
}
else
{
m_PhotonView.RPC("DieRPC", RpcTarget.OthersBuffered, position, force, attackerPhotonViewID);
}

}


[PunRPC]
private void DieRPC(Vector3 position, Vector3 force, int attackerViewID)
{
PhotonView attacker = null;
if (attackerViewID != -1) {
attacker = PhotonNetwork.GetPhotonView(attackerViewID);
}

m_Health.Die(position, force, attacker != null ? attacker.gameObject : null);
}

Comments

  • Good_COmrade
    Options
    I think if I switch master client with an object in scene, then I'll solve the problem But if I trying to do this, I catching Null reference exeption error in Room script on this part

    public bool SetMasterClient(Player masterClientPlayer)
    {
    if (this.isOffline)
    {
    return false;
    }
    Hashtable newProps = new Hashtable() { { GamePropertyKey.MasterClientId, masterClientPlayer.ActorNumber } };
    Hashtable prevProps = new Hashtable() { { GamePropertyKey.MasterClientId, this.MasterClientId } };
    return this.LoadBalancingClient.OpSetPropertiesOfRoom(newProps, prevProps);
    }