#include <amxmodx>
#include <gm_time>
enum _:PCVAR
{
UTC,
YEAR,
Float:TIME
}
new g_pCvar[PCVAR], g_iNewYear, taskid = 112022;
public plugin_init()
{
register_plugin("[GM] New Year Task", "0.0.1", "[GM] NWC");
register_dictionary("gm_nyt.txt");
register_dictionary("gm_time.txt");
register_clcmd("say /newyear", "NewYearCmd");
register_clcmd("say_team /newyear", "NewYearCmd");
bind_pcvar_num(create_cvar("newyear_utc", "3", FCVAR_NONE, "UTC", true, -12.0, true, 12.0), g_pCvar[UTC]);
bind_pcvar_num(create_cvar("newyear_year", "2022", FCVAR_NONE, "What year is coming", true, 1971.0), g_pCvar[YEAR]);
bind_pcvar_float(create_cvar("newyear_info", "60.0", FCVAR_NONE, "Information in the chat 1 time in n seconds", true, 10.0), g_pCvar[TIME]);
AutoExecConfig(true, "nyt", "gm_plugins");
set_task_ex(g_pCvar[TIME], "NewYearCmd", 0, _, _, SetTask_Repeat);
}
public plugin_cfg()
{
g_iNewYear = (g_pCvar[YEAR] - 1970) * 31557600 - g_pCvar[UTC] * 3600;
new iLeft = g_iNewYear - get_systime();
if(iLeft < 0)
{
return;
}
set_task_ex(float(iLeft), "NewYear", taskid);
}
public NewYear()
{
client_print_color(0, print_team_red, "%L %L", 0, "NY_PREFIX", 0, "NY_HAS_COME_ALL", g_pCvar[YEAR]);
}
public NewYearCmd(id)
{
new iLeft = g_iNewYear - get_systime();
if(iLeft < 0)
{
client_print_color(id, print_team_red, "%L %L", -1, "NY_PREFIX", -1, "NY_HAS_COME_PLAYER", g_pCvar[YEAR]);
return PLUGIN_HANDLED;
}
new szText[128];
get_str_time(id, iLeft, szText, charsmax(szText));
client_print_color(id, print_team_red, "%L %L", -1, "NY_PREFIX", -1, "NY_TIMELEFT", szText);
return PLUGIN_HANDLED;
}
public plugin_end()
{
remove_task(taskid);
}
stock set_task_ex(Float:time, const function[], id = 0, const any:parameter[] = "", len = 0, SetTaskFlags:flags = SetTask_Once, repeat = 0)
{
new strFlags[2];
get_flags(_:flags, strFlags, charsmax(strFlags));
set_task(time, function, id, parameter, len, strFlags, repeat);
}