Raised This Month: $ Target: $400

[Any] Dynamic Selectors

Post New Thread Reply   
Thread Tools Display Modes
Senior Member
Join Date: May 2020
Plugin ID:
Plugin Version:
Plugin Category:
General Purpose
Plugin Game:
Plugin Dependencies:
    Servers with this Plugin:
    Plugin Description:
    Dynamic Target Selectors with Arguments like in Minecraft but for SourceMod
    Old 03-27-2022 , 14:54   [Any] Dynamic Selectors
    Reply With Quote #1

    Dynamic Selectors

    So I was bored this weekend and implemented dynamic target selectors, like Mincraft has them for SourceMod. This means there are now 4/5 new target selectors you can filter.

    Last time something like this was attempted was with [Any] Dynamic Targeting, but this is quite a bit different. I guess they'd even somewhat work together.

    I tested it in TF2 but it should work with any game.
    • @p Nearest player (sort=nearest,limit=1)
    • @r Random player (sort=random,limit=1)
    • @s Self (equal to @me, but filterable)
    • @!s Everyone but Self (equal to @!me, but filterable)
    • @a Everyone (no sorting or limit; equal to @all, but filterable)

    These will populate the base list of targets that can then be filtered.

    Filters are specified in square brackes and can not contains spaces, more square brackets, quotes, or argument/value separators.
    Specify As many or little as you want, duplicate argument will use the last value.

    Arguments available by default:
    • sort=Sorting Sorting being one of:
      • nearest, near Nearest players first
      • furthest, far Furthest players first
      • random, rng Random target sorting
      • arbitrary, any Undefined order
    • limit=Number Number of targets to return (positive integer)
    • c=Number combination of sort and limit
      • positive is nearest N players
      • positive is furthest -N players
    • r=Number Maximum distance to caller in HU
    • rm=Number Minimum distance to caller in HU
    • distance=Range Distance range to caller in HU
    • x=Range The targets x coordinate has to be within the range
    • y=Range The targets y coordinate has to be within the range
    • z=Range The targets z coordinate has to be within the range
    • dx=Range Distance between targets x and callers x has to be within range
    • dy=Range Distance between targets y and callers y has to be within range
    • dz=Range Distance between targets z and callers z has to be within range
    • team=Team Team specifyer (can be negated with ! prefix)
      • 0, none Unassigned
      • 1, spec Spectators
      • 2, T, RED, survivor, combine for Team 2
      • 3, CT, BLU, infected, rebel for Team 3
    • flag=Flags Check for all admin flags (can be negted with ! prefix)
    • hp=Range Target health has to be within range

    Range values are formatted according to this list and can be negated using a ! prefix:
    • A literal value: attrib=100
    • An upper bound: attrib=..100
    • A lower bound: attrib=100..
    • Both bounds: attribg=-100..100

    Example: sm_slay @a[rm=100,team=BLU]

    Plugins can also register additional argument parsers with natives. Argument and value buffers are 64 bytes, so no super long stuff (as if that was affordable in chat anyways).
    (API is untested, let me know if it's broken)
    OnPluginStart() {
    	DTS_RegisterTargetFilter("hp", dts_healthFilter);
    OnPluginEnd() {
    bool dts_healthFilter(int caller, int target, const char[] key, const char[] value) {
    	if (!IsClientInGame(target)) return false;
    	int result = DTS_IntInRange(GetClientHealth(target), value);
    	if (result == -1) {
    		SetFilterError("Invalid value for argument 'hp', value or range expected!");
    	return result == 1;

    Plugins & LibrariesListing GitHubDosMike Tools ▶ ToDo

    Last edited by reBane; 10-15-2023 at 12:37. Reason: Update to 23w41a
    reBane is offline
    Junior Member
    Join Date: Mar 2015
    Old 09-27-2023 , 19:34   Re: [Any] Dynamic Selectors
    Reply With Quote #2

    Nice, I wanted something like this for a local TF2 DS I'm messing around with (maybe I'll host an actual server one day lol).
    There seem to be a few problems though:
    The targets work with the chat triggers and in-game console, but not with the DS console - sm_slay @r or sm_slay @a = no matching client was found when executed on the server console. I believe this means I cannot exec any configs/scripts that include these targets.
    Also, @r seemed to always target the same player(bot) every time. The server console dumps a bunch of "shuffle x and y" messages, but every time the list is identical.
    Lastly, when I tried to compile from source (get source on this post), I got an error on line 573: "error 100: function prototypes do not match".

    Last edited by DZHEX; 09-27-2023 at 19:45.
    DZHEX is offline
    Senior Member
    Join Date: May 2020
    Old 10-15-2023 , 12:42   Re: [Any] Dynamic Selectors
    Reply With Quote #3

    I have not had any issues with random targets, but i removed the spammy output and used a different way shuffling. About the error you get on compile, that was some SourcePawn change that messed with the Function type, i dont know if they intend to fix/change that in the future, but I can work around that (should no longer complain)
    As for console, that's not triggering OnClientCommand, so yea... I don't like hooking every command, but I made it opt in, so you can just uncomment #define ALT_HOOK_METHOD and recompile
    Plugins & LibrariesListing GitHubDosMike Tools ▶ ToDo
    reBane is offline

    Thread Tools
    Display Modes

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump

    All times are GMT -4. The time now is 21:34.

    Powered by vBulletin®
    Copyright ©2000 - 2023, vBulletin Solutions, Inc.
    Theme made by Freecode