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 Stormy102 · Nov 10, 2014 at 02:07 PM · javascriptnetworkingscoreboardkick

What is wrong with this scoreboard?

I am trying to create a scoreboard for multiplayer. I want the scoreboard to track player's name, kills, death and ping. I also want the server to be able to kick players using this. This will provide the framework for kicking and a scoreboard. Here is the code:

 #pragma strict
 
 import System.Text.RegularExpressions;
 
 //Strings
 private var Username : String;
 private var players : String[];
 private var pings : String[];
 
 //Ints
 private var myConnection : int = -1;
 private var i : int = 0;
 private var a : int = 0;
 private var kills : int[];
 private var deaths : int[];
 
 //Boolean
 private var showScoreboard : boolean = false;
 
 //KeyCodes
 var toggleKey : KeyCode = KeyCode.Tab;
 
 //NetworkPlayers
 var connections : NetworkPlayer[];
 
 function Start()
 {
     Username = PlayerPrefs.GetString("Username", "Guest");
     if (Network.isServer)
     {
         connections = Network.connections;
         ServerConfig();
     }
     if (Network.isClient)
     {
         if (myConnection == -1 && Network.isClient)
         {
             for (a = 0; a < connections.Length; a++)
             {
                 if (connections[a] == networkView.owner)
                 {
                     myConnection = a + 1;
                     networkView.RPC("TellScoreboardName", RPCMode.All, Username, myConnection);
                 }
             }
         }
     }
 }
 
 function Update()
 {
     if (myConnection == -1 && Network.isClient)
     {
         for (a = 0; a < connections.Length; a++)
         {
             if (connections[a] == networkView.owner)
             {
                 myConnection = a + 1;
                 networkView.RPC("TellScoreboardName", RPCMode.All, Username, myConnection);
             }
         }
     }
     if (Input.GetKeyDown(toggleKey))
     {
         showScoreboard = true;
     }
     if (Input.GetKeyUp(toggleKey))
     {
         showScoreboard = false;
     }
 }
 
 function OnGUI()
 {
     if (showScoreboard && Network.isServer)
     {
         GUI.Window(0, Rect(Screen.width /4, Screen.height/4, Screen.width /2, Screen.height/2), Scoreboard, "Scoreboard");
     }
 }
 
 function Scoreboard(windowID : int)
 {
     GUI.Label(Rect(5,30,250,25), "Name");
     GUI.Label(Rect(260,30,50,25), "Kills");
     GUI.Label(Rect(315,30,50,25), "Deaths");
     GUI.Label(Rect(370,30,100,25), "Ping (Avg)");
     for (var PL : int = 0; PL < players.Length; PL++)
     {
         GUI.Label(Rect(5,60 + (25 * PL),250,25), players[PL]);
     }
     /*for (i = 0; i < kills.Length; i++)
     {
         GUI.Label(Rect(260,60 + (25 * i),50,25), kills[i].ToString());
     }
     for (i = 0; i < deaths.Length; i++)
     {
         GUI.Label(Rect(315,60 + (25 * i),50,25), deaths[i].ToString());
     }
     for (i = 0; i < connections.Length; i++)
     {
         GUI.Label(Rect(370,60 + (25 * (i + 1)),100,25), Network.GetAveragePing(Network.connections[i + 1]) + "ms");
     }*/
     if (Network.isServer && connections.Length > 0)
     {
         for (var PK = 0; PK < (connections.Length + 1); PK++)
         {
             if(GUI.Button(Rect(425, 50 + (25 * (PK + 1)), 100,25), "Kick"))
             {
                 networkView.RPC("KickPlayer", RPCMode.AllBuffered, PK, connections[i]);
                 Network.CloseConnection(connections[i], true);
             }
         }
     }
 }
 
 function ServerConfig()
 {
     var tempIntNoPlayers : int = GameObject.FindGameObjectWithTag("MainCamera").GetComponent(NetworkManager).NoOfPlayers;
     players = new String[tempIntNoPlayers + 1];
     kills = new int[tempIntNoPlayers + 1];
     deaths = new int[tempIntNoPlayers + 1];
     pings = new String[tempIntNoPlayers + 1];
     players[0] = Username;
     kills[0] = 0;
     deaths[0] = 0;
     pings[0] = "0";
 }
 
 @RPC
 function ScoreboardUpdate(pls : String, info : NetworkMessageInfo)//, kls : int[], dts : int[], png : String[])
 {
     var stringArray : String[] = Regex.Split(pls, "-");
     
     players = stringArray;
     /*kills = kls;
     deaths = dts;
     pings = png;*/
 }
 
 @RPC
 function TellScoreboardName(pl : String, connectionInt : int, info : NetworkMessageInfo)
 {
     if (Network.isServer)
     {
         players[connectionInt] = pl;
     }
 }
 
 @RPC
 function KickPlayer(playerNo : int, player : NetworkPlayer)
 {
     if (Network.isServer)
     {
         GameObject.FindGameObjectWithTag("MainCamera").GetComponent(FPSChat).addGameChatMessage(players[playerNo]+" was kicked from the game");
     }
 }

Any suggestions will help. Cheers,

Stormy102

Comment
Add comment · Show 2
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 Stormy102 · Nov 10, 2014 at 02:37 PM 0
Share

Anyone????

avatar image ExtremePowers · Nov 10, 2014 at 02:40 PM 0
Share

Isn't it working on the server?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ExtremePowers · Nov 10, 2014 at 02:12 PM

The client never gets the connections array if im not mistaking, so the length that it tries to get will always be 0.

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

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Two questions with mutliplayer 0 Answers

Where is a free, helpful tutorial on how to use Unity's networking? 2 Answers

MultiPlayer Game Network ? 1 Answer

getting a list of all lan servers 0 Answers

Unity 3d Networking Local Search 0 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