#include <amxmisc>
#include <reapi>
native aes_set_player_bonus(player,bonus,bool:force = false);
native aes_get_player_bonus(player);
new clutch_no_scenario;
new clutch_min_enemies;
new clutch_reward;
new clutch_prepare_msg;
new clutch_done_msg;
new g_pClutchedPlayer;
new WinStatus:g_iRoundWinStatus;
public plugin_init()
{
register_plugin("Clutch Player", "25.08.2025", "@emmajule");
register_dictionary("clutch.txt");
RegisterHookChain(RG_CSGameRules_RestartRound, "CSGameRules_RestartRound", true);
RegisterHookChain(RG_CSGameRules_CheckWinConditions, "CSGameRules_CheckWinConditions", true);
parse_cfg();
}
public CSGameRules_RestartRound()
{
g_pClutchedPlayer = 0;
g_iRoundWinStatus = WINSTATUS_NONE;
}
public CSGameRules_CheckWinConditions()
{
new NumAliveTerrorist, NumAliveCT;
rg_initialize_player_counts(NumAliveTerrorist, NumAliveCT, _, _);
if (!g_iRoundWinStatus && !get_member_game(m_bRoundTerminating))
{
if (NumAliveCT == 1 && NumAliveTerrorist >= clutch_min_enemies)
{
g_iRoundWinStatus = WINSTATUS_CTS;
g_pClutchedPlayer = RetriveLastAlivePlayerTeam("CT");
}
else if (NumAliveTerrorist == 1 && NumAliveCT >= clutch_min_enemies)
{
g_iRoundWinStatus = WINSTATUS_TERRORISTS;
g_pClutchedPlayer = RetriveLastAlivePlayerTeam("TERRORIST");
}
}
else if (get_member_game(m_iRoundWinStatus) == g_iRoundWinStatus)
{
g_iRoundWinStatus = WINSTATUS_NONE;
if (!is_user_connected(g_pClutchedPlayer)) {
return;
}
if (clutch_no_scenario && NumAliveTerrorist + NumAliveCT != 1) {
return;
}
aes_set_player_bonus(g_pClutchedPlayer, aes_get_player_bonus(g_pClutchedPlayer) + clutch_reward);
if (clutch_done_msg)
{
// CLUTCH_TAG = [^4Clutch^1]
// CLUTCH_DONE_MSG = За исполнение клатча вы получили:^4 %d$
client_print_color(g_pClutchedPlayer, 0, "%l %l", "CLUTCH_TAG", "CLUTCH_DONE_MSG", clutch_reward);
}
}
else if ((g_iRoundWinStatus == WINSTATUS_TERRORISTS && NumAliveTerrorist > 1) || (g_iRoundWinStatus == WINSTATUS_CTS && NumAliveCT > 1))
{
g_iRoundWinStatus = WINSTATUS_NONE;
}
}
RetriveLastAlivePlayerTeam(const szTeam[])
{
new aPlayers[32], iCount, pClient;
get_players_ex(aPlayers, iCount, GetPlayers_ExcludeDead | GetPlayers_MatchTeam, szTeam);
pClient = aPlayers[0];
if (clutch_prepare_msg) {
// CLUTCH_PREPARE_MSG = Вы остались один! Убейте всех и получите:^4 %d$
client_print_color(pClient, 0, "%l %l", "CLUTCH_TAG", "CLUTCH_PREPARE_MSG", clutch_reward);
}
return pClient;
}
parse_cfg()
{
bind_pcvar_num(create_cvar("clutch_no_scenario", "0", .description = "Клатч защитывается только если игрок убил всех врагов^nТак например не будут считатся взрыв бомбы или разминирование.."), clutch_no_scenario);
bind_pcvar_num(create_cvar("clutch_min_enemies", "2", .description = "Минимальное кол-во оставшихся врагов для выполнения клатча", .has_min = true, .min_val = 2.0), clutch_min_enemies);
bind_pcvar_num(create_cvar("clutch_reward", "10", .description = "Награда в виде бонусных очков за клатч"), clutch_reward);
bind_pcvar_num(create_cvar("clutch_prepare_msg", "1", .description = "Показывать уведомление игроку о том что он должен выполнить клатч когда остался один"), clutch_prepare_msg);
bind_pcvar_num(create_cvar("clutch_done_msg", "1", .description = "Показывать уведомление игроку при успешном выполнении клатча"), clutch_done_msg);
new path[PLATFORM_MAX_PATH];
get_configsdir(path, charsmax(path));
// strcat(path, "/plugins/clutch.cfg", charsmax(path));
strcat(path, "/clutch.cfg", charsmax(path));
server_cmd("exec %s", path);
server_exec();
}