Solved Finding a player?

Discussion in 'Hurtworld Development' started by Veydart, Dec 13, 2015.

  1. I need function to find player, target!
     
  2. Code:
            ////////////////////////////////////////
            ///     Player Finding by LaserHydra
            ////////////////////////////////////////        PlayerIdentity GetPlayer(string searchedPlayer, PlayerIdentity executer)
            {
                List<PlayerIdentity> foundPlayers =
                    (from player in GameManager.Instance.GetIdentityMap().Values
                     where player.Name.ToLower().Contains(searchedPlayer.ToLower())
                     select player).ToList();            switch (foundPlayers.Count)
                {
                    case 0:
                        hurt.SendChatMessage(executer, "The player can not be found.");
                        break;                case 1:
                        return foundPlayers[0];                default:
                        List<string> playerNames = (from player in foundPlayers select player.Name).ToList();
                        string players = ListToString(playerNames, 0, ", ");
                        hurt.SendChatMessage(executer, "Multiple matching players found: \n" + players);
                        break;
                }            return null;
            }
    Please credit me if you use this.
    Or make your own, what I recommend.
     
    Last edited by a moderator: Dec 13, 2015
  3. Code:
    PlayerIdentity FindPlayer(string nameorid)
            {
                foreach (KeyValuePair<CSteamID, PlayerIdentity> players in (Dictionary<CSteamID, PlayerIdentity>)Singleton<GameManager>.Instance.GetIdentifierMap())
                {
                    PlayerIdentity toPlayer = players.Value;
                    if (toPlayer.Name.ToLower().Contains(nameorid.ToLower()) || toPlayer.SteamId.ToString() == nameorid)
                    {
                        return toPlayer;
                    }
                }
                return null;
            }
    
     
  4. Wulf

    Wulf Community Admin

  5. You understand me. I'm writing plugin on give item for player, I cant choose who get items! please help me!
     
  6. - Kits Plugin as reference for giving items
    - Above code
    - C# knowledge
    Thats all you need.
    If your problem is the knowledge, i recommend learning C# and not just always hoping for getting a finished code. At least you can not call that developing then, then you should just post what you want into the Requests section and propably somebody will make that.

    You should at least try it yourself and if you fail, tell us what you have tried and where you problem is.
     
  7. How would I call FindSession without adding the entire code in to my plugin, or is that actually required? I have it working with my plugin, but I have to add the following to the plugin for it to work. Is there a way to call it without?
    Code:
    private PlayerSession FindSession(string nameOrIdOrIp)
            {
                var sessions = GameManager.Instance.GetSessions();
                PlayerSession session = null;
                foreach (var i in sessions)
                {
                    if (nameOrIdOrIp.Equals(i.Value.Name, StringComparison.OrdinalIgnoreCase) ||
                        nameOrIdOrIp.Equals(i.Value.SteamId.ToString()) || nameOrIdOrIp.Equals(i.Key.ipAddress))
                    {
                        session = i.Value;
                        break;
                    }
                }
                return session;
            }
     
  8. Wulf

    Wulf Community Admin

    I'll need to expose it via the API, otherwise you could use the Covalence API.