I need function to find player, target!
Solved Finding a player?
Discussion in 'Hurtworld Development' started by Veydart, Dec 13, 2015.
-
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; }
Or make your own, what I recommend.Last edited by a moderator: Dec 13, 2015 -
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; }
-
Wulf Community Admin
You could also just use the function that Oxide already provides: Oxide/HurtworldCore.cs at master · OxideMod/Oxide · GitHub.
-
You understand me. I'm writing plugin on give item for player, I cant choose who get items! please help me!
-
- 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. -
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; }
-
Wulf Community Admin