Plugin FPS

Статус
В этой теме нельзя размещать новые ответы.
Сообщения
46
Реакции
2
I wanted to add a new CVAR
Freeze the player until the player puts the value required FPS on console, then he will be able to move

C++:
#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.
* v0.5: Added the ability to activate / deactivate the plugin.
*/

new Float:g_fMaxFPS, g_MaxFPS_Warnings, g_MaxFPS_Punishment, g_FW_FM_CMD_START_POST;

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(szLang, CreateLangKey("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(szLang, CreateLangKey("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_language, szOutPut, charsmax(szOutPut));

    for(new i, maxloop = get_langsnum(), szLang[3]; i < maxloop; i++)
    {
        get_lang(i, szLang)
        if(equal(szLang,szOutPut))
        {
            copy(szServerLang, charsmax(szServerLang), szOutPut);
            return i;
        }
    }

    return -1;
}

public plugin_run_state( handleCvar, const oldValue[], const newValue[] )
{
    if( str_to_num(newValue) >= 1 )
    {
        if(!g_FW_FM_CMD_START_POST)
        {
            g_FW_FM_CMD_START_POST = register_forward(FM_CmdStart, "fw_CmdStart", true);
        }
    }
    else {
        if(g_FW_FM_CMD_START_POST)
        {
            unregister_forward(FM_CmdStart, g_FW_FM_CMD_START_POST, true);
            g_FW_FM_CMD_START_POST = 0;
        }
    }
}

public plugin_pause()
{
    set_cvar_num("fps_checker_state", 0);
}

public plugin_unpause()
{
    set_cvar_num("fps_checker_state", 1);
}

public plugin_init()
{
    register_plugin("Fps Checker", "0.5", "Dev-CS.ru & Natsheh");

    if(!g_FW_FM_CMD_START_POST)
    {
        g_FW_FM_CMD_START_POST = register_forward(FM_CmdStart, "fw_CmdStart", true);
    }

    #if AMXX_VERSION_NUM <= 182
    CvarHookChange(
        CvarRegister("fps_checker_state", "1", "FPSChecker run state < 1 - active / 0 - deactive >", FCVAR_SERVER, true, 0.0, true, 1.0),
        "plugin_run_state"
        );

    CvarCache(
        CvarRegister("fps_checker_maxfps", "105", "Maximum FPS for players", FCVAR_SERVER, true, MIN_FPS_POSSIBLE, true, MAX_FPS_POSSIBLE),
        CvarType_Float,
        g_fMaxFPS
        );

    CvarCache(
        CvarRegister("fps_checker_maxwarnings", "3", "Max warnings given before the action", FCVAR_SERVER, true, 0.0, true, MAX_WARNINGS_POSSIBLE),
        CvarType_Integer,
        g_MaxFPS_Warnings
        );
    CvarCache(
        CvarRegister("fps_checker_punishment", "0", "Punishment type < 0 - kick / 1 - slay / else = ban >", FCVAR_SERVER, true, 0.0),
        CvarType_Integer,
        g_MaxFPS_Punishment
        );
    #else
    hook_cvar_change(
        create_cvar("fps_checker_state", "1", FCVAR_SERVER, "FPSChecker run state < 1 - active / 0 - deactive >", true, 0.0, true, 1.0),
        "plugin_run_state"
        );
    bind_pcvar_float(
        create_cvar("fps_checker_maxfps", "105", FCVAR_SERVER, "Maximum FPS for players", true, MIN_FPS_POSSIBLE, true, MAX_FPS_POSSIBLE),
        g_fMaxFPS
        );
    bind_pcvar_num(
        create_cvar("fps_checker_maxwarnings", "3", FCVAR_SERVER, "Max warnings given before the action", true, 0.0, true, MAX_WARNINGS_POSSIBLE),
        g_MaxFPS_Warnings
        );
    bind_pcvar_num(
        create_cvar("fps_checker_punishment", "0", FCVAR_SERVER, "Punishment type < 0 - kick / 1 - slay / else = ban >", true, 0.0),
        g_MaxFPS_Punishment
        );
    #endif
}

enum fps_s {
    warnings,
    num_cmds,
    msec_sum,
    Float: next_check,
    Float: fps
}

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(id, uc_handle)
{
    if ( ! g_bIsUserBotOrHLTV [ id ] && ( pev ( id , pev_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(szReason, charsmax(szReason), "%2.f+ FPS", g_fMaxFPS);
                    punish_user(id, szReason);
                    g_fps_info[id][warnings] = 0;
                }
                else
                {
                    set_dhudmessage( 225, 0, 0, 0.5, 0.65, 1, 0.5, 1.0, 0.01, 0.01 );
                    show_dhudmessage( id, "%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_handle, UC_Msec);
    }
}

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

            user_kill(id);
            client_print(id, print_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);
        }
    }
}
 

Ayk

Сообщения
763
Реакции
478
Помог
19 раз(а)
kooomax,

  • В данном разделе размещаются темы, в которых требуется помощь с доработкой или объяснением материала.
    В теме должны быть опубликованы попытки (diff кода или последовательность действий) самостоятельного поиска решения.
    Если у вас нет наработок и попыток самому вникнуть в проблему, тогда вам в раздел "Покупка"
 
Статус
В этой теме нельзя размещать новые ответы.

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу