#include <amxmodx>
#include <amxmisc>
#include <reapi>
#include <nvault>
#define AUTO_RESET_INACTIVE_USERS 30 // * 30 - через сколько дней выполнить сброс
new g_ResetSound[] = "reset_score/rs.wav";
enum _:SETTINGS
{
ENABLE,
MESSAGE,
NOTIFICATION,
OPTION,
SOUND
};
new g_iPlayerSettings[MAX_PLAYERS + 1][SETTINGS], g_nResetScore;
public plugin_precache()
{
precache_sound(g_ResetSound);
}
public plugin_init()
{
register_plugin("Reset Score", "1.2", "maFFyoZZyk");
RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed_Post", .post = true);
register_clcmd("rs", "cmdRSmenu");
register_saycmd("rs", "reset_say");
register_saycmd("resetcsore", "reset_say");
register_saycmd("restartscore", "reset_say");
}
register_saycmd(saycommand[], function[])
{
new szTemp[MAX_RESOURCE_PATH_LENGTH];
formatex(szTemp, charsmax(szTemp), "say /%s", saycommand);
register_clcmd(szTemp, function);
formatex(szTemp, charsmax(szTemp), "say_team /%s", saycommand);
register_clcmd(szTemp, function);
// formatex(szTemp, charsmax(szTemp), "%s", saycommand);
// register_clcmd(szTemp, function);
}
public plugin_cfg()
{
g_nResetScore = nvault_open("reset_menu");
if(g_nResetScore == INVALID_HANDLE)
set_fail_state("[!] Opening nVault failed!");
else
nvault_prune(g_nResetScore, 0, get_systime() - (86400 * AUTO_RESET_INACTIVE_USERS));
}
public client_putinserver(iPlayer)
{
if(is_user_bot(iPlayer) || is_user_hltv(iPlayer))
return;
new szEnable[MAX_PLAYERS + 1][2], iTimestamp, iDataExists;
iDataExists = nvault_lookup(g_nResetScore, get_key(iPlayer, "ENABLE"), szEnable[iPlayer], charsmax(szEnable[]), iTimestamp );
if(iDataExists)
{
g_iPlayerSettings[iPlayer][ENABLE] = str_to_num(szEnable[iPlayer]);
g_iPlayerSettings[iPlayer][MESSAGE] = nvault_get(g_nResetScore, get_key(iPlayer, "MESSAGE"));
g_iPlayerSettings[iPlayer][NOTIFICATION] = nvault_get(g_nResetScore, get_key(iPlayer, "NOTIFICATION"));
g_iPlayerSettings[iPlayer][OPTION] = nvault_get(g_nResetScore, get_key(iPlayer, "OPTION"));
g_iPlayerSettings[iPlayer][SOUND] = nvault_get(g_nResetScore, get_key(iPlayer, "SOUND"));
}
else
{
g_iPlayerSettings[iPlayer][ENABLE] = 1;
g_iPlayerSettings[iPlayer][MESSAGE] = 1;
g_iPlayerSettings[iPlayer][NOTIFICATION] = 1;
g_iPlayerSettings[iPlayer][OPTION] = 1;
g_iPlayerSettings[iPlayer][SOUND] = 1;
nvault_set(g_nResetScore, get_key(iPlayer, "ENABLE"), fmt("%d", 1));
nvault_set(g_nResetScore, get_key(iPlayer, "MESSAGE"), fmt("%d", 1));
nvault_set(g_nResetScore, get_key(iPlayer, "NOTIFICATION"), fmt("%d", 1));
nvault_set(g_nResetScore, get_key(iPlayer, "OPTION"), fmt("%d", 1));
nvault_set(g_nResetScore, get_key(iPlayer, "SOUND"), fmt("%d", 1));
}
}
public cmdRSmenu(iPlayer)
{
new iMenu, szMenu[MAX_MENU_LENGTH], szTemp[128];
formatex(szMenu, charsmax(szMenu), "\y[\rReset Score\y] \wМеню настройки");
iMenu = menu_create(szMenu, "RSmenuHandler");
formatex(szTemp, charsmax(szTemp), "\wАвтообнуление %s", g_iPlayerSettings[iPlayer][ENABLE] ? "\d[\yВключено\d]" : "\d[\rВыключено\d]");
menu_additem(iMenu, szTemp);
formatex(szTemp, charsmax(szTemp), "\wОповещения %s", g_iPlayerSettings[iPlayer][MESSAGE] ? "\d[\yВключены\d]" : "\d[\rВыключены\d]");
menu_additem(iMenu, szTemp);
formatex(szTemp, charsmax(szTemp), "\wВариант оповещения %s", g_iPlayerSettings[iPlayer][NOTIFICATION] ? "\d[\yDHUD\d]" : "\d[\rЧат\d]");
menu_additem(iMenu, szTemp);
formatex(szTemp, charsmax(szTemp), "\wСообщения %s", g_iPlayerSettings[iPlayer][OPTION] ? "\d[\yRandom\d]" : "\d[\rDefault\d]");
menu_additem(iMenu, szTemp);
formatex(szTemp, charsmax(szTemp), "\wЗвук %s", g_iPlayerSettings[iPlayer][SOUND] ? "\d[\yВключены\d]" : "\d[\rВыключены\d]");
menu_additem(iMenu, szTemp);
menu_setprop(iMenu, MPROP_EXITNAME, "\rВыход");
menu_display(iPlayer, iMenu);
return PLUGIN_HANDLED;
}
public RSmenuHandler(iPlayer, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED;
}
g_iPlayerSettings[iPlayer][ENABLE] = nvault_get(g_nResetScore, get_key(iPlayer, "ENABLE"));
g_iPlayerSettings[iPlayer][MESSAGE] = nvault_get(g_nResetScore, get_key(iPlayer, "MESSAGE"));
g_iPlayerSettings[iPlayer][NOTIFICATION] = nvault_get(g_nResetScore, get_key(iPlayer, "NOTIFICATION"));
g_iPlayerSettings[iPlayer][OPTION] = nvault_get(g_nResetScore, get_key(iPlayer, "OPTION"));
g_iPlayerSettings[iPlayer][SOUND] = nvault_get(g_nResetScore, get_key(iPlayer, "SOUND"));
switch(item)
{
case 0:
{
if(g_iPlayerSettings[iPlayer][ENABLE])
{
nvault_set(g_nResetScore, get_key(iPlayer, "ENABLE"), fmt("%d", 0));
g_iPlayerSettings[iPlayer][ENABLE] = 0;
}
else
{
nvault_set(g_nResetScore, get_key(iPlayer, "ENABLE"), fmt("%d", 1));
g_iPlayerSettings[iPlayer][ENABLE] = 1;
}
cmdRSmenu(iPlayer);
}
case 1:
{
if(g_iPlayerSettings[iPlayer][MESSAGE])
{
nvault_set(g_nResetScore, get_key(iPlayer, "MESSAGE"), fmt("%d", 0));
g_iPlayerSettings[iPlayer][MESSAGE] = 0;
}
else
{
nvault_set(g_nResetScore, get_key(iPlayer, "MESSAGE"), fmt("%d", 1));
g_iPlayerSettings[iPlayer][MESSAGE] = 1;
}
cmdRSmenu(iPlayer);
}
case 2:
{
if(g_iPlayerSettings[iPlayer][NOTIFICATION])
{
nvault_set(g_nResetScore, get_key(iPlayer, "NOTIFICATION"), fmt("%d", 0));
g_iPlayerSettings[iPlayer][NOTIFICATION] = 0;
}
else
{
nvault_set(g_nResetScore, get_key(iPlayer, "NOTIFICATION"), fmt("%d", 1));
g_iPlayerSettings[iPlayer][NOTIFICATION] = 1;
}
cmdRSmenu(iPlayer);
}
case 3:
{
if(g_iPlayerSettings[iPlayer][OPTION])
{
nvault_set(g_nResetScore, get_key(iPlayer, "OPTION"), fmt("%d", 0));
g_iPlayerSettings[iPlayer][OPTION] = 0;
}
else
{
nvault_set(g_nResetScore, get_key(iPlayer, "OPTION"), fmt("%d", 1));
g_iPlayerSettings[iPlayer][OPTION] = 1;
}
cmdRSmenu(iPlayer);
}
case 4:
{
if(g_iPlayerSettings[iPlayer][SOUND])
{
nvault_set(g_nResetScore, get_key(iPlayer, "SOUND"), fmt("%d", 0));
g_iPlayerSettings[iPlayer][SOUND] = 0;
}
else
{
nvault_set(g_nResetScore, get_key(iPlayer, "SOUND"), fmt("%d", 1));
g_iPlayerSettings[iPlayer][SOUND] = 1;
}
cmdRSmenu(iPlayer);
}
}
rg_send_audio(iPlayer, "events/tutor_msg.wav");
return PLUGIN_HANDLED;
}
public CBasePlayer_Killed_Post(const iVictim, iAttacker, pevInflictor)
{
if (!is_user_connected(iVictim))
return;
if(g_iPlayerSettings[iVictim][ENABLE])
{
new iFrags, iDeaths;
iFrags = floatround(get_entvar(iVictim, var_frags));
iDeaths = get_member(iVictim, m_iDeaths);
if(iDeaths >= iFrags)
{
if(g_iPlayerSettings[iVictim][MESSAGE])
{
if(g_iPlayerSettings[iVictim][OPTION])
{
if(g_iPlayerSettings[iVictim][NOTIFICATION])
{
new col_03 = random_num(0, 5);
switch (col_03)
{
case 0: set_dhudmessage(224, 224, 224, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
case 1: set_dhudmessage(0, 224, 0, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
case 2: set_dhudmessage(0, 224, 224, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
case 3: set_dhudmessage(224, 224, 0, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
case 4: set_dhudmessage(224, 0, 0, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
case 5: set_dhudmessage(0, 0, 224, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
}
show_dhudmessage(iVictim, "Ваш Счет Обнулен ^nАВТОМАТИЧЕСКИ!");
}
else
client_print_color(iVictim, -2, "^1[^4GFS^1] Ваш Счет Обнулен ^4АВТОМАТИЧЕСКИ^1!");
}
else
{
if(g_iPlayerSettings[iVictim][NOTIFICATION])
{
set_dhudmessage(0, 224, 0, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
show_dhudmessage(iVictim, "Ваш Счет Обнулен ^nАВТОМАТИЧЕСКИ!");
}
else
client_print_color(iVictim, -2, "^1[^4GFS^1] Ваш Счет Обнулен ^4АВТОМАТИЧЕСКИ^1!");
}
}
reset_func(iVictim);
}
}
return;
}
public reset_say(iPlayer)
{
if(!is_user_connected(iPlayer))
return 0;
if(g_iPlayerSettings[iPlayer][MESSAGE])
{
if(g_iPlayerSettings[iPlayer][OPTION])
{
if(g_iPlayerSettings[iPlayer][NOTIFICATION])
{
new col_03 = random_num(0, 5);
switch (col_03)
{
case 0: set_dhudmessage(224, 224, 224, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
case 1: set_dhudmessage(0, 224, 0, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
case 2: set_dhudmessage(0, 224, 224, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
case 3: set_dhudmessage(224, 224, 0, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
case 4: set_dhudmessage(224, 0, 0, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
case 5: set_dhudmessage(0, 0, 224, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
}
show_dhudmessage(iPlayer, "Ваш Счет Обнулен");
}
else
{
new chat_msg = random_num(0, 3);
switch (chat_msg)
{
case 0: client_print_color(iPlayer, -2, "^1[^4GFS^1] Ваш Счет ^4Обнулен^1!");
case 1: client_print_color(iPlayer, -2, "^1[^4GFS^1] Ваш Счет ^4Успешно Обнулен^1!");
case 2: client_print_color(iPlayer, -2, "^1[^4GFS^1] Вы ^3обнулили ^1свой счет!");
case 3: client_print_color(iPlayer, -2, "^1[^4GFS^1] Вы ^3сбросили ^1свой счет!");
}
}
}
else
{
if(g_iPlayerSettings[iPlayer][NOTIFICATION])
{
set_dhudmessage(0, 224, 0, -1.00, 0.65, 2, 6.00, 3.20, 0.05, 1.50);
show_dhudmessage(iPlayer, "Ваш Счет Обнулен ^nАВТОМАТИЧЕСКИ!");
}
else
client_print_color(iPlayer, -2, "^1[^4GFS^1] Ваш Счет ^4Обнулен^1!");
}
}
reset_func(iPlayer);
return 1;
}
stock reset_func(iPlayer)
{
if(g_iPlayerSettings[iPlayer][SOUND])
client_cmd(iPlayer, "play %s", g_ResetSound);
set_entvar(iPlayer, var_frags, 0.0);
set_member(iPlayer, m_iDeaths, 0);
message_begin(MSG_ALL, 85);
write_byte(iPlayer);
write_short(0);
write_short(0);
write_short(0);
write_short(0);
message_end();
}
get_key(const iPlayer, key[])
{
new szAuth[24], szKey[64];
get_user_authid(iPlayer, szAuth, charsmax(szAuth));
formatex(szKey, charsmax(szKey), "%s_%s", szAuth, key);
return szKey;
}
public plugin_end()
{
nvault_close(g_nResetScore);
}