| Blockland Forums > Modification Help |
| findClients( mask ) [RESOURCE] |
| (1/2) > >> |
| Port:
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: string The 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. --- Code: (Example of usage) ---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(); } } --- End code --- 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. |
| jes00:
Nice. |
| mp7964:
--- Quote from: jes00 on November 15, 2011, 09:37:22 AM ---Nice. --- End quote --- |
| Nexus:
Here are some client sided methods --- Code: ---function findplayerbyname(%name) { if(!isobject(serverconnection)) { echo("You are not connected to a server"); return 0; } if(!isobject(serverconnection.getcontrolobject())) { echo("You cannot see other players at this time."); return 0; } %group = serverconnection.getcontrolobject().getgroup(); for(%a=0; %a<%group.getcount(); %a++) { if((%b = %group.getobject(%a)).getclassname() $= "Player") { if(strPos(%b.getshapename(), %name) > -1) //case sensitive return %b; } } return -1; } --- End code --- --- Code: ---function fetchall() { for(%a=0; %a<npl_list.rowcount(); %a++) commandtoserver('fetch', getfield(npl_list.getrowtext(%a), 1)); } --- End code --- mmm yes |
| Chrono:
What do those have to do with this topic? |
| Navigation |
| Message Index |
| Next page |