Raised This Month: $38 Target: $400
 9% 

[ANY] Distance Target Filters


Post New Thread Reply   
 
Thread Tools Display Modes
Author
SoulSharD
Member
Join Date: Oct 2013
Location: United Kingdom
Plugin ID:
4141
Plugin Version:
1.1.0
Plugin Category:
Admin Commands
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Allows you to target players within a specifc distance.
    Old 03-25-2014 , 16:30   [ANY] Distance Target Filters
    Reply With Quote #1

    Description:

    This plugin will allow you to target players within a specified distance from YOU and including YOU. This plugin contains both opposite and non-opposite targeting filters. (@distance and @!distance)

    This plugin was only test on TF2, though it should work on other games. Please let me know if it doesn't.

    I sincerely apologize if another plugin like this already exists.

    Cvars:

    • sm_distancetarget_version - Displays the current version of the plugin.
    • sm_distancetarget_self - Determine whether or not distance targeting includes yourself. 0/1 (def. 0)


    Commands:

    • sm_setdistance <distance> - This will set the distance argument for the filter. You must set this before using the filter. All distances are in Hammer Units which are considered as inches. (Which are poorly accurate.) However, after playing with it you'll soon get the feel of the measurements. [All admins with GENERIC access can use this.]
    The command is also custom to all admins. (i.e. you don't share the same distance value.)

    Filter Examples:


    Code:
    1#:
    
    sm_setdistance 512
    sm_slay @distance
    
    // Anybody that was within 512 units from you is now dead.
    // INCLUDING YOU.
    
    2#:
    
    sm_setdistance 512
    sm_slay @!distance
    
    // Anybody that wasn't within 512 units from you is now dead.
    
    3#:
    
    sm_setdistance 0
    sm_slay @distance
    
    // This will only target you because you're the only one that's 0 units away from yourself.
    // In this case, use: '@me'.
    
    4#:
    
    sm_setdistance 0
    sm_slay @!distance
    
    // This will kill everyone.
    // In this case, use: '@all'.


    Installation:
    1. Download the below 'filterdistance.smx' file. (Click: Get Plugin.)
    2. Paste the 'filterdistance.smx' file into: addons/sourcemod/plugins
    3. Load the plugin using your preferred methods. (Restart or command.)
    Changelog:
    • 25/03/2014 - 1.0.0: Initial Release
    • 25/03/2014 - 1.0.1: Added changes suggested by ddhoward
    • 25/03/2014 - 1.0.2: Added changes suggested by ddhoward and Mitchell
    • 11/04/2015 - 1.1.0: Added a CVAR to prevent self-targeting.


    Attached Files
    File Type: sp Get Plugin or Get Source (filterdistance.sp - 483 views - 2.1 KB)
    __________________


    Last edited by SoulSharD; 04-11-2015 at 09:46.
    SoulSharD is offline
    Pelipoika
    Veteran Member
    Join Date: May 2012
    Location: Inside
    Old 03-25-2014 , 16:45   Re: [ANY] Distance Target Filters
    Reply With Quote #2

    Why not sm_slay @distance 2048 instead of

    setdistance 2048
    sm_slay @distance ?
    __________________
    Pelipoika is offline
    SoulSharD
    Member
    Join Date: Oct 2013
    Location: United Kingdom
    Old 03-25-2014 , 16:55   Re: [ANY] Distance Target Filters
    Reply With Quote #3

    Quote:
    Originally Posted by Pelipoika View Post
    Why not sm_slay @distance 2048 instead of

    setdistance 2048
    sm_slay @distance ?

    Target filters don't have any ability to use arguments. At least I don't think so.
    __________________

    SoulSharD is offline
    Pelipoika
    Veteran Member
    Join Date: May 2012
    Location: Inside
    Old 03-25-2014 , 16:59   Re: [ANY] Distance Target Filters
    Reply With Quote #4

    Quote:
    Originally Posted by SoulSharD View Post
    Target filters don't have any ability to use arguments. At least I don't think so.
    Oh, seems so
    __________________

    Last edited by Pelipoika; 03-25-2014 at 17:00.
    Pelipoika is offline
    ddhoward
    Veteran Member
    Join Date: May 2012
    Location: California
    Old 03-25-2014 , 17:39   Re: [ANY] Distance Target Filters
    Reply With Quote #5

    Quote:
    Originally Posted by Pelipoika View Post
    Why not sm_slay @distance 2048 instead of

    setdistance 2048
    sm_slay @distance ?
    "2048" would be an argument belonging to sm_slay.

    SoulSharD is correct; you cannot use any special arguments with targeting filters.


    This is very well done. I have a few suggestions, but most will have to wait until I have more time; my class is about to start.


    Also, you should definitely put sm_ before the command. Remember, when a command has sm_ prefixing it, typing the sm_ is optional when using chat triggers.
    Also, you should probably do distance[client] = 0.0 in OnClientDisconnect(client)
    __________________

    Last edited by ddhoward; 03-25-2014 at 17:44.
    ddhoward is offline
    SoulSharD
    Member
    Join Date: Oct 2013
    Location: United Kingdom
    Old 03-25-2014 , 17:56   Re: [ANY] Distance Target Filters
    Reply With Quote #6

    Quote:
    Originally Posted by ddhoward View Post
    Also, you should definitely put sm_ before the command. Remember, when a command has sm_ prefixing it, typing the sm_ is optional when using chat triggers.
    Also, you should probably do distance[client] = 0.0 in OnClientDisconnect(client)
    Done, added/changed all suggestions in 1.0.1.

    Thank you. =')

    I will await further suggestions from you.
    __________________


    Last edited by SoulSharD; 03-25-2014 at 17:59.
    SoulSharD is offline
    ddhoward
    Veteran Member
    Join Date: May 2012
    Location: California
    Old 03-25-2014 , 20:43   Re: [ANY] Distance Target Filters
    Reply With Quote #7

    Command_SetDistance can be simplified to this:

    PHP Code:
    public Action:Command_SetDistance(clientargs)
    {
        
    decl String:arg1[5];
        
    GetCmdArg(1arg1sizeof(arg1));
        
        
    distance[client] = FloatAbs(StringToFloat(arg1));
        
        
    ReplyToCommand(client"[SM] Set distance filter to: %f"distance[client]);
        return 
    Plugin_Handled;

    You can also optimize this slightly, as you know exactly where the '!' would be, if it's present.

    PHP Code:
        new bool:opposite;
        if(
    strPattern[1] == '!'opposite true
    And this:

    PHP Code:
                if(!opposite
                {    
                    if(
    vDistance <= distance[client]) PushArrayCell(hClientsi);
                }
                else
                {
                    if(
    vDistance distance[client]) PushArrayCell(hClientsi);
                } 
    Can be changed to this (untested!!):

    PHP Code:
                if((vDistance <= distance[client]) == !oppositePushArrayCell(hClientsi); 
    __________________

    Last edited by ddhoward; 03-25-2014 at 20:48.
    ddhoward is offline
    ddhoward
    Veteran Member
    Join Date: May 2012
    Location: California
    Old 03-25-2014 , 20:51   Re: [ANY] Distance Target Filters
    Reply With Quote #8

    Good work on storing the current user of the command in a global variable OnClientCommand. I believe I discussed this same thing before... ah here it is: https://forums.alliedmods.net/showthread.php?p=2091799
    __________________
    ddhoward is offline
    Mitchell
    ~lick~
    Join Date: Mar 2010
    Old 03-26-2014 , 09:45   Re: [ANY] Distance Target Filters
    Reply With Quote #9

    Quote:
    Originally Posted by ddhoward View Post
    Command_SetDistance can be simplified to this:

    Can be changed to this (untested!!):

    PHP Code:
                if((vDistance <= distance[client]) == !oppositePushArrayCell(hClientsi); 
    this doesn't look right, but it's probably just me.

    Last edited by Mitchell; 03-26-2014 at 09:51.
    Mitchell is offline
    ddhoward
    Veteran Member
    Join Date: May 2012
    Location: California
    Old 03-26-2014 , 09:49   Re: [ANY] Distance Target Filters
    Reply With Quote #10

    I've gone over it in my head several dozen times; I have yet to find an instance where it does not work.
    __________________

    Last edited by ddhoward; 03-26-2014 at 09:50.
    ddhoward is offline
    Reply


    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 09:32.


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