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

@ -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>