View Single Post
Old 17/01/2020, 04:19 PM   #4
FunnyBear
Gangsta
 
Join Date: Mar 2013
Posts: 510
Reputation: 15
Default Re: Make the world time the same for everyone

Put this together quickly

pawn Code:
new Text:td_time, Text:td_day, g_time = 0, g_day = 0;

#define MINUTE  1800
//define your minute in milliseconds (1.8 seconds in a game minute)

//OnGameModeInit

td_time = TextDrawCreate(577.000000, 20.000000, "00:00");
TextDrawFont(td_time, 3);
TextDrawLetterSize(td_time, 0.554166, 2.449999);
TextDrawTextSize(td_time, 400.000000, 17.000000);
TextDrawSetOutline(td_time, 2);
TextDrawSetShadow(td_time, 0);
TextDrawAlignment(td_time, 2);
TextDrawColor(td_time, -1);
TextDrawBackgroundColor(td_time, 255);
TextDrawBoxColor(td_time, 50);
TextDrawUseBox(td_time, 0);
TextDrawSetProportional(td_time, 1);
TextDrawSetSelectable(td_time, 0);

td_day = TextDrawCreate(577.000000, 8.000000, "_");
TextDrawFont(td_day, 3);
TextDrawLetterSize(td_day, 0.266665, 1.299998);
TextDrawTextSize(td_day, 400.000000, 17.000000);
TextDrawSetOutline(td_day, 2);
TextDrawSetShadow(td_day, 0);
TextDrawAlignment(td_day, 2);
TextDrawColor(td_day, -1);
TextDrawBackgroundColor(td_day, 255);
TextDrawBoxColor(td_day, 50);
TextDrawUseBox(td_day, 0);
TextDrawSetProportional(td_day, 1);
TextDrawSetSelectable(td_day, 0);

SetTimer("Timer", MINUTE, 1); //initiate the timer


//OnPlayerConnect
TogglePlayerClock(playerid, 0); //disables default server clock so you can set your own


//somewhere in your script
stock GetDayName()
{
    new dayname[9];
    switch(g_day)
    {
        case 0: format(dayname, sizeof(dayname), "Monday");
        case 1: format(dayname, sizeof(dayname), "Tuesday");
        case 2: format(dayname, sizeof(dayname), "Wednesday");
        case 3: format(dayname, sizeof(dayname), "Thursday");
        case 4: format(dayname, sizeof(dayname), "Friday");
        case 5: format(dayname, sizeof(dayname), "Saturday");
        case 6: format(dayname, sizeof(dayname), "Sunday");
    }
    return dayname;
}

forward Timer();
public Timer()
{
    g_time ++;
    for (new i=0; i<MAX_PLAYERS; i++)
    {
        new
            str[20],
            gseconds = g_time % 60,
            gminutes = (g_time - gseconds) / 60;

        format(str, sizeof (str), "%02d:%02d", gminutes, gseconds);
        TextDrawSetString(td_time, str);
        TextDrawShowForPlayer(i, td_time);

        format(str, sizeof (str), "%s", GetDayName());
        TextDrawSetString(td_day, str);
        TextDrawShowForPlayer(i, td_day);

        if(g_day == 6 && g_time == 1440) //if week is over
        {
            g_day = 0, g_time = 0;
        }
        else if(g_time == 1440) //if day is over
        {
            g_day ++, g_time = 0;
            format(str, sizeof (str), "00:00");
            TextDrawSetString(td_time, str);
        }
        SetPlayerTime(i, gminutes, gseconds); //set global time (darkness changes depending on the hour)
    }
    return 1;
}
FunnyBear is offline   Reply With Quote