10.09.2011, 09:36
(
Last edited by AceFlyer; 10/09/2011 at 04:22 PM.
)
This tutorial Is About Making a time system For SAMP Using Text draws
As Timers Which Show The Time of the Day like In Single Player were Removed In Multiplayer This System Might come In Handy
Some Functions You Should know To Fully Understand This Tut:
https://sampwiki.blast.hk/wiki/Category:...ions#Textdraws
https://sampwiki.blast.hk/wiki/SetTimer
First Of All Lets Start With The Includes:
Next The Defines(You Can use Any Color Defines But Remember To Change The stuff on The functions)
Next We start With the Actual scripting:
These Are Global Variables
Put The Above code At The top Of Your Script
Next We Actually Create Textdraws To show The Time On:
Ok Now To explain That Last Step:
This Part Creates The Text draw Above The Health Bar (You Can Change cords if you like)
The Line After That Sets The Textdraw Color To White
[/PAWN]
This Sets Both The Variables Of Mins And Hrs To 0 This Can be set to whatever time You Want to start at When you Restart Server
This Sets a Timer Which Repeats every 1000 milliseconds That is 1 second
We now have to set up The Timer for This We First Forward the timer
Now We Can Create a Timer
Oh And Finally To Show The Textdraws
Note:That This Time system Takes 1 hour As one Min And 1second As 1min
Hope This Helps You This Is My First Tutorial
As Timers Which Show The Time of the Day like In Single Player were Removed In Multiplayer This System Might come In Handy
Some Functions You Should know To Fully Understand This Tut:
https://sampwiki.blast.hk/wiki/Category:...ions#Textdraws
https://sampwiki.blast.hk/wiki/SetTimer
First Of All Lets Start With The Includes:
pawn Code:
#include <a_samp>
pawn Code:
#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
These Are Global Variables
pawn Code:
// new variables
new Text:Servt; //Server Time Text draw Variable
new Tsec; //stores the mins of time
new THrs; //stores hours of time
Next We Actually Create Textdraws To show The Time On:
pawn Code:
public OnGameModeInit()
{
Servt=TextDrawCreate(545, 31, "00:00");
TextDrawColor(Servt, COLOR_WHITE);
Tsec= 0;
THrs= 0;
SetTimer("TimeU",1000,true);
return 1;
}
pawn Code:
Servt=TextDrawCreate(545, 31, "00:00");
TextDrawColor(Servt, COLOR_WHITE);
The Line After That Sets The Textdraw Color To White
[/PAWN]
pawn Code:
Tsec= 0;
THrs= 0;
pawn Code:
SetTimer("TimeU",1000,true);
We now have to set up The Timer for This We First Forward the timer
pawn Code:
forward TimeU();
pawn Code:
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
}
pawn Code:
Public OnPlayerSpawn(playerid)
{
TextDrawShowForPlayer(playerid,Servt);
return 1;
}
Hope This Helps You This Is My First Tutorial