I use this:
function newPlayerListGui::finishName(%this, %name)
{
%this.finishNameError = 0;
if(strReplace(%name, " ", "") $= "")
{
return "";
}
%count = NPL_List.rowCount();
if(!%count)
{
return "";
}
for(%i = 0; %i < %count; %i++)
{
%rowName = getField(NPL_List.getRowText(%i), 1);
if(getSubStr(%rowName, 0, strLen(%name)) $= %name)
{
%matchingCount++;
%match = %rowName;
}
}
if(%matchingCount > 1)
{
%this.finishNameError = 2;
return "";
}
if(%match $= "")
{
%this.finishNameError = 1;
return "";
}
return %match;
}
If it returns blank, an error occurred. If newPlayerListGui.finishNameEr ror is 1, no name was found starting with the input. If newPlayerListGui.finishNameEr ror is 2, multiple names were found that start with the input.
I use a variable in newPlayerListGui because of the very unlikely chance that the player's name is 1 or 2.
Example of it being used:
%oldName = %name;
%name = newPlayerListGui.finishName(%name);
if(%name $= "")
{
if(newPlayerListGui.finishNameError == 1)
{
newChatHUD_addLine("Error. No names found starting with" SPC %oldName @ ".");
}
else if(newPlayerListGui.finishNameError == 2)
{
newChatHUD_addLine("Error. Multiple names found starting with" SPC %oldName @ ".");
}
return;
}