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.