- Home /
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 ...
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.
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).
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 ?
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 ... :)
I would log every thing and that should make a clear picture of what is being called when and what is wrong.
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 :( )