Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mlkielb 1 · Jun 25, 2010 at 01:55 AM · multiplayernetworkscoreboard

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mlkielb 1 · Jun 25, 2010 at 05:47 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges