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 /
This question was closed Dec 17, 2012 at 10:28 AM by KiraSensei.
avatar image
0
Question by KiraSensei · Nov 25, 2012 at 11:56 PM · networknetworkplayer

Score dialog : probably a network problem ...

Hello everyone !

In my FPS game, I try to make a score dialog. To manage it, I have some informations in a script existing in all clients (and the server).

So when one of the players has his life at 0, I call :

 networkView.RPC("NewKill", RPCMode.All, Network.player, by);

The called method is the following one :

 @RPC
 function NewKill (dead:NetworkPlayer, killer:NetworkPlayer) {
     var playersfound:int = 0;
     for (var currPlayer:PlayerData in playersList.players)
     {
         if (currPlayer.player == dead)
         {
             ++currPlayer.deaths;
             ++playersfound;
         }
         else if (currPlayer.player == killer)
         {
             ++currPlayer.kills;
             ++playersfound;
         }
         if (playersfound == 2) break;
     }
 }

The var playersList is a list of PlayerData, and PlayerData contains the nickname of the player, the number of kills he made, the number of times he died, and his NetworkPlayer info. As you can see I compare the NetworkPlayer to be sure to get the right player and increment what I need to.

My problem is that when the first player kills the second one, nothing happens for the killer player, and I find twice the dead guy for the second one.

So in the first player score dialog I can see 0 kills and deaths for every player and in the second player score dialog, the killer died once, and the dead guy died once too.

If I invert them (the second one kills the first one), nothing happens in the second player score dialog (no kill, no death), and the first player see that he killed once, and the second killed once too ...

To resume, whatever the scenario is, I go two times in the same "if", sometimes it is in the dead part, sometimes in the kill part, and this is only for on of the two players ! I don't know why, I don't know how ... A part of the problem may be a problem in the "==" operator of the NetworkPlayer (I don't really know what it compares).

The debugger is not really helpful, I can't see the intel in the currPlayer var ...

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0
Wiki

Answer by PaulUsul · Nov 26, 2012 at 07:03 PM

Hi here are some quick suggestions,

When calling the rpc are you sure the by is the correct variable.

Try debugging out the ip+port+guid of the player when going through the loop.

Try going through Network.connections and compare the list manually to identify the problem.

 for(NetworkPlayer p in Network.connections)
 {
     Debug.Log(p.ipAddress      // The IP address of this player.
       + " " + p.port           // The port of this player.
       + " " + p.guid           // The GUID for this player, used when connecting with NAT punchthrough.
       + " " + p.externalIP     // Returns the external IP address of the network interface.
       + " " + p.externalPort); // Returns the external port of the network interface.
 }



but the ToString should be sufficient. You can see them all here NetworkPlayer.

Debug.Log more, other than that it looks okay.

Comment
Add comment · Show 8 · 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
avatar image KiraSensei · Nov 26, 2012 at 09:43 PM 0
Share

Thanks i'll try this.

EDIT :

oh my, I have only one connection, how can it be possible ? my 2 players can shoot themselves ...

$$anonymous$$y dead player and my killer player don't have the same port (one has the port I hard coded, and the other one has a random one).

avatar image PaulUsul · Nov 27, 2012 at 07:27 AM 0
Share

Well I don't know if you have a connection to your self, but that does explain it. I'm guessing you add to playersList on OnPlayerConnected ?

avatar image KiraSensei · Nov 27, 2012 at 08:49 AM 0
Share

You pointed one of my problems. Thanks !

I corrected an error and now when one player kills another one, the killed player has the right score dialog (one death for him, one kill for the other guy) but the killer player sees 0 kill and deaths for him and for the dead guy. But I checked once again and my RPC call really is to everybody ... I'll try to put some logs everywhere to understand what is happening, but if you have an other idea ... :)

avatar image PaulUsul · Nov 27, 2012 at 11:29 AM 0
Share

I would log every thing and that should make a clear picture of what is being called when and what is wrong.

avatar image KiraSensei · Nov 27, 2012 at 10:52 PM 0
Share

Ok so there are some things I still don't understand ... First, I think the Network.connections does not send all players connected.

The "for" loop on Network.connections only dumps 1 player : 192.168.0.10 25002 192.168.0.10 57781 (no guid)

I dumped the dead player : 192.168.0.10 57781 531424762515568677 192.168.0.10 57781 (there is a guid !)

And the killer player : 192.168.0.10 25002 192.168.0.10 57781

In my loop on playersList (in my code in the question), I dumped the current player, I have two :

192.168.0.10 25002 192.168.0.10 57781 and

192.168.0.10 25002 192.168.0.10 57781

they are the same ...

In this case, the killer was the server and the dead guy was the client. It increments only in the client score dialog the number of kills of the server and the number of kills on the client (so if we compare the players infos, it is consistent...). Nothing is visible in the server score dialog

Now when the killer is the client and the dead guy is the server I have :

The "for" loop on Network.connections only dumps 1 player : 192.168.0.10 25002 192.168.0.10 57781 (no guid)

I dumped the dead player : 192.168.0.10 25002 192.168.0.10 57781

And the killer player : 192.168.0.10 57781 531424762515568677 192.168.0.10 57781

In my loop on playersList (in my code in the question), I dumped the current player, I have two :

192.168.0.10 25002 192.168.0.10 57781 and

192.168.0.10 25002 192.168.0.10 57781

Here the result in the scores is : nothing happens in the client score dialog, and in the sever score dialog I have one more death for the server and one more kill for the client (exactly what I want, but only on its dialog and in this way :( )

Show more comments

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Spawn networked player then add local object references [UNET] 1 Answer

Network.player is -1 for both instances. Unique player id? 1 Answer

Sending Network player info with RPC 1 Answer

Mix unity Network Manager with own network script 1 Answer

Network two players collision 2 Answers


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