[Tutorial] Time System
#1

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:
pawn Code:
#include <a_samp>
Next The Defines(You Can use Any Color Defines But Remember To Change The stuff on The functions)
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
Next We start With the Actual scripting:
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
Put The Above code At The top Of Your Script

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;
}
Ok Now To explain That Last Step:
pawn Code:
Servt=TextDrawCreate(545, 31, "00:00");
TextDrawColor(Servt, COLOR_WHITE);
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]

pawn Code:
Tsec= 0;
THrs= 0;
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
pawn Code:
SetTimer("TimeU",1000,true);
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
pawn Code:
forward TimeU();
Now We Can Create a Timer
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

}
Oh And Finally To Show The Textdraws
pawn Code:
Public OnPlayerSpawn(playerid)
{
TextDrawShowForPlayer(playerid,Servt);

return 1;
}
Note:That This Time system Takes 1 hour As one Min And 1second As 1min
Hope This Helps You This Is My First Tutorial
Reply


Messages In This Thread
Time System - by AceFlyer - 10.09.2011, 09:36
Re: Time System - by Lorenc_ - 10.09.2011, 09:37
Re: Time System - by AceFlyer - 10.09.2011, 09:39
Re: Time System - by Xx_OutLawZ_xX - 10.09.2011, 09:42
Re: Time System - by Darnell - 10.09.2011, 09:58
Re: Time System - by System64 - 10.09.2011, 10:50
Re: Time System - by kurta999 - 10.09.2011, 10:56
Re: Time System - by =WoR=G4M3Ov3r - 10.09.2011, 11:30
Re: Time System - by Davz*|*Criss - 10.09.2011, 12:25
Re: Time System - by Wesley221 - 10.09.2011, 13:49
Re: Time System - by AceFlyer - 10.09.2011, 14:36
Re: Time System - by Basicz - 10.09.2011, 14:46
Re: Time System - by AceFlyer - 10.09.2011, 16:02
Re: Time System - by System64 - 10.09.2011, 16:07
Re: Time System - by AceFlyer - 10.09.2011, 16:10
Re: Time System - by AceFlyer - 10.09.2011, 16:20
Re: Time System - by System64 - 10.09.2011, 16:26
Re: Time System - by System64 - 10.09.2011, 19:07
Re: Time System - by AceFlyer - 11.09.2011, 04:08
Re: Time System - by System64 - 11.09.2011, 05:26
Re: Time System - by AceFlyer - 11.09.2011, 11:23
Re: Time System - by Millionaire - 11.09.2011, 12:03
Re: Time System - by GAMER_PS2 - 30.10.2011, 11:16
Re: Time System - by Tanush123 - 21.01.2012, 20:12

Forum Jump:


Users browsing this thread: 1 Guest(s)