AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [ANY] Distance Target Filters (https://forums.alliedmods.net/showthread.php?t=237527)

SoulSharD 03-25-2014 16:30

[ANY] Distance Target Filters
 
1 Attachment(s)
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.



Pelipoika 03-25-2014 16:45

Re: [ANY] Distance Target Filters
 
Why not sm_slay @distance 2048 instead of

setdistance 2048
sm_slay @distance ?

SoulSharD 03-25-2014 16:55

Re: [ANY] Distance Target Filters
 
Quote:

Originally Posted by Pelipoika (Post 2115877)
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.

Pelipoika 03-25-2014 16:59

Re: [ANY] Distance Target Filters
 
Quote:

Originally Posted by SoulSharD (Post 2115881)
Target filters don't have any ability to use arguments. At least I don't think so.

Oh, seems so

ddhoward 03-25-2014 17:39

Re: [ANY] Distance Target Filters
 
Quote:

Originally Posted by Pelipoika (Post 2115877)
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)

SoulSharD 03-25-2014 17:56

Re: [ANY] Distance Target Filters
 
Quote:

Originally Posted by ddhoward (Post 2115908)
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.

ddhoward 03-25-2014 20:43

Re: [ANY] Distance Target Filters
 
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); 


ddhoward 03-25-2014 20:51

Re: [ANY] Distance Target Filters
 
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

Mitchell 03-26-2014 09:45

Re: [ANY] Distance Target Filters
 
Quote:

Originally Posted by ddhoward (Post 2115946)
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.

ddhoward 03-26-2014 09:49

Re: [ANY] Distance Target Filters
 
I've gone over it in my head several dozen times; I have yet to find an instance where it does not work.


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

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.