Beispiel #1
0
        public static BasePlayer PlayerByIndex(int playerIndex)
        {
            BasePlayer player = null;

            if (playerIndex > 0 && playerIndex <= Engine.Globals.MaxClients)
            {
                player = EntUtils.IndexEnt <BasePlayer>(playerIndex);
            }

            return(player);
        }
Beispiel #2
0
        /// <summary>
        /// Find a player with a case-insensitive name search
        /// </summary>
        /// <param name="testName"></param>
        /// <returns></returns>
        public static BasePlayer FindPlayerByName(string testName)
        {
            if (testName == null)
            {
                throw new ArgumentNullException(nameof(testName));
            }

            for (var i = 1; i <= Engine.Globals.MaxClients; ++i)
            {
                var entity = EntUtils.IndexEnt(i);

                if (entity != null && entity?.IsPlayer() == true && entity.NetName.Equals(testName, StringComparison.OrdinalIgnoreCase))
                {
                    return((BasePlayer)entity);
                }
            }

            return(null);
        }