AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Restrict FPS of specific player (https://forums.alliedmods.net/showthread.php?t=344315)

Mixtaz 10-26-2023 04:25

Restrict FPS of specific player
 
Hello everyone. I have rather peculiar problem. There is a guy on my server who is playing on very high fps and he is doing something called SGS (stand-up ground strafing) and some sort of parachute shenaningans.

He is ruining experience for some of the players and I want to force limit his FPS to 100. I've made an attempt to make a plugin that stops him, but for some reason whenever he joins it also automatically kicks everyone whose fps is above 100.

But in this case he is the only threat actor here so I only care that he has 100 FPS max. Here is the code I've made:

PHP Code:

#include < amxmodx >

#define PLUGIN_VERSION "1.1"

#define TASK_FREQ 2.0 

#define isThreat(%1) equal(%1, g_szThreatActorSID)

new Trie:g_tCvars;

const 
g_iFpsMax 100;
const 
g_iFpsOverride 0;

new const 
g_szThreatActorSID[] = "STEAM_0:1:122354662";
new 
g_szAuthID32 ]

public 
plugin_cfg( )
{
    
g_tCvars TrieCreate( );

    new 
szFpsMax], szFpsOverride];
    
num_to_strg_iFpsMaxszFpsMaxcharsmaxszFpsMax ) );
    
num_to_strg_iFpsOverrideszFpsOverridecharsmaxszFpsOverride ) );
    
    
TrieSetStringg_tCvars"fps_max"szFpsMax );
    
TrieSetStringg_tCvars"fps_override"szFpsOverride );
    
    
set_taskTASK_FREQ"OnTaskCheckCvars"___"b" );
}

public 
plugin_init( )
{
    
register_plugin"Fps Limit"PLUGIN_VERSION"DoNii x Mixtaz" );
    
register_cvar"fps_limit_cvar"PLUGIN_VERSIONFCVAR_SERVER FCVAR_SPONLY );
}

public 
plugin_end( )
TrieDestroyg_tCvars );

public 
client_authorizedid )
{
    
get_user_authid(idg_szAuthIDcharsmax(g_szAuthID))

    if(
isThreat(g_szAuthID))
        
client_printidprint_console"Ustaw komendy fps_max 100 i fps_override 0!" );
}

public 
OnTaskCheckCvars( )
{
    new 
szPlayers32 ], iNum;
    
get_playersszPlayersiNum"c" );
    static 
iTempID;

    for( new 
iiNumi++ )
    {
        
iTempID szPlayers];

        if(
isThreat(g_szAuthID))
        {
            
query_client_cvariTempID"fps_max""OnCvarResult" );
            
query_client_cvariTempID"fps_override""OnCvarResult" );
        }
    }
}

public 
OnCvarResultid, const szCvar[ ], const szValue[ ] )

    new 
szValueCheck], szReason128 ];
    
TrieGetStringg_tCvarsszCvarszValueCheckcharsmaxszValueCheck ) );
    
    new 
iValue str_to_numszValue );
    
    if( 
equalszCvar"fps_max" ) )
    {    
        if( 
iValue g_iFpsMax )
        {
            
formatexszReasoncharsmaxszReason ), "^n***************************^n** Ustaw komendy fps_max 100 i fps_override 0! ^n***************************"g_iFpsMax );
            
            
server_cmd"kick #%d"get_user_useridid ));
            
client_printidprint_consoleszReason );
        }
    }
    
    else if( 
equalszCvar"fps_override" ) )
    {
        if( 
iValue != g_iFpsOverride )
        {
            
formatexszReasoncharsmaxszReason ), "^n***************************^n** Ustaw komendy fps_max 100 i fps_override 0! <- **^n***************************"g_iFpsOverride );
            
            
server_cmd"kick #%d"get_user_useridid ));
            
client_printidprint_consoleszReason );
        }
    }
    return 
PLUGIN_CONTINUE;



Napoleon_be 10-26-2023 10:15

Re: Restrict FPS of specific player
 
You're executing query_client_cvar() on all players instead of the threath itself. Don't loop through all player, just target the threat itself and act accordingly.

