wesleywh / EasyMultiplayer-Invector

Where to submit issues for "Easy Multiplayer - Invector" suite of packages that is available via GumRoad or the Unity Asset Store. GUMROAD: https://cyberbulletgames.gumroad.com/ ASSET STORE: https://assetstore.unity.com/publishers/34070
0 stars 0 forks source link

Leaderboard shows numbers for dead players #8

Closed AmmarTee closed 2 years ago

AmmarTee commented 2 years ago

It would be much preferred if dead players dissappear from the leaderboard

Or/And

If we could see all players in the server on the leaderboard with 0 kills as soon as they join

wesleywh commented 2 years ago

Done. This has been implemented and will be part of v0.3.6 release.

AmmarTee commented 2 years ago

It is not fixed We are testing on the latest release

AmmarTee commented 2 years ago
using UnityEngine;
using EMI.Utils;
using EMI.Managers;
using UnityEngine.UI;
using System.Collections;
using System.Linq;

namespace EMI.UI
{
    /// <summary>
    /// A very simple script showing how you can tie into the available callback and populate
    /// a list of player names and tie it to their total kill count;
    /// </summary>
    public class KillCounterPlayerList : MonoBehaviour
    {
        #region Properties
        [SerializeField, Tooltip("The text to update, if not supplied will try to auto populate")] protected Text textComp = null;
        #endregion

        #region Init
        protected virtual void Start()
        {
            StartCoroutine(InitCallback());
            if (textComp == null) textComp = GetComponent<Text>();
        }
        protected virtual IEnumerator InitCallback()
        {
            yield return new WaitUntil(() => KillCounterUI.instance != null);
            KillCounterUI.instance.OnKillCounterUpdated += KillCountUpdated;
        }
        #endregion

        #region KillCount Updated
        /// <summary>
        /// This is called every single time the killCounter is updated. //Default Broken
        /// </summary>
        //protected virtual void KillCountUpdated(Dictionary<int, int> killCounter)
        //{
        //    string playerName;
        //    string tmpString = "";
        //    foreach (KeyValuePair<int, int> item in killCounter)
        //    {
        //        ClientConnection conn = ClientUtil.GetClientConnection(item.Key);
        //        playerName = (conn == null || string.IsNullOrEmpty(conn.playerName)) ? item.Key.ToString() : conn.playerName;
        //        //if((playerName[0])!='-'){
        //        //}
        //        //else
        //        //{
        //        //    tmpString += $"{playerName} : {item.Value}\n";
        //        //}
        //        //if((playerName[0])=='-')
        //        //{

        //        //}
        //        //else
        //        tmpString += $"{playerName} : {item.Value}\n";

        //    }
        //    if (textComp) textComp.text = tmpString;
        //}
        //protected virtual void KillCountUpdated(Dictionary<int, int> killCounter) //Git Hub Broken
        //{
        //    string playerName;
        //    string tmpString = "";
        //    Dictionary<string, int> playerNameDictionary = new Dictionary<string, int>();
        //    foreach (KeyValuePair<int, int> item in killCounter)
        //    {
        //      ClientConnection conn = ClientUtil.GetClientConnection(item.Key);
        //      playerName = (conn == null || string.IsNullOrEmpty(conn.playerName)) ? item.Key.ToString() : conn.playerName;
        //      playerNameDictionary.Add(playerName, item.Value);
        //    }
        //    foreach (KeyValuePair<string, int> item in playerNameDictionary.OrderByDescending(x => x.Key))
        //    {
        //      tmpString += $"{item.Key} : {item.Value}\n";
        //    }
        //    if (textComp) textComp.text = tmpString;

        //    Debug.Log(tmpString);
        //}
        //protected virtual void KillCountUpdated(Dictionary<int, int> killCounter) //Works
        //{
        //    string playerName;
        //    string tmpString = "";
        //    foreach (KeyValuePair<int, int> item in killCounter)
        //    {
        //      ClientConnection conn = ClientUtil.GetClientConnection(item.Key);
        //      playerName = (conn == null || string.IsNullOrEmpty(conn.playerName)) ? item.Key.ToString() : conn.playerName;
        //      tmpString += $"{playerName} : {item.Value}\n";
        //    }
        //    if (textComp) textComp.text = tmpString;
        //}

        protected virtual void KillCountUpdated(Dictionary<int, int> killCounter) //Ammars
        {
            string playerName;
            string tmpString = "";
            Dictionary<string, int> playerNameDictionary = new Dictionary<string, int>();
            foreach (KeyValuePair<int, int> item in killCounter)
            {
                ClientConnection conn = ClientUtil.GetClientConnection(item.Key);
                playerName = (conn == null || string.IsNullOrEmpty(conn.playerName)) ? item.Key.ToString() : conn.playerName;
                playerNameDictionary.Add(playerName, item.Value);
                //tmpString += $"{playerName} : {item.Value}\n";
            }
            foreach (KeyValuePair<string, int> item in playerNameDictionary.OrderByDescending(x => x.Key))
                {
                    tmpString += $"{item.Key} : {item.Value}\n";
                }
            if (textComp) textComp.text = tmpString;
            Debug.Log(tmpString);
        }
        #endregion
    }
}