예제 #1
0
        /// <summary>
        ///     Check if the parameter is well-formatted and return the output.
        /// </summary>
        /// <param name="command">The command text.</param>
        /// <param name="output">The output of this parameter.</param>
        /// <returns>True if the parameter is well-formatted, False otherwise.</returns>
        public override bool Check(ref string command, out object output)
        {
            if (!base.Check(ref command, out output))
                return false;

            int id;
            GtaPlayer player = null;
            string word = (output as string).ToLower();

            /*
             * Check whether the word is not a number.
             * If it is, find the player with this id.
             */
            if (!int.TryParse(word, out id))
            {
                IEnumerable<GtaPlayer> players = GtaPlayer.All.Where(p => p.Name.ToLower().Contains(word.ToLower()));
                if (players.Count() == 1)
                {
                    player = players.First();
                }
            }
            else
            {
                player = GtaPlayer.Find(id);
            }

            if (player == null || !player.IsConnected)
            {
                output = null;
                return false;
            }

            output = player;
            return true;
        }
예제 #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="PlayerObject" /> class.
 /// </summary>
 /// <param name="id">The identifier.</param>
 public PlayerObject(int id) : this(GtaPlayer.Find(id / (Max + 1)), id % (Max + 1))
 {
 }