#pragma compress 1
#pragma semicolon 1
#include <amxmodx>
#include <reapi>
#include <nvault>
stock const PLUGIN_NAME[] = "HUD Timeleft";
stock const PLUGIN_VERSION[] = "2.0.1";
stock const PLUGIN_AUTHOR[] = "BiZaJe";
#if AMXX_VERSION_NUM >= 200
stock const TG_AUTHOR[] = "@officialgeorg";
#endif
#define TASK_ID 16528
enum _:HUD_OPTION{
RGB[3],
Float:POS[2]
}
enum _:Cvar_List{
TYPE_INFORMER,
TYPE_DISPLAY,
HUD_COLOR[32],
HUD_POS[12]
}
new g_Cvar_List[Cvar_List], g_Hud_Option[HUD_OPTION], g_DisplayHud[MAX_PLAYERS + 1] = 1, g_szSteamID[MAX_PLAYERS + 1][MAX_AUTHID_LENGTH];
new g_SyncHud;
new VaultData;
public plugin_init()
{
#if AMXX_VERSION_NUM >= 200
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR, TG_AUTHOR);
#else
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
#endif
register_dictionary("hud_timeleft.txt");
RegisterHookChain(RG_CBasePlayer_Spawn, "HC_CBasePlayer_Spawn", .post = true);
RegisterHookChain(RG_CBasePlayer_Killed, "HC_CBasePlayer_Killed_Post", .post = true);
register_clcmd("say /off_timeleft", "switch_display_timeleft");
g_SyncHud = CreateHudSyncObj();
RegisterCvars();
}
public client_authorized(iPlayer){
get_user_authid(iPlayer, g_szSteamID[iPlayer], charsmax(g_szSteamID[]));
}
public client_putinserver(iPlayer){
if(is_user_bot(iPlayer) || is_user_hltv(iPlayer)){
return;
}
VaultData = nvault_open("hud_timeleft");
if(VaultData == INVALID_HANDLE){
log_amx("[HUD TIMELEFT] Ошибка чтения vault файла");
return;
}
new szDiplayHud[2];
if(nvault_get(VaultData, g_szSteamID[iPlayer], szDiplayHud, charsmax(szDiplayHud))){
g_DisplayHud[iPlayer] = str_to_num(szDiplayHud);
}else{
g_DisplayHud[iPlayer] = 1;
num_to_str(g_DisplayHud[iPlayer], szDiplayHud, charsmax(szDiplayHud));
nvault_set(VaultData, g_szSteamID[iPlayer], szDiplayHud);
}
if(g_DisplayHud[iPlayer]){
set_task(1.0, "Hud_Timeleft", iPlayer + TASK_ID, .flags="b");
}
nvault_close(VaultData);
}
public client_disconnected(iPlayer){
remove_task(iPlayer + TASK_ID);
}
public switch_display_timeleft(iPlayer){
g_DisplayHud[iPlayer] = !g_DisplayHud[iPlayer];
if(!g_DisplayHud[iPlayer]){
remove_task(iPlayer + TASK_ID);
}else{
set_task(1.0, "Hud_Timeleft", iPlayer + TASK_ID, .flags="b");
}
VaultData = nvault_open("hud_timeleft");
if(VaultData == INVALID_HANDLE){
log_amx("[HUD TIMELEFT] Ошибка чтения vault файла");
return;
}
new szDiplayHud[2];
num_to_str(g_DisplayHud[iPlayer], szDiplayHud, charsmax(szDiplayHud));
nvault_set(VaultData, g_szSteamID[iPlayer], szDiplayHud);
nvault_close(VaultData);
}
public HC_CBasePlayer_Spawn(const this){
if(is_user_bot(this) || is_user_hltv(this)){
return;
}
if(g_Cvar_List[TYPE_DISPLAY] <= 0){
return;
}
if(!g_DisplayHud[this]){
return;
}
remove_task(this + TASK_ID);
}
public HC_CBasePlayer_Killed_Post(const this, pevAttacker, iGib){
if(is_user_bot(this) || is_user_hltv(this)){
return;
}
if(g_Cvar_List[TYPE_DISPLAY] <= 0){
return;
}
if(!g_DisplayHud[this]){
return;
}
set_task(1.0, "Hud_Timeleft", this + TASK_ID, .flags="b");
}
public Hud_Timeleft(taskID) {
taskID -= TASK_ID;
new iTimeLeft = get_timeleft();
if(g_Cvar_List[TYPE_INFORMER] <= 0){
set_hudmessage(.red = g_Hud_Option[RGB][0], .green = g_Hud_Option[RGB][1], .blue = g_Hud_Option[RGB][2], .x = g_Hud_Option[POS][0], .y = g_Hud_Option[POS][1], .holdtime = 1.0);
ShowSyncHudMsg(taskID, g_SyncHud, fmt("%L", taskID, "INFORMER_HUD_TIMELEFT", (iTimeLeft / 60), (iTimeLeft % 60)));
}else{
set_dhudmessage(.red = g_Hud_Option[RGB][0], .green = g_Hud_Option[RGB][1], .blue = g_Hud_Option[RGB][2], .x = g_Hud_Option[POS][0], .y = g_Hud_Option[POS][1], .holdtime = 1.0);
show_dhudmessage(taskID, fmt("%L", taskID, "INFORMER_HUD_TIMELEFT", (iTimeLeft / 60), (iTimeLeft % 60)));
}
}
public RegisterCvars(){
bind_pcvar_num(create_cvar(
"hud_type_informer",
"0",
FCVAR_NONE,
"Тип информера^n\
0 - HUD^n\
1 - DHUD"),
g_Cvar_List[TYPE_INFORMER]
);
bind_pcvar_num(create_cvar(
"hud_type_display",
"0",
FCVAR_NONE,
"Тип отображения^n\
0 - Всегда показывать^n\
1 - Только когда игрок мертв"),
g_Cvar_List[TYPE_DISPLAY]
);
bind_pcvar_string(create_cvar(
"hud_color",
"0 170 255",
FCVAR_NONE,
"Цвет HUD`а"),
g_Cvar_List[HUD_COLOR],
charsmax(g_Cvar_List[HUD_COLOR])
);
bind_pcvar_string(create_cvar(
"hud_position",
"-1.0 0.8",
FCVAR_NONE,
"Позиция HUD"),
g_Cvar_List[HUD_POS],
charsmax(g_Cvar_List[HUD_POS])
);
new szHudOption[32], iColors, iPos;
if(g_Cvar_List[HUD_COLOR][0] != EOS){
while(argbreak(g_Cvar_List[HUD_COLOR], szHudOption, charsmax(szHudOption), g_Cvar_List[HUD_COLOR], charsmax(g_Cvar_List[HUD_COLOR])) != -1){
g_Hud_Option[RGB][iColors++] = str_to_num(szHudOption);
}
}
iPos = 0;
if(g_Cvar_List[HUD_POS][0] != EOS){
while(argbreak(g_Cvar_List[HUD_POS], szHudOption, charsmax(szHudOption), g_Cvar_List[HUD_POS], charsmax(g_Cvar_List[HUD_POS])) != -1){
g_Hud_Option[POS][iPos++] = str_to_float(szHudOption);
}
}
AutoExecConfig(true, "hud_timeleft");
}