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.

ParameterTypeDefaultDescription
patternconst char*
callerCPlayerSlotWho is targeting (immunity, @me, @aim); -1 for the console.
flagsintSOURCE2MOD_TARGET_* filters.
targetsstd::vector<CPlayerSlot>&Filled with the players, in slot order.
nameSource2ModTargetName*nullptrHow 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.

ParameterType
patternconst char*
callerCPlayerSlot
flagsint
targetCPlayerSlot&

GetTargetErrorPhrase

virtual const char* GetTargetErrorPhrase(int error) = 0;

The phrase (in common.phrases) for an error: "No matching client", ...

ParameterType
errorint

GetTargetErrorText

virtual const char* GetTargetErrorText(int error) = 0;

The same in English, for a reply that is not translated.

ParameterType
errorint

AddTargetFilter

virtual Source2ModTargetFilterId AddTargetFilter(const char* name, Source2ModTargetFilter filter, const char* phrase, bool phraseIsTranslation) = 0;

Adds "@<name>". @p phrase names the targets ("all admins").

ParameterType
nameconst char*
filterSource2ModTargetFilter
phraseconst char*
phraseIsTranslationbool

Returns Source2ModTargetFilterId — An id for RemoveTargetFilter, 0 when the name is taken.

RemoveTargetFilter

virtual bool RemoveTargetFilter(Source2ModTargetFilterId id) = 0;

Source2ModTargetName

How to name what was targeted ("all terrorists", or the one player's name).

Fields

FieldTypeDescription
textstd::string
isPhrasebooltext is a phrase name in common.phrases ("all terrorists") rather than a name.

On this page