/*
Благодароность bizon за remove_task
*/
#include <amxmodx>
#include <reapi>
#define TASK_ID 16528
enum CVARS{
Float:UPDATE_HUD,
HUD_COLOR_R,
HUD_COLOR_G,
HUD_COLOR_B,
Float:HUD_POS_X,
Float:HUD_POS_Y
}
new g_eCvars[CVARS];
public plugin_init()
{
register_plugin("HUD Timeleft", "1.0.2", "BiZaJe")
RegisterHookChain(RG_CBasePlayer_Spawn, "HC_CBasePlayer_Spawn", .post = true);
RegisterHookChain(RG_CBasePlayer_Killed, "HC_CBasePlayer_Killed_Post", .post = true)
RegisterCvars();
}
public client_disconnected(iPlayer){
remove_task(iPlayer + TASK_ID);
}
public HC_CBasePlayer_Spawn(const this){
remove_task(this + TASK_ID);
}
public HC_CBasePlayer_Killed_Post(const this, pevAttacker, iGib){
set_task(g_eCvars[UPDATE_HUD], "Hud_Timeleft", this + TASK_ID, .flags="b");
}
public Hud_Timeleft(taskID) {
new id = taskID - TASK_ID;
new iTimeLeft = get_timeleft();
set_hudmessage(.red = g_eCvars[HUD_COLOR_R], .green = g_eCvars[HUD_COLOR_G], .blue = g_eCvars[HUD_COLOR_B], .x = g_eCvars[HUD_POS_X], .y = g_eCvars[HUD_POS_Y], .holdtime = g_eCvars[UPDATE_HUD]);
show_hudmessage(id, "До конца карты: %d:%02d", (iTimeLeft / 60), (iTimeLeft % 60));
}
public RegisterCvars(){
bind_pcvar_float(create_cvar(
"hud_update_time",
"1.0",
FCVAR_NONE,
"Время обновления HUD"),
g_eCvars[UPDATE_HUD]
);
bind_pcvar_num(create_cvar(
"hud_color_r",
"0",
FCVAR_NONE,
"Цвет HUD`а (Красный)"),
g_eCvars[HUD_COLOR_R]
);
bind_pcvar_num(create_cvar(
"hud_color_g",
"170",
FCVAR_NONE,
"Цвет HUD`а (Зеленый)"),
g_eCvars[HUD_COLOR_G]
);
bind_pcvar_num(create_cvar(
"hud_color_b",
"255",
FCVAR_NONE,
"Цвет HUD`а (Синий)"),
g_eCvars[HUD_COLOR_B]
);
bind_pcvar_float(create_cvar(
"hud_position_x",
"-1.0",
FCVAR_NONE,
"Позиция HUD (X)"),
g_eCvars[HUD_POS_X]
);
bind_pcvar_float(create_cvar(
"hud_position_y",
"0.8",
FCVAR_NONE,
"Позиция HUD (Y)"),
g_eCvars[HUD_POS_Y]
);
AutoExecConfig(true, "hud_timeleft");
}