FindPlayer now has partial matches.

This commit is contained in:
Deathmax 2011-06-03 19:51:43 +08:00
parent 0e01dca587
commit 60156af877
2 changed files with 19 additions and 4 deletions

View file

@ -64,7 +64,7 @@ namespace TShockAPI
{
string plStr = args.Message.Remove(0, 5).Trim();
int ply = args.PlayerID;
if (!(Tools.FindPlayer(plStr) == -1 || plStr == ""))
if (!(Tools.FindPlayer(plStr) == -1 || Tools.FindPlayer(plStr) == -2 || plStr == ""))
{
if (!TShock.players[Tools.FindPlayer(plStr)].IsAdmin())
{
@ -74,6 +74,8 @@ namespace TShockAPI
else
Tools.SendMessage(ply, "You can't kick another admin!", new float[] { 255f, 0f, 0f });
}
else if (Tools.FindPlayer(plStr) == -2)
Tools.SendMessage(ply, "More than one player matched!", new float[] { 255f, 0f, 0f });
else
Tools.SendMessage(ply, "Invalid player!", new float[] { 255f, 0f, 0f });
}
@ -82,7 +84,7 @@ namespace TShockAPI
{
string plStr = args.Message.Remove(0, 4).Trim();
int ply = args.PlayerID;
if (!(Tools.FindPlayer(plStr) == -1 || plStr == ""))
if (!(Tools.FindPlayer(plStr) == -1 || Tools.FindPlayer(plStr) == -2 || plStr == ""))
{
if (!TShock.players[Tools.FindPlayer(plStr)].IsAdmin())
{
@ -92,6 +94,8 @@ namespace TShockAPI
else
Tools.SendMessage(ply, "You can't ban another admin!", new float[] { 255f, 0f, 0f });
}
else if (Tools.FindPlayer(plStr) == -2)
Tools.SendMessage(ply, "More than one player matched!", new float[] { 255f, 0f, 0f });
else
Tools.SendMessage(ply, "Invalid player!", new float[] { 255f, 0f, 0f });
}

View file

@ -1,6 +1,7 @@
using System;
using System.IO;
using Terraria;
using System.Collections.Generic;
namespace TShockAPI
{
@ -116,7 +117,7 @@ namespace TShockAPI
/// <returns>int player</returns>
public static int FindPlayer(string ply)
{
int pl = -1;
/*int pl = -1;
for (int i = 0; i < Main.player.Length; i++)
{
if ((ply.ToLower()) == Main.player[i].name.ToLower())
@ -125,7 +126,17 @@ namespace TShockAPI
break;
}
}
return pl;
return pl;*/
List<int> found = new List<int>();
for (int i = 0; i < Main.player.Length; i++)
if (Main.player[i].name.ToLower().Contains(ply.ToLower()))
found.Add(i);
if (found.Count == 1)
return found[0];
else if (found.Count > 1)
return -2;
else
return -1;
}
/// <summary>