Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaderboard shows numbers for dead players #8

Closed
AmmarTee opened this issue Apr 10, 2022 · 3 comments
Closed

Leaderboard shows numbers for dead players #8

AmmarTee opened this issue Apr 10, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@AmmarTee
Copy link

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

@AmmarTee AmmarTee added the enhancement New feature or request label Apr 10, 2022
@wesleywh
Copy link
Owner

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

@AmmarTee
Copy link
Author

It is not fixed We are testing on the latest release

@AmmarTee
Copy link
Author

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
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants