When scripting, I often find myself in the situation that findClientByName or findClientByBL_ID aren't good enough, and I need to expose a better way of selecting targets to clients. So this time, I decided to make my own method.
findClients( mask )
return: stringThe return value will
always be a string. If no targets are found, this is simply an empty string. If targets are found, it will be a space-seperated list of object ID's (of gameConnection objects).
mask is a string containing a "search pattern" which is highly inspired by SourceMod. Normally, it will simply return all clients whose names
mask occurs in, but these "special rules" occur:
- If mask starts with an exclamation mark (!), it will return all clients who do not match the expression. Example: !pie will return all clients that do not have pie in their name.
- If mask starts with the & character, it will return the client with the specified user ID. Example: &2 will return the third player on the server (because user ID's start at 0).
- If mask starts with a sharp (#) which is followed by a number, it will return all clients using the specified BL_ID. Example: #12297 will return all clients with BL_ID 12297. (Note: On LAN servers, there are no BL_IDs, all clients play under BL_ID 999999)
- If mask starts with a sharp (#) which is followed by a string, it will return all clients with the exact name specified. Example: #Port will return all clients with the name "Port", but not clients with the name "Portable".
- If mask starts with the at character (@), it will return a special list of clients matching the "tag" following it. A list of all tags can be seen below.
List of available "tags" for @:
- all: All clients.
- alive: All clients with a player object that is not dead.
- admin: All admins.
- admins: All admins.
- sa: All super admins.
- sas: All super admins.
- superadmin: All super admins.
- superadmins: All super admins.
- loading: All clients who are currently loading.
Please note:
- You cannot combine ! and a diffirent operator in a incorrect way. Example: @!loading will return all clients. The correct use would be !@loading, to return all clients who are not loading. Another example: #!Port will return all clients named exactly "!Port". To return all clients who are not named "Port", you need to use !#Port.
- Specifying none or an invalid "tag" to @ will just result in retrieving all clients.
exec( "./Support_ClientFind.cs" );
function serverCmdAdvKick( %cl, %a, %b, %c, %d, %e )
{
if ( !%cl.isAdmin )
return;
%result = findClients( trim( %a SPC %b SPC %c SPC %d SPC %e ) );
if ( !strLen( %result ) || !getWordCount( %result ) )
return;
%cnt = getWordCount( %result );
for ( %i = 0 ; %i < %cnt ; %i++ )
{
%target = getWord( %result, %i );
messageAll( '', "\c3" @ %cl.name SPC "\c6has kicked \c3" @ %target.getPlayerName() );
%target.delete();
}
}
With the above code, typing
/advkick !@loading would kick all players who are not currently loading.
Download:
http://pastebin.com/raw.php?i=KtE3pRLQ(included functions: findClients, startsWith, clientFind_isInt)
If you find any bugs or have suggestions for features, feel free to tell me.