- Home /
Networking scoreboard problem (based off Leepo's tutorial)
Been working on this issue for days. My score board adds points when someone makes a kill or dies. However, sometimes the calculations are correct, some times the kill isn't given to a player, but a kill and/or death is added to the server player everytime even if it isn't involved with the combat.
My code is almost exactly the same as the Leepo tutorial except i'm not using raycasting. I'm using manually instantiated projectiles to do the killing.
First a bullet is fired with:
NetworkViewID viewID1 = Network.AllocateViewID(); networkView.RPC("shootBullet", RPCMode.All, viewID1, Shot1.transform.position,Shot1.transform.rotation);
[RPC]
void shootBullet(NetworkViewID viewID, Vector3 location, Quaternion rotation){
randomNumberX = Random.Range(-strayFactor, strayFactor);
randomNumberY = Random.Range(-strayFactor, strayFactor);
randomNumberZ = Random.Range(-strayFactor, strayFactor);
Transform bulletprefab;
bulletprefab = (Transform)Instantiate(bullet, location, rotation);
Physics.IgnoreCollision(bulletprefab.collider,transform.collider);
bulletprefab.transform.Rotate(randomNumberX, randomNumberY, randomNumberZ);
NetworkView nView;
nView = bulletprefab.GetComponent<NetworkView>();
nView.viewID = viewID;
}
And then this takes place within the bullet script:
if(go.CompareTag("Player")){
NetSlalomPlayer status = go.gameObject.GetComponent<NetSlalomPlayer>();
string[] settingsArray = new string[2];
settingsArray[0] = bulletDamage +"";
settingsArray[1] = localPlayerName;
go.collider.SendMessage("ApplyDamage", settingsArray, SendMessageOptions.DontRequireReceiver);
NetworkViewID viewID = Network.AllocateViewID();
networkView.RPC("shootBoom", RPCMode.All, viewID, transform.position,transform.rotation);
networkView.RPC("KillSelf", RPCMode.All);
}
And then this is the code for the ApplyDamage function called by the previous script:
public void ApplyDamage (string[] info){
float damage = float.Parse(info[0]);
string killerName = info[1];
hullHealth -= damage;
setOwnHealth();
if(hullHealth<=0){
hullHealth = maxHealth;
theScoreBoard.LocalPlayerHasKilled();
networkView.RPC("Respawn", RPCMode.All);
networkView.RPC("tellOwnHealth",RPCMode.Others, hullHealth);
}else{
networkView.RPC("tellOwnHealth",RPCMode.Others, hullHealth);
}
}
On to the scoreboard script where the LocalPlayerHasKilled script is.
public void LocalPlayerHasKilled(){ int kills =0; int deaths = 0; foreach (FPSPlayerNode playerInstance in gameSetupScript.playerList) { if (Network.player == playerInstance.networkPlayer) { kills = playerInstance.kills; deaths = playerInstance.deaths; break; } } kills++; //Overwrite the data of other players with the new correct score networkView.RPC("UpdateKillScore",RPCMode.All, Network.player, kills, deaths); }
[RPC] void UpdateKillScore(NetworkPlayer player, int kills, int deaths){ Debug.Log(player + "=local "+kills+"kills & deaths="+deaths); bool found = false; foreach (FPSPlayerNode playerInstance in gameSetupScript.playerList) { if (player == playerInstance.networkPlayer) { playerInstance.kills=kills; playerInstance.deaths=deaths; found=true; break;
} }
if(!found){ Debug.LogError("Could not find network player "+player+" in the gamesetup playerlist!"); } scoreBoardHeight = gameSetupScript.playerList.Count*15+40;
}
I'll keep tearing my hair out, going over the examples and tutorials over and over again. But from what I can tell the code seems fine. I'm thinking maybe there is some pitfall setting in the editor or something. All i've seen is to make sure "run in the background" is checked for debugging. Any help would be great. Thanks.
Even after just testing Leepo's Example 4 it seems like the scoreboard from there doesn't work quite properly either. Has anyone else had this problem? Or does the scoreboard in example 4 work fine for you while debugging?
Right now I am trying to send all kills and deaths to just the server player, so the server scoreboard will keep the real score. And then I want the server to update all the clients scoreboards, or have all the clients pull the correct score from the server player. Is this possible? and could someone help me some tips for the code? Thanks.
Answer by Twinfox.du · May 23, 2011 at 11:04 PM
I am having a very similar issue when assigning players to different vehicles on the server and propagating this information to other clients. Sometimes it works, most of the time not. One thing in common in our codes is that we are using the Networkplayer struct to ID the players in RPC calls. Now I haven't tested this yet, but perhaps the networkplayer values are unique to each instance of the game, and therefore cannot be compared over network?
Your answer

Follow this Question
Related Questions
Unity multiplayer solutions: Photon, Unity Networking - what else and in what way is good? 0 Answers
Main Parameters of MP game for Clients to Join 0 Answers
Unity 3 socket secure policy 0 Answers
A name For the Character Please Help 3 Answers
If my game uses Photon Multiplayer, can my users host their own game? 1 Answer