Here is a quick version. Note that the days might be a bit off and the month in some rare cases could be one off due to having to assume each month is only 30 days. Doing it correctly I think it more complicated.
The countdown_target cvar needs to the the unix timestamp of the target date/time. You can convert a date/time to a unix timestamp on several websites online.
PHP Code:
#include <amxmodx>
new g_pCvarTargetTime
public plugin_init()
{
register_plugin("Countdown Time Display", "0.1", "Me");
register_clcmd("say /countdown", "cmdCountdown");
g_pCvarTargetTime = register_cvar("countdown_target", "1671954140")
}
public cmdCountdown(id)
{
new iSeconds, iMinutes, iHours, iDays, iMonths, iYears;
new szMessage[128], len;
iSeconds = get_pcvar_num(g_pCvarTargetTime) - get_systime();
if( iSeconds > 0 )
{
iYears = iSeconds / 31536000
iMonths = iSeconds % 31536000 / 2592000;
iDays = iSeconds % 2592000 / 86400;
iHours = iSeconds % 86400 / 3600;
iMinutes = iSeconds % 3600 / 60;
iSeconds = iSeconds % 60;
if( iYears )
{
len += formatex(szMessage[len], charsmax(szMessage) - len, "%dy ", iYears)
}
if( iMonths )
{
len += formatex(szMessage[len], charsmax(szMessage) - len, "%dm ", iMonths)
}
if( iDays )
{
len += formatex(szMessage[len], charsmax(szMessage) - len, "%dd ", iDays)
}
if( iHours )
{
len += formatex(szMessage[len], charsmax(szMessage) - len, "%dh ", iHours)
}
if( iMinutes )
{
len += formatex(szMessage[len], charsmax(szMessage) - len, "%dm ", iMinutes)
}
if( iSeconds )
{
len += formatex(szMessage[len], charsmax(szMessage) - len, "%ds", iSeconds)
}
client_print(id, print_chat, szMessage);
}
else
{
client_print(id, print_chat, "The countdown has expired.");
}
return PLUGIN_HANDLED
}
__________________