TogglePlayerClock

From SA-MP Wiki

Jump to: navigation, search

TogglePlayerClock


Show/Hide the in-game clock (top right corner) for a specific player.


Note: Time is not synced with other players!


Parameters:
(playerid, toggle)
playeridThe player whose clock you want to enable/disable
toggle1 to show and 0 to hide


This function does not return a specific value.


//Example to sync time between players
 
 
static i_ServerSeconds;
static i_ServerMinutes;
static i_ServerHours;
 
forward ProcessGameTime();
 
public OnGameModeInit()
{
	SetTimer("ProcessGameTime", 1000, 1);
}
 
public ProcessGameTime()
{
	i_ServerSeconds++;
 
	// One minute has passed...
	if(i_ServerSeconds == 60)
	{
		// Reset the second counter
		i_ServerSeconds = 0;
 
		// Increment the minute counter
		i_ServerMinutes++;
 
		// One hour has passed
		if(i_ServerMinutes == 60)
		{
			i_ServerMinutes = 0;
			i_ServerHours++;
 
			if(i_ServerHours == 24)
			{
				// One day has passed
				i_ServerHours = 0;
			}
		}
	}
}
 
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	UpdatePlayerTime(playerid);
}
 
 
stock UpdatePlayerTime(playerid)
{
	SetPlayerTime(playerid, i_ServerHours, i_ServerMinutes);
}

Note: Time will automatically advance 6 hours when the player dies.


Related Functions

The following functions might be useful as well, as they're related to this function in one way or another.

Personal tools