PHP Code:

public OnTaskCheckCvars( )
{
    new 
szPlayers32 ], iNum;
    
get_playersszPlayersiNum"c" );
    static 
iTempID;

    for( new 
iiNumi++ )
    {
        
iTempID szPlayers];

        if(
isThreat(g_szAuthID))
        {
            
query_client_cvariTempID"fps_max""OnCvarResult" );
            
query_client_cvariTempID"fps_override""OnCvarResult" );
        }
    }



deprale 10-30-2023 08:23

Re: Restrict FPS of specific player
 
cvars can be faked, instead there are better ways to check for high fps.

mlibre 10-30-2023 13:17

Re: Restrict FPS of specific player
 
@deprale show us your cards

Mixtaz 11-03-2023 06:22

Re: Restrict FPS of specific player
 
I have changed my code, there are no useless loops anymore:

PHP Code:

#include < amxmodx >

#define PLUGIN_VERSION "1.1a"
#define TASK_FREQ 2.0
#define MAX_FPS 100
#define OVERRIDE_STATE 0
#define isThreat(%1) equal(%1, g_szThreatActorSID)

new Trie:g_tCvars;

new const 
g_szThreatActorSID[] = "STEAM_0:1:122354662";

public 
plugin_cfg( )
{
    
g_tCvars TrieCreate( );

    new 
szFpsMax], szFpsOverride];
    
num_to_strMAX_FPSszFpsMaxcharsmaxszFpsMax ) );
    
num_to_strOVERRIDE_STATEszFpsOverridecharsmaxszFpsOverride ) );
    
    
TrieSetStringg_tCvars"fps_max"szFpsMax );
    
TrieSetStringg_tCvars"fps_override"szFpsOverride );
}

public 
plugin_init( )
{
    
register_plugin"Restrict Player FPS"PLUGIN_VERSION"Mixtaz" );
}

public 
plugin_end( ) TrieDestroyg_tCvars );

public 
client_authorizedid )
{
    static 
szAuthID[24];
    
get_user_authid(idszAuthIDcharsmax(szAuthID))

    if(
isThreat(szAuthID))
        
initPlayerCheck(id)
}

public 
initPlayerCheck(id)
{
    
query_client_cvarid"fps_max""PlayerPunish" );
    
query_client_cvarid"fps_override""PlayerPunish" );

    
set_taskTASK_FREQ"initPlayerCheck"id__"b" );
}

public 
PlayerPunishid, const szCvar[ ], const szValue[ ] )

    new 
szValueCheck], szReason128 ];
    new 
userid get_user_userid(id);
    
TrieGetStringg_tCvarsszCvarszValueCheckcharsmaxszValueCheck ) );
    
    new 
iValue str_to_numszValue );
    
    if( 
equalszCvar"fps_max" ) )
    {    
        if( 
iValue MAX_FPS )
        {
            
formatexszReasoncharsmaxszReason ), "Ustaw komende fps_max na %i!"MAX_FPS );
            
            
server_cmd("kick #%d ^"%s^""useridszReason);
        }
    }
    
    else if( 
equalszCvar"fps_override" ) )
    {
        if( 
iValue != OVERRIDE_STATE )
        {
            
formatexszReasoncharsmaxszReason ), "Ustaw komende fps_override na %i!"OVERRIDE_STATE );
            
            
server_cmd("kick #%d ^"%s^""useridszReason);
        }
    }
    return 
PLUGIN_CONTINUE;


It should work fine. Btw, I'm also interested in a better method of checking player's values for certain commands. Feel free to share :)

DJEarthQuake 11-04-2023 07:37

Re: Restrict FPS of specific player
 
The script has 2 methods. Feel free to use or cannibalize.

https://github.com/djearthquake/amxx...eck_finale.sma

mlibre 11-04-2023 08:15

Re: Restrict FPS of specific player
 
query_client_cvar not is very reliable I read it for there

georgik57 11-15-2023 06:16

Re: Restrict FPS of specific player
 
in client_PreThink, measure the time between current think and last think to get accurate player fps


All times are GMT -4. The time now is 15:45.

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