#if defined _timeleft_included #endinput #endif #define _timeleft_included enum { TIMELEFT_AUTO = 0, TIMELEFT_SECOND = 1, TIMELEFT_MINUTE = 60, TIMELEFT_HOUR = 3600, TIMELEFT_DAY = 86400, TIMELEFT_WEEK = 604800, TIMELEFT_MONTH = 2592000, TIMELEFT_YEAR = 31104000, } stock timeleft_get_timeleft(time, left_type = 0, &type = 0, &status = 0) { new count = 0, last_count = 0, division = 0; if (left_type != TIMELEFT_AUTO) { count = time / left_type; type = left_type; division = time - (count * left_type); if (division < 0) { status = -1; } else if (division > 0) { status = 1; } else { status = 0; } return count; } else { type = TIMELEFT_AUTO; do { switch (type) { case TIMELEFT_SECOND: { type = TIMELEFT_AUTO; status = 0; return 0; } case TIMELEFT_MINUTE: { type = TIMELEFT_SECOND; } case TIMELEFT_HOUR: { type = TIMELEFT_MINUTE; } case TIMELEFT_DAY: { type = TIMELEFT_HOUR; } case TIMELEFT_MONTH: { type = TIMELEFT_DAY; } case TIMELEFT_YEAR: { type = TIMELEFT_MONTH; } default: { type = TIMELEFT_YEAR; } } count = time / type; division = count * type; if (last_count > 0 && last_count - count < type) { status = -1; return 1; } else if (count > 0) { if (time - division > 0) { status = 1; } else { status = 0; } return count; } last_count = count * type; } while (type > TIMELEFT_AUTO); } return 0; } stock timeleft_format_timeleft(timeleft, type, status, title[], len) { new const titles[][][] = { {"TIMELEFT_SECOND", "TIMELEFT_SECONDS", "TIMELEFT_SECONDS2"}, {"TIMELEFT_MINUTE", "TIMELEFT_MINUTES", "TIMELEFT_MINUTES2"}, {"TIMELEFT_HOUR", "TIMELEFT_HOURS", "TIMELEFT_HOURS2"}, {"TIMELEFT_DAY", "TIMELEFT_DAYS", "TIMELEFT_DAYS2"}, {"TIMELEFT_WEEK", "TIMELEFT_WEEKS", "TIMELEFT_WEEKS2"}, {"TIMELEFT_MONTH", "TIMELEFT_MONTHS", "TIMELEFT_MONTHS2"}, {"TIMELEFT_YEAR", "TIMELEFT_YEARS", "TIMELEFT_YEARS2"}, }; new const cases[] = { 2, 0, 1, 1, 1, 2 }; new titleId, langKeyId; switch (type) { case TIMELEFT_MINUTE: { langKeyId = 1; } case TIMELEFT_HOUR: { langKeyId = 2; } case TIMELEFT_DAY: { langKeyId = 3; } case TIMELEFT_WEEK: { langKeyId = 4; } case TIMELEFT_MONTH: { langKeyId = 5; } case TIMELEFT_YEAR: { langKeyId = 6; } default: { langKeyId = 0; } } if (timeleft > 1) { titleId = (timeleft % 100 > 4 && timeleft % 100 < 20) ? 2 : cases[ min(timeleft % 10, 5) ]; } else { titleId = 1; } switch (status) { case -1: { if (timeleft > 1) { formatex(title, len, "%L %d %L", LANG_SERVER, "TIMELEFT_BEFORE", timeleft, LANG_SERVER, titles[langKeyId][titleId]); } else { formatex(title, len, "%L %L", LANG_SERVER, "TIMELEFT_BEFORE", LANG_SERVER, titles[langKeyId][titleId]); } } case 1: { if (timeleft > 1) { formatex(title, len, "%L %d %L", LANG_SERVER, "TIMELEFT_BEFORE", timeleft, LANG_SERVER, titles[langKeyId][titleId]); } else { formatex(title, len, "%L %L", LANG_SERVER, "TIMELEFT_BEFORE", LANG_SERVER, titles[langKeyId][titleId]); } } default: { if (timeleft > 1) { formatex(title, len, "%d %L", timeleft, LANG_SERVER, titles[langKeyId][titleId]); } else { formatex(title, len, "%L", LANG_SERVER, titles[langKeyId][titleId]); } } } }