#include <sourcemod>
#include <clientprefs>
Handle g_hHud;
Handle g_hCookie;
bool g_bLate;
bool g_bHideTime[MAXPLAYERS + 1];
public APLRes AskPluginLoad2( Handle hPlugin, bool late, char[] sError, int error_len )
{
g_bLate = late;
}
public void OnPluginStart()
{
g_hHud = CreateHudSynchronizer();
g_hCookie = RegClientCookie("server_time","Включение/Выключение отображения текущего времени", CookieAccess_Private);
RegConsoleCmd("sm_time",Cmd_Time);
if(g_bLate)
{
for(int x = 1; x<= MaxClients; x++)
{
if(IsClientInGame(x) && !IsFakeClient(x) && AreClientCookiesCached(x) )
{
OnClientCookiesCached(x);
}
}
}
}
public void OnClientCookiesCached(int iClient)
{
char sValue[4];
GetClientCookie(iClient, g_hCookie, sValue, sizeof sValue );
if(sValue[0])
{
g_bHideTime[iClient] = view_as<bool>( StringToInt(sValue ) );
}
else
{
g_bHideTime[iClient] = false;
}
}
public void OnMapStart()
{
CreateTimer(1.0, Timer_Update,INVALID_HANDLE,TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public Action Cmd_Time(int iClient, int iArgs)
{
g_bHideTime[iClient] = !(g_bHideTime[iClient]);
SetClientCookie(iClient, g_hCookie, g_bHideTime[iClient] ? "1" : "0" );
CGOPrintToChat(iClient, "Вы успешно %s отображение времени на сервере!", g_bHideTime[iClient] ? "выключили" : "включили");
}
stock Action Timer_Update (Handle hTimer)
{
char sTime[40];
GetServerTime(sTime,sizeof sTime);
for(int x = 1; x<= MaxClients; x++)
{
if(IsClientInGame(x) && !IsFakeClient(x) && !g_bHideTime[x])
{
SetHudTextParams(-0.40, -0.02, 1.0, 255, 255, 255, 255);
ShowSyncHudText(x, g_hHud, sTime);
}
}
}
void GetServerTime(char[] sTime, int iLength)
{
char sBuffer[16];
FormatTime(sBuffer,sizeof sBuffer, "%H:%M:%S");
FormatEx(sTime, iLength, "Текущее время: %s",sBuffer);
}