//
// Keeps the in game time synced to the server's time and
// draws the current time on the player's hud using a textdraw/
// (1 minute = 1 minute real world time)
//
//  Kye 2009

#include <a_samp>
#pragma tabsize 0

//--------------------------------------------------

new Text:TimeDisp;
new hour, minute;
new timestr[32];

forward UpdateTime();

//--------------------------------------------------


public UpdateTime()
{
    gettime(hour, minute);
   	format(timestr,32,"~w~%02d~y~:~w~%02d",hour,minute);
   	TextDrawSetString(TimeDisp,timestr);
   	
   	SetWorldTime(hour);
   	
	new x=0;
	while(x!=MAX_PLAYERS) {
	    if(IsPlayerConnected(x) && GetPlayerState(x) != PLAYER_STATE_NONE) {
	        SetPlayerTime(x,hour,minute);
		 }
		 x++;
	}
}

//--------------------------------------------------

public OnGameModeInit()
{
	// Init our text display
	TimeDisp = TextDrawCreate(605.0,23.0,"00:00");
	TextDrawUseBox(TimeDisp, 0);
	TextDrawFont(TimeDisp, 3);
	TextDrawSetShadow(TimeDisp,2); // no shadow
    TextDrawSetOutline(TimeDisp,1); // thickness 1
    TextDrawBackgroundColor(TimeDisp,0x000000FF);
    TextDrawColor(TimeDisp,0xFFFFFFFF);
    TextDrawAlignment(TimeDisp,3);
	TextDrawLetterSize(TimeDisp,0.63,2.1);
	
	UpdateTime();
	SetTimer("UpdateTime",1000 * 60,1);

	return 1;
}

//--------------------------------------------------

public OnPlayerSpawn(playerid)
{
	TextDrawShowForPlayer(playerid,TimeDisp);
	
	gettime(hour, minute);
	SetPlayerTime(playerid,hour,minute);
	
	return 1;
}
//--------------------------------------------------

public OnPlayerConnect(playerid)
{
    gettime(hour, minute);
    SetPlayerTime(playerid,hour,minute);
    return 1;
}

//--------------------------------------------------
