I just saw the poster above me’s post and realised that. I’ll change it hang on.
[editline]15:14[/editline]
There. Read the comments (//).
[lua]
// Serach through the players.
function SearchForPlayer( Data )
// Check data.
if ( !Data || Data == "" || Data == nil ) then
// Return 1 - used for no players.
return 1;
end
// Lower data.
Data = string.lower( Data );
// Count variable.
local Players = { };
// Cycle through the players.
for _, pl in pairs( player.GetAll() ) do
// If we find the data in their name.
if ( string.find( string.lower( pl:Name() ), Data ) ) then
// Add to the count variable.
table.insert( pl, Players );
end
// If we find the data in their steam id.
if ( string.find( string.lower( pl:SteamID() ), Data ) ) then
// Add to the count variable.
table.insert( pl, Players );
end
// If we find the data in their user id.
if ( string.find( string.lower( pl:UserID() ), Data ) ) then
// Add to the count variable.
table.insert( pl, Players );
end
end
// If there was only one match.
if ( #Players == 1 ) then
// Return the player.
return Players[ 1 ];
// If there was more than one match found.
elseif ( #Players > 1 ) then
return 0;
// If no matches were found.
else
return 1;
end
// Return false.
return false;
end
// Check a return from the search utility library.
function FixSearchPlayer( pl, Search )
// Make sure we're working with a player.
if ( !pl:IsValid() || !pl:IsPlayer() ) then
// Exit.
return;
end
// Check data.
if ( !Search || Search == "" || Search == nil ) then
// Trying to search a nil string/entity.
SF.Utility.Debug( "Tried to search a nill string/entity." );
return false;
end
// If there was more than one player.
if ( Search == 0 )
// Print & return.
pl:ChatPrint( "More than one player found." );
return false;
elseif ( Search == 1 ) then
// No matches.
pl:ChatPrint( "No players/matches were found." );
return false;
end
// Exit.
return true;
end
// Example.
function TestingHai( pl, cmd, arg )
// Search for the player.
local Target = SearchForPlayer( arg[ 1 ] );
Target = FixSearchPlayer( pl, Target );
// Check target.
if ( !Target ) then
return;
end
// God.
Target:GodEnable();
end
concommand.Add( “TestingHai”, TestingHai );
[/lua]