AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   Apply cvars for a single client or flag (https://forums.alliedmods.net/showthread.php?t=347252)

tinke 04-14-2024 15:08

Apply cvars for a single client or flag
 
Is there a way I can apply a cvar (that usually would apply to all player), to a single player or flag (vip for example)

example:
in the hidenseek chasemod plugin: (https://forums.alliedmods.net/showthread.php?t=239132)

the radius of the freezenade is defined in hidenseek.cfg by 'hns_freeze_radius' and what I want is change this cvar for a single player/flag, is that possible? if yes, how can I do that.

obs: i have little to no sourcepawn/csgo server knowledge, so take easy on me

Peter Brev 04-29-2024 05:02

Re: Apply cvars for a single client or flag
 
I don't have a CSS server to test this, but try the following.

At the top of the file, add the following global variables:
PHP Code:

bool    g_bRadiusPlayer[MAXPLAYERS 1];
float     g_fFreezeOverride[MAXPLAYERS 1]; 

Those will be used as our override value whenever a player gets frozen.

In the OnPluginStart section, under all the CreateConVar stuff, add:
PHP Code:

RegAdminCmd("hns_freeze_radius_player"hns_freeze_playerADMFLAG_ROOT"Override the freeze radius of a player"); 

This adds an admin command with root privileges to set a custom freeze radius to a player.

Add the following block of code somewhere:
PHP Code:

Action hns_freeze_player(int clientint args)
{
    if (
args 2)
    {
        
ReplyToCommand(client"[HNS] Usage: hns_freeze_radius_player <name|#userid> <radius>");
        return 
Plugin_Handled;
    }

    
char arg1[MAX_NAME_LENGTH];
    
char arg2[12];

    
GetCmdArg(1arg1sizeof(arg1));
    
GetCmdArg(2arg2sizeof(arg2));

    
int Target FindTarget(clientarg1truefalse);

    if (
Target == -1)
        return 
Plugin_Handled;

    
int arg2int StringToFloat(arg2);

    if (
arg2int 0)
    {
        
ReplyToCommand(client"[HNS] Invalid radius amount.");
        return 
Plugin_Handled;
    }

    if (
arg2int != GetConVarFloat(g_hFreezeRadius))
    {
        
g_bRadiusPlayer[client]      = true;
        
g_fFreezeOverride[client] = arg2int;

        
ReplyToCommand(client"[HNS] Freeze radius set to %d for %N."arg2intTarget);
    }

    else
    {
        
g_bRadiusPlayer[client]      = false;
        
ReplyToCommand(client"[HNS] Value %d is already the global freeze radius value.");
        return 
Plugin_Handled;
    }

    return 
Plugin_Handled;


This is the function of our new admin command.

Finally, find the following line (around the 1100):

PHP Code:

if (GetVectorDistance(faDecoyCoordtargetCoord) <= g_fFreezeRadius)
                        
Freeze(iClientg_fFreezeDurationFROSTNADEiThrower); 

Replace with:
PHP Code:

if (g_bRadiusPlayer[iClient] && GetVectorDistance(faDecoyCoordtargetCoord) <= g_fFreezeOverride[iClient])
                        
Freeze(iClientg_fFreezeDurationFROSTNADEiThrower);
                    else if (
GetVectorDistance(faDecoyCoordtargetCoord) <= g_fFreezeRadius)
                        
Freeze(iClientg_fFreezeDurationFROSTNADEiThrower); 

Again, this is untested. It may very need some tweaking. Try it and see what happens.


All times are GMT -4. The time now is 19:01.

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