Code: Select all
#include <amxmodx>//#include <time> #define UPDATE_INTERVAL 1.0#define HUD_TIME 1.1 new gCvarColor;new gCvarPosX;new gCvarPosY; public plugin_init() { register_plugin("Server Info Display", "0.0.2", "Exolent"); //register_dictionary("time.txt"); //register_dictionary("timeleft.txt"); gCvarColor = register_cvar("serverinfo_color", "0,255,0"); gCvarPosX = register_cvar("serverinfo_pos_x", "-0.1"); gCvarPosY = register_cvar("serverinfo_pos_y", "0.1"); set_task(UPDATE_INTERVAL, "TaskDisplayInfo", .flags = "b");} public TaskDisplayInfo() { new timeString[32], dateString[32]; get_time("%I:%M:%S %p", timeString, charsmax(timeString)); get_time("%m/%d/%Y", dateString, charsmax(dateString)); new timeLeft[64], timeLeftLen; new timeLeftSeconds = get_timeleft(); new const timeUnitNames[][] = {"week", "day", "hour", "minute", "second"}; new const timeUnitsToSeconds[sizeof(timeUnitNames)] = {604800, 86400, 3600, 60, 1}; new timeUnitValue[sizeof(timeUnitNames)], timeUnitIndex[sizeof(timeUnitNames)], timeUnitTotal; for(new i, unit; i < sizeof(timeUnitNames); i++) { unit = timeUnitsToSeconds[i]; if((timeUnitValue[timeUnitTotal] = timeLeftSeconds / unit) > 0) { timeUnitIndex[timeUnitTotal++] = i; timeLeftSeconds %= unit; } } for(new i = 0; i < timeUnitTotal; i++) { timeLeftLen += formatex(timeLeft[timeLeftLen], charsmax(timeLeft) - timeLeftLen, "%s%s%s%d %s%s", (i && timeUnitTotal > 2) ? ", " : "", (i && (timeUnitTotal - i) == 1) ? " and" : "", i ? " " : "", timeUnitValue[i], timeUnitNames[timeUnitIndex[i]], (timeUnitValue[i] == 1) ? "" : "s" ); } new hostName[32]; get_user_name(0, hostName, charsmax(hostName)); /*new players[32], pnum, id; get_players(players, pnum, "ch");*/ new color[12], r[4], g[4]; get_pcvar_string(gCvarColor, color, charsmax(color)); strtok(color, r, charsmax(r), color, charsmax(color), ','); strtok(color, g, charsmax(g), color, charsmax(color), ','); set_hudmessage(str_to_num(r), str_to_num(g), str_to_num(color), get_pcvar_float(gCvarPosX), get_pcvar_float(gCvarPosY), .holdtime = HUD_TIME, .channel = -1); show_hudmessage(0, "%s^nThe Time: %s^nDate: %s^nTime Left: %s", hostName, timeString, dateString, timeLeft); /*for(new i = 0; i < pnum; i++) { id = players[i]; get_time_length(id, timeLeftSeconds, timeunit_seconds, timeLeft, charsmax(timeLeft)); show_hudmessage(id, "%L: %s^n%L: %s^n%s", id, "THE_TIME", time, id, "TIME_LEFT", timeLeft, hostName); }*/}