#include <a_samp>
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_BRIGHTRED 0xFF0000AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_PINK 0xFF66FFAA
#define COLOR_BLUE 0x3A47DEFF
#define COLOR_TAN 0xBDB76BAA
#define COLOR_PURPLE 0x800080AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_INDIGO 0x1E90FFAA
#define COLOR_BLACK 0x00000000
#define COLOR_DARKGREY 0x696969FF
// new variables
new Text:Servt; //Server Time Text draw Variable
new Tsec; //stores the mins of time
new THrs; //stores hours of time
public OnGameModeInit()
{
Servt=TextDrawCreate(545, 31, "00:00");
TextDrawColor(Servt, COLOR_WHITE);
Tsec= 0;
THrs= 0;
SetTimer("TimeU",1000,true);
return 1;
}
Servt=TextDrawCreate(545, 31, "00:00");
TextDrawColor(Servt, COLOR_WHITE);
Tsec= 0;
THrs= 0;
SetTimer("TimeU",1000,true);
forward TimeU();
public TimeU()
{
new string[7]; // it makes a variable for a string with size 128
Tsec+=1; //this adds 1 to the existing time variable
if(Tsec==60) { //this resets the mins to 00 one it reaches 60
Tsec=00;
THrs+=1; //this adds 1 to the hours every 60 seconds
}
if(THrs==24) { //This Checks if time is 24:00
Tsec=00; //This Sets resets Mins
THrs=0; //this Resets Hours
}
if(Tsec<10) { // This Adds a 0 Before The Mins Display For it To look like an actual clock
//formats string
format(string,sizeof(string),"%d:%d0",THrs,Tsec);
}
if(Tsec>10) { // This Removes a 0 Before The Mins Display after it has reached 10
//formats string
format(string,sizeof(string),"%d:%d",THrs,Tsec);
}
if(THrs<10) {
//formats string
format(string,sizeof(string),"0%d:%d",THrs,Tsec);
}
for(new i; i<MAX_PLAYERS; i++) { //loops through all players
if(IsPlayerConnected(i)) { //checks if the player is connected
SetPlayerTime(i,THrs,Tsec); //sets All players time
}
}
TextDrawSetString(Servt,string); //updates the textdraw
}
Public OnPlayerSpawn(playerid)
{
TextDrawShowForPlayer(playerid,Servt);
return 1;
}
format(string,sizeof(string),"%02d:%02d",THrs,Tsec);
if(Tsec<10) { // This Adds a 0 Before The Mins Display For it To look like an actual clock
//formats string
format(string,sizeof(string),"%d:%d0",THrs,Tsec);
}
if(Tsec>10) { // This Removes a 0 Before The Mins Display after it has reached 10
//formats string
format(string,sizeof(string),"%d:%d",THrs,Tsec);
}
if(THrs<10) {
//formats string
format(string,sizeof(string),"0%d:%d",THrs,Tsec);
}
This can be done with an easier way. Change the '%d' to '%02d'. This will show the 0 in front of the (1-9) in the minutes, aswell as the hours. |
#define FILTERSCRIPT
#include < a_samp >
new
Text: td_SAClock[ 2 ],
currentMinutes,
currentHours,
clockTimer
;
forward SAClock_Update( );
public SAClock_Update( )
{
static
hoursOutput[ 4 ], // 3chars + NULL
minutesOutput[ 3 ] // 2chars + NULL
;
if ( 0 <= currentMinutes <= 58 )
currentMinutes ++;
else
currentHours = ( currentHours == 23 ) ? 0 : currentHours + 1, currentMinutes = 0;
if ( 0 <= currentMinutes <= 9 )
format( minutesOutput, 3, "0%d", currentMinutes );
else
format( minutesOutput, 3, "%d", currentMinutes );
if ( 0 <= currentHours <= 9 )
format( hoursOutput, 4, "0%d:", currentHours );
else
format( hoursOutput, 4, "%d:", currentHours );
TextDrawSetString( td_SAClock[ 0 ], hoursOutput );
TextDrawSetString( td_SAClock[ 1 ], minutesOutput );
for ( new slots = GetMaxPlayers( ), i; i < slots; i ++ )
{
if ( !IsPlayerConnected( i ) || IsPlayerNPC( i ) )
continue;
SetPlayerTime( i, currentHours, currentMinutes );
}
return 1;
}
public OnFilterScriptInit( )
{
td_SAClock[ 0 ] = TextDrawCreate( 547.000000, 36.000000, "00" );
TextDrawBackgroundColor( td_SAClock[ 0 ], 255 );
TextDrawFont( td_SAClock[ 0 ], 1 );
TextDrawLetterSize( td_SAClock[ 0 ], 0.509999, 1.800000 );
TextDrawColor( td_SAClock[ 0 ], -1 );
TextDrawSetOutline( td_SAClock[ 0 ], 0 );
TextDrawSetProportional( td_SAClock[ 0 ], 1 );
TextDrawSetShadow( td_SAClock[ 0 ], 1 );
td_SAClock[ 1 ] = TextDrawCreate( 578.000000, 36.000000, ":00" );
TextDrawBackgroundColor( td_SAClock[ 1 ], 255 );
TextDrawFont( td_SAClock[ 1 ], 1 );
TextDrawLetterSize( td_SAClock[ 1 ], 0.509999, 1.800000 );
TextDrawColor( td_SAClock[ 1 ], -1 );
TextDrawSetOutline( td_SAClock[ 1 ], 0 );
TextDrawSetProportional( td_SAClock[ 1 ], 1 );
TextDrawSetShadow( td_SAClock[ 1 ], 1 );
clockTimer = SetTimer( "SAClock_Update", 1000, true );
currentMinutes = 0;
currentHours = 0;
return 1;
}
public OnFilterScriptExit( )
{
TextDrawHideForAll( td_SAClock[ 0 ] );
TextDrawHideForAll( td_SAClock[ 1 ] );
KillTimer( clockTimer );
currentMinutes = -1;
currentHours = -1;
return 1;
}
public OnPlayerConnect( playerid )
{
TextDrawShowForPlayer( playerid, td_SAClock[ 0 ] );
TextDrawShowForPlayer( playerid, td_SAClock[ 1 ] );
return 1;
}
new string[ 7 ];
I'll create pawn Code: new string[ 7 ]; Instead of 128. |
( My code is more complex though ) |
I'll rate 7.0 in explaining, |
Note:That This Time system Takes 1 hour As one Min And 1second As 1min |