How to do do kill and respawn?

Options
Hi,

I want to implement killing a player (by disabling it) and respawning him after a set amount of time. I know I should use RPCs to do so because this needs to happen on every client but don't know this: "How to tell every client that this specific player is died and needs to respawn after a set amount of time."

My current code for this section is this:

protected override void OnPlayerKill(PlayerController hitmanPlayerController, PlayerController victimPlayerController)
{
if (PhotonNetwork.isMasterClient)
{
base.OnPlayerKill(hitmanPlayerController, victimPlayerController);

//victimPlayerController.Kill();
GetComponent().RPC("DisablePlayerAndEnableItAfterTime_Driver", PhotonTargets.All, 3f);

GameManager.Instance.IncreasePlayerRoundScore(hitmanPlayerController.PlayerId, 1);
}
}

[PunRPC]
protected void DisablePlayerAndEnableItAfterTime_Driver(float t)
{
StartCoroutine("DisablePlayerAndEnableItAfterTime", t);
}

IEnumerator DisablePlayerAndEnableItAfterTime(float t)
{
gameObject.SetActive(false);

yield return new WaitForSeconds(t);

gameObject.SetActive(true);
}

I'm testing against IsMasterClient so only the master client be able to do these sensitive things to prevent cheating.

Comments

  • Aidin
    Options
    Thanks xXGriMe, I've actually seen those 3 part videos but it won't work for me. Because in that tutorial, Mike destroys the player that is killed by PhotonNetwork.Destroy which automatically destroys the player on all clients, that's why he didn't need an RPC call.

    But I want to disable my player and enable it after a few seconds and this needs to happen on all players' machines.

    Also I was thinking maybe this should happen automatically but this might not happen due to problems in calculations on other machines.
  • vadim
    Options
    If player's client stays in room all the time, send "Disable" RPC and, after timeout, "Enable" RPC to all other clients. Others disable / enable player's object locally.