Raised This Month: $ Target: $400
 0% 

Solved Adding CVAR to disable/enable this plugin


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
ddag1
Member
Join Date: Apr 2020
Old 10-11-2021 , 19:21   Adding CVAR to disable/enable this plugin
Reply With Quote #1

Hi there. Can someone please add a CVAR to disable/enable this plugin?
Thank you so much in advance!

PHP Code:
#include < amxmodx >
#include < fakemeta >

#if AMXX_VERSION_NUM <= 182
#include < dhudmessage >
#include < cvar_util >
    #if !defined _cvar_util_included
        #assert "cvar_util.inc library required ! Download it at : https://forums.alliedmods.net/showthread.php?t=154642#InstallationFiles"
    #endif
#else
    #define client_disconnect client_disconnected
#endif

#define MAX_FPS_POSSIBLE 999.0
#define MIN_FPS_POSSIBLE 60.0
#define MAX_WARNINGS_POSSIBLE 5.0

/*
* v0.1: Dev-CS.ru
* v0.2: Dev-CS.ru
* v0.3: Fixed a bug while a player is frozen causing FPS Overrates, added CVars!
* v0.4: Organized the if statement checks in the cmdstart forward.
*/

new Float:g_fMaxFPSg_MaxFPS_Warningsg_MaxFPS_Punishment;

public 
plugin_natives()
{
    
register_dictionary("fps_checker.txt");
}

public 
plugin_cfg()
{
    new 
szLang[3];
    
get_server_language(szLang);

    if(
GetLangTransKey("MAXIMUM_FPS_ALLOWED") == TransKey_Bad)
    {
        
AddTranslation(szLangCreateLangKey("MAXIMUM_FPS_ALLOWED"), "Maximum FPS allowed in the server is");
        
server_print("[ FPS CHECKER ] (%s) Adding a translation key 'MAXIMUM_FPS_ALLOWED' text translation!"szLang);
    }

    if(
GetLangTransKey("MAXIMUM_FPS_SLAY_REASON") == TransKey_Bad)
    {
        
AddTranslation(szLangCreateLangKey("MAXIMUM_FPS_SLAY_REASON"), "* You've been slayed due having your FPS over the %2.f limit!");
        
server_print("[ FPS CHECKER ] (%s) Adding a translation key 'MAXIMUM_FPS_SLAY_REASON' text translation!"szLang);
    }
}

get_server_language(szServerLang[3]="")
{
    static 
szOutPut[3], iPCVar_language 0; if( !iPCVar_language iPCVar_language get_cvar_pointer("amx_language");

    
get_pcvar_string(iPCVar_languageszOutPutcharsmax(szOutPut));

    for(new 
imaxloop get_langsnum(), szLang[3]; maxloopi++)
    {
        
get_lang(iszLang)
        if(
equal(szLang,szOutPut))
        {
            
copy(szServerLangcharsmax(szServerLang), szOutPut);
            return 
i;
        }
    }

    return -
1;
}

public 
plugin_init()
{
    
register_plugin("Fps Checker""0.4""Dev-CS.ru & Natsheh");
    
register_forward(FM_CmdStart"fw_CmdStart"true);

    
#if AMXX_VERSION_NUM <= 182
    
CvarCache
        
CvarRegister("fps_checker_maxfps""105""Maximum FPS for players"FCVAR_SERVERtrueMIN_FPS_POSSIBLEtrueMAX_FPS_POSSIBLE),
        
CvarType_Float,
        
g_fMaxFPS
        
);

    
CvarCache
        
CvarRegister("fps_checker_maxwarnings""3""Max warnings given before the action"FCVAR_SERVERtrue0.0trueMAX_WARNINGS_POSSIBLE),
        
CvarType_Integer,
        
g_MaxFPS_Warnings
        
);
    
CvarCache
        
CvarRegister("fps_checker_punishment""0""Punishment type < 0 - kick / 1 - slay / else = ban >"FCVAR_SERVERtrue0.0),
        
