- Home /
[Photon]Player dies when new player connects
Okay... I'm going to try and make this as painless as possible. I wrote all this code myself. I'm comparing two meshes in a collision elsewhere. The compared collisions are between a weapon and a player's body.
The code below is commented hopefully as much as possible. Here's the issue as a scenario. Player 1 kills player 2. Player 2 posts to player 1 & 2's GUI that player 1 has 1 kill. The player can continue gaining kills over and over. When a new player connects, player 2 posts to player 3 the GUI score for player 1. If player 2 was the only one who died, player 2 dies as player 3 connects. [b] Why does he die?[/b]
A side note, when the player who died disconnects from the server, the scores are erased and put back to nothing. When a new player connects, the GUI stops updating.
private void OnGUI () {
if(lastID>11000)
if(GUI.Button (new Rect (0, (lastID/1000)*40, 150, 20), "Last Kill by: "+lastID) && myPhotonView.viewID == lastID){
if(this.hpWidth<8.0f && winnerID==myPhotonView.viewID)
hpWidth+=1.0f;
}//if more than 10 players have connected, display in correct place
if(lastID!=0 && GUI.Button (new Rect (Screen.width-150, (lastID/1000)*40, 150, 20), "viewID "+lastID+" has ["+kC[lastID]+"] kills")){
if(this.hpWidth<8.0f && lastID==myPhotonView.viewID)//if i'm not dead and I won last
this.hpWidth+=1.0f;//heal a little
}//show gui for winner's kill count
if(myPhotonView.isMine){//if i'm looking at the game
if(this.hpWidth<=0.0f){//if i'm also dead
calcDeath (hasDIED);//find out who killed me
hasDIED=true;//tell game i've calculated who killed me
if (GUI.Button (new Rect (10,10,150,100), "Respawn")) {//show a button for respawning
this.myPhotonView.RPC("spawnHP", PhotonTargets.AllBuffered);//update HP for spawn HP
hpWidth=8.0f;//update hp in case spawnHP didn't work
this.myPhotonView.RPC("updateHP", PhotonTargets.AllBuffered, hpWidth);
check=0;
newestID=0;
if(hasDIED==true){
this.myPhotonView.RPC("sendlast", PhotonTargets.AllBuffered, winnerID);
}//sending the winner's viewID to all players, adds score+=1
hasDIED=false;
}
}//isDead
}//ismine
}
Of course there's more code, If nobody posts I'll just add more blocks of the code. If you have any ideas, answers would be nice so we can keep code blocks in the original question's comments section. Thanks for any assistance!
Ok... if the player is damaged, but not dead (anything but full hp) and a new player connects, the player who has died previously instantly dies on new connection.
Here's some more code...
[RPC]
private void sendlast(int thiswinner){
ownLog[winnerID]=0;
lastID = thiswinner;
kC[lastID]+=1;
if(kC[lastID]>4 && myPhotonView.viewID == lastID)
swordW.particleSystem.enableEmission = true;
}
[RPC]
private void spawnHP(float hpWidth){
hpWidth = 8.0f;
player.renderer.enabled = true;//found
swordW.renderer.enabled = true;//found
sheildW.renderer.enabled = true;//found
swordW.collider.enabled = true;//found
this.rigidbody.collider.enabled = true;//found
swordW.rigidbody.collider.enabled = true;//found
if(kC[lastID]>4 && myPhotonView.viewID == lastID)
swordW.particleSystem.enableEmission = true;
//swordW.particleSystem.renderer.enabled = true;//found
}
The GUI isn't so much the issue here atm... I'm more concerned with the player connecting and killing another player immediately. The winnerID = viewID (2) rather than viewID 1001+.
so, it dies due to something the player connects with, but the player never touches the fragile player
Your answer
![](https://koobas.hobune.stream/wayback/20220613132955im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[Photon] collider's owner's myphotonview? 0 Answers
whoHit me most? Photon 0 Answers
Access Var From Another GameObject 1 Answer
Button Turns Off and On Object 1 Answer