ISource2ModTargeting
Command text to players: "@ct", "#12", "STEAM_1:0:123", "bob".
Patterns:
- @all, @ct, @t, @spec, @alive, @dead, @bots, @humans, @me, @!me, @aim (the player under the caller's crosshair), and filters plugins add;
- #<userid>, a SteamID in any form (#STEAM_1:0:1, [U:1:2], 7656119...), #<exact name>;
- otherwise part of a name (case-insensitive); a name that matches exactly wins over partial matches.
The caller's immunity is checked through ISource2ModPermissions (CanTarget) unless SOURCE2MOD_TARGET_NO_IMMUNITY; the console (slot -1) targets anyone.
std::vector<CPlayerSlot> targets;
Source2ModTargetName name;
int n = g_pSource2ModTargeting->ProcessTargetString(arg, caller, SOURCE2MOD_TARGET_ALIVE, targets, &name);
if (n <= 0)
return ctx.Reply(g_pSource2ModTargeting->GetTargetErrorText(n));Interface id ISource2ModTargeting001 (SOURCE2MOD_TARGETING_INTERFACE) · Global g_pSource2ModTargeting · Header source2mod/ISource2ModTargeting.h
Types
Source2ModTargetFilterId
using Source2ModTargetFilterId = Source2ModHookId;A target filter (AddTargetFilter).
Source2ModTargetFilter
using Source2ModTargetFilter = Source2ModCallback<bool(CPlayerSlot caller, std::vector<CPlayerSlot>& targets)>;A filter a plugin adds ("@admins"): fills @p targets with whom it means.
Methods
ProcessTargetString
virtual int ProcessTargetString(const char* pattern, CPlayerSlot caller, int flags, std::vector<CPlayerSlot>& targets, Source2ModTargetName* name = nullptr) = 0;Finds the players a pattern means.
| Parameter | Type | Default | Description |
|---|---|---|---|
pattern | const char* | ||
caller | CPlayerSlot | Who is targeting (immunity, @me, @aim); -1 for the console. | |
flags | int | SOURCE2MOD_TARGET_* filters. | |
targets | std::vector<CPlayerSlot>& | Filled with the players, in slot order. | |
name | Source2ModTargetName* | nullptr | How to name them (optional). |
Returns int — The number of players, or a SOURCE2MOD_TARGET_* error (<= 0).
FindTarget
virtual int FindTarget(const char* pattern, CPlayerSlot caller, int flags, CPlayerSlot& target) = 0;One player, or an error: ProcessTargetString with NO_MULTI.
| Parameter | Type |
|---|---|
pattern | const char* |
caller | CPlayerSlot |
flags | int |
target | CPlayerSlot& |
GetTargetErrorPhrase
virtual const char* GetTargetErrorPhrase(int error) = 0;The phrase (in common.phrases) for an error: "No matching client", ...
| Parameter | Type |
|---|---|
error | int |
GetTargetErrorText
virtual const char* GetTargetErrorText(int error) = 0;The same in English, for a reply that is not translated.
| Parameter | Type |
|---|---|
error | int |
AddTargetFilter
virtual Source2ModTargetFilterId AddTargetFilter(const char* name, Source2ModTargetFilter filter, const char* phrase, bool phraseIsTranslation) = 0;Adds "@<name>". @p phrase names the targets ("all admins").
| Parameter | Type |
|---|---|
name | const char* |
filter | Source2ModTargetFilter |
phrase | const char* |
phraseIsTranslation | bool |
Returns Source2ModTargetFilterId — An id for RemoveTargetFilter, 0 when the name is taken.
RemoveTargetFilter
virtual bool RemoveTargetFilter(Source2ModTargetFilterId id) = 0;| Parameter | Type |
|---|---|
id | Source2ModTargetFilterId |
Source2ModTargetName
How to name what was targeted ("all terrorists", or the one player's name).
Fields
| Field | Type | Description |
|---|---|---|
text | std::string | |
isPhrase | bool | text is a phrase name in common.phrases ("all terrorists") rather than a name. |