CvarType_Integer,
        
g_MaxFPS_Punishment
        
);
    
#else
    
bind_pcvar_float(
        
create_cvar("fps_checker_maxfps""105"FCVAR_SERVER"Maximum FPS for players"trueMIN_FPS_POSSIBLEtrueMAX_FPS_POSSIBLE),
        
g_fMaxFPS
        
);
    
bind_pcvar_num(
        
create_cvar("fps_checker_maxwarnings""3"FCVAR_SERVER"Max warnings given before the action"true0.0trueMAX_WARNINGS_POSSIBLE),
        
g_MaxFPS_Warnings
        
);
    
bind_pcvar_num(
        
create_cvar("fps_checker_punishment""0"FCVAR_SERVER"Punishment type < 0 - kick / 1 - slay / else = ban >"true0.0),
        
g_MaxFPS_Punishment
        
);
    
#endif
}

enum fps_s {
    
warnings,
    
num_cmds,
    
msec_sum,
    
Floatnext_check,
    
Floatfps
}

new 
g_fps_info[33][fps_s], bool:g_bIsUserBotOrHLTV[33];

public 
client_putinserver(id) {
    
g_bIsUserBotOrHLTV[id] = (is_user_bot(id) || is_user_hltv(id)) ? true false;
    
g_fps_info[id][warnings] = g_fps_info[id][num_cmds] = g_fps_info[id][msec_sum] = 0;
    
g_fps_info[id][next_check] = g_fps_info[id][fps] = 0.0;
}

public 
client_disconnect(id)
{
    
g_fps_info[id][next_check] = get_gametime() + 999999999.0;
}

public 
fw_CmdStart(iduc_handle)

    if (!
g_bIsUserBotOrHLTV[id] && (pev(idpev_flags) & FL_FROZEN) == 0)
    {
        if(
g_fps_info[id][next_check] <= get_gametime())
        {
            
g_fps_info[id][fps] = (g_fps_info[id][num_cmds] * 1000.0) / g_fps_info[id][msec_sum];
            if (
g_fps_info[id][fps] > g_fMaxFPS)
            {
                if (++
g_fps_info[id][warnings] > g_MaxFPS_Warnings)
                {
                    static 
szReason[32];
                    
formatex(szReasoncharsmax(szReason), "%2.f+ FPS"g_fMaxFPS);
                    
punish_user(idszReason);
                    
g_fps_info[id][warnings] = 0;
                }
                else
                {
                    
set_dhudmessage225000.50.6510.51.00.010.01 );
                    
show_dhudmessageid"%L %2.f FPS"LANG_SERVER"MAXIMUM_FPS_ALLOWED"g_fMaxFPS);
                }
            }

            
g_fps_info[id][num_cmds] = g_fps_info[id][msec_sum] = 0;
            
g_fps_info[id][next_check] = get_gametime() + 1.0;
        }

        
g_fps_info[id][num_cmds] ++;
        
g_fps_info[id][msec_sum] += get_uc(uc_handleUC_Msec); 
    }
}

punish_user(const id, const szReason[])
{
    switch( 
g_MaxFPS_Punishment )
    {
        case 
0server_cmd("kick #%d ^" %^""get_user_userid(id), szReason);
        case 
1:
        {
            if(!
is_user_alive(id)) return;

            
user_kill(id);
            
client_print(idprint_chat"%L"LANG_SERVER"MAXIMUM_FPS_SLAY_REASON"g_fMaxFPS);
        }
        default:
        {
            
server_cmd("banid ^"%d^" ^"#%d^"; writeid; kick #%d ^" Banned %d minutes: %s ^";", g_MaxFPS_Punishment, get_user_userid(id), get_user_userid(id), g_MaxFPS_Punishment, szReason);
        
}
    }


Last edited by ddag1; 10-13-2021 at 21:18.
ddag1 is offline
 



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 23:58.


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