3 * =============================================================================
4 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _commandfilters_included
36 #define _commandfilters_included
38 #define MAX_TARGET_LENGTH 64
40 #define COMMAND_FILTER_ALIVE (1<<0) /**< Only allow alive players */
41 #define COMMAND_FILTER_DEAD (1<<1) /**< Only filter dead players */
42 #define COMMAND_FILTER_CONNECTED (1<<2) /**< Allow players not fully in-game */
43 #define COMMAND_FILTER_NO_IMMUNITY (1<<3) /**< Ignore immunity rules */
44 #define COMMAND_FILTER_NO_MULTI (1<<4) /**< Do not allow multiple target patterns */
45 #define COMMAND_FILTER_NO_BOTS (1<<5) /**< Do not allow bots to be targetted */
47 #define COMMAND_TARGET_NONE 0 /**< No target was found */
48 #define COMMAND_TARGET_NOT_ALIVE -1 /**< Single client is not alive */
49 #define COMMAND_TARGET_NOT_DEAD -2 /**< Single client is not dead */
50 #define COMMAND_TARGET_NOT_IN_GAME -3 /**< Single client is not in game */
51 #define COMMAND_TARGET_IMMUNE -4 /**< Single client is immune */
52 #define COMMAND_TARGET_EMPTY_FILTER -5 /**< A multi-filter (such as @all) had no targets */
53 #define COMMAND_TARGET_NOT_HUMAN -6 /**< Target was not human */
54 #define COMMAND_TARGET_AMBIGUOUS -7 /**< Partial name had too many targets */
57 * Processes a generic command target string, and resolves it to a list
58 * of clients or one client, based on filtering rules and a pattern.
60 * Note that you should use LoadTranslations("common.phrases") in OnPluginStart(),
61 * as that file is guaranteed to contain all of the translatable phrases that
62 * ProcessTargetString() will return.
64 * @param pattern Pattern to find clients against.
65 * @param admin Admin performing the action, or 0 if the server.
66 * @param targets Array to hold targets.
67 * @param max_targets Maximum size of the targets array.
68 * @param filter_flags Filter flags.
69 * @param target_name Buffer to store the target name.
70 * @param tn_maxlength Maximum length of the target name buffer.
71 * @param tn_is_ml OUTPUT: Will be true if the target name buffer is an ML phrase,
72 * false if it is a normal string.
73 * @return If a multi-target pattern was used, the number of clients found
74 * is returned. If a single-target pattern was used, 1 is returned
75 * if one valid client is found. Otherwise, a COMMAND_TARGET reason
76 * for failure is returned.
78 native ProcessTargetString(const String:pattern[],
88 * Replies to a client with a given message describing a targetting
91 * Note: The translation phrases are found in common.phrases.txt.
93 * @param client Client index, or 0 for server.
94 * @param reason COMMAND_TARGET reason.
97 stock ReplyToTargetError(client, reason)
101 case COMMAND_TARGET_NONE:
103 ReplyToCommand(client, "[SM] %t", "No matching client");
105 case COMMAND_TARGET_NOT_ALIVE:
107 ReplyToCommand(client, "[SM] %t", "Target must be alive");
109 case COMMAND_TARGET_NOT_DEAD:
111 ReplyToCommand(client, "[SM] %t", "Target must be dead");
113 case COMMAND_TARGET_NOT_IN_GAME:
115 ReplyToCommand(client, "[SM] %t", "Target is not in game");
117 case COMMAND_TARGET_IMMUNE:
119 ReplyToCommand(client, "[SM] %t", "Unable to target");
121 case COMMAND_TARGET_EMPTY_FILTER:
123 ReplyToCommand(client, "[SM] %t", "No matching clients");
125 case COMMAND_TARGET_NOT_HUMAN:
127 ReplyToCommand(client, "[SM] %t", "Cannot target bot");
129 case COMMAND_TARGET_AMBIGUOUS:
131 ReplyToCommand(client, "[SM] %t", "More than one client matched");