SA-MP Forums Archive
SetWorldTime issue. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SetWorldTime issue. (/showthread.php?tid=516980)



SetWorldTime issue. - Aerotactics - 02.06.2014

In my script, I've modified the gl_realtime to be a custom time speed, however, when I try to set the server time to the hour, 1am - 12pm work fine, but at 1 pm, the time sets to night again, and from 1pm to 12am, the time acts as if it were 1am - 12pm. This was supposed to be a straightforward script, but it's just not.

-gamehour is the setworldtime hour
-IsMorning is a bool for am/pm

EDIT: To clarify, I'm not looking for a script re-write. I simply want to know why this isn't working the way it should. The problem still exists.

This script is in a clock.
pawn Код:
minute++;
if(minute == 60)
{
    minute = 0;
    hour++;
    gamehour++;
}
if(hour == 12 && minute == 0)
{
    if(IsMorning == true){IsMorning = false;}
    else{IsMorning = true;}
}
if(hour == 13){hour = 1;}
if(gamehour == 24){gamehour = 0;}
if(gamehour == 0 && minute == 0){day++;}
if(day == 7){day = 0;}
SetWorldTime(gamehour);
13 is the gamehour output, which should correspond to 1 pm on a 12 hour clock, but it doesn't





Re: SetWorldTime issue. - Threshold - 02.06.2014

pawn Код:
minute++;
if(minute == 60)
{
    minute = 0;
    hour++;
    gamehour++;
}
if(hour == 12 && minute == 0)
{
    if(IsMorning == true){IsMorning = false;}
    else{IsMorning = true;}
}
if(hour == 13){hour = 1;}
if(gamehour == 24){gamehour = 0;}
if(gamehour == 0 && minute == 0){day++;}
if(day == 7){day = 0;}
SetWorldTime(gamehour);
Where is this coming from?


Re: SetWorldTime issue. - Aerotactics - 03.06.2014

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
pawn Код:
minute++;
if(minute == 60)
{
    minute = 0;
    hour++;
    gamehour++;
}
if(hour == 12 && minute == 0)
{
    if(IsMorning == true){IsMorning = false;}
    else{IsMorning = true;}
}
if(hour == 13){hour = 1;}
if(gamehour == 24){gamehour = 0;}
if(gamehour == 0 && minute == 0){day++;}
if(day == 7){day = 0;}
SetWorldTime(gamehour);
Where is this coming from?
A timer.


Re: SetWorldTime issue. - Aerotactics - 03.06.2014

Bump


Re: SetWorldTime issue. - Threshold - 03.06.2014

What's the point of adding 'gamehour'? Why don't you just SetWorldTime(hour); ??


Re: SetWorldTime issue. - Aerotactics - 04.06.2014

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
What's the point of adding 'gamehour'? Why don't you just SetWorldTime(hour); ??
Because "hour" is representing time on a 12 hour clock, not a 24 hour clock.


Re: SetWorldTime issue. - Dignity - 04.06.2014

I personally don't see the point in editing scripts, it'll take you more time to understand the script you're editing than it'll take you making one from scratch. Also, you could've simplified above code easily.

Here's an example, I made this in five minutes using an array instead of 50 variables determining what day/time it is.

time[0] = hours
time[1] = minutes
time[2] = AM/PM
time[3] = day

pawn Код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>

new time[4];

public OnPlayerConnect(playerid)
{
    SetTimerEx("worldtime", 60000, true, "i", playerid); // 60 sec; realtime
   
    return true;
}

CMD:settime(playerid, params[])
{
    new input[7], value, string[20];
   
    if(sscanf(params, "s[7]i", input, value)) return SendClientMessage(playerid, -1, "/settime [hour/minutes] [value]");

    if(strcmp(input, "hour", true)) time[0] = value;
    else if(strcmp(input, "minutes", true)) time[1] = value;

    format(string, sizeof(string), "%s set to %d", input, value);
    SendClientMessage(playerid, -1, string);

    SetWorldTime(hour);

    return true;
}

forward worldtime(playerid);
public worldtime(playerid)
{
    new formatx[7];

    if(time[1] < 60) // minutes
    {
        format(formatx, sizeof(formatx), "%d/%d", time[0], time[1]);
        // textdraw changes

        time[1] += 1;
        SetWorldTime(time[0]);
    }

    else if(time[0] >= 12 || time[1] >= 60) // hours/min changing
    {
        if(time[0] < 12) time[0] += 1;
        else if(time[0] == 12) time[0] = 0;

        if(time[2] == 0) time[2] += 1;
        else if(time[2] == 1)
        {
            time[2] = 0;

            if(time[3] < 7) time[3] += 1;
            else if(time[3] >= 7) time[3] = 1;
        }

        if(time[2] == 0) format(formatx, sizeof(formatx), "%d/%d AM", time[0], time[1]);
        else if(time[2] == 1) format(formatx, sizeof(formatx), "%d/%d PM", time[0], time[1]);
        // textdraw changes

        time[1] = 0;
        SetWorldTime(time[0]);
    }

    return true;
}
The above compiles but hasn't been tested. It's just an example though.


Re: SetWorldTime issue. - Aerotactics - 10.06.2014

@Mionee I know it can be simplified, but I chose to rewrite the gl_realtime fs because it included the weather and textdraw, etc. This issue is still a problem for me, setworldtime still isn't working properly.


Re: SetWorldTime issue. - Threshold - 10.06.2014

I will re-do this script for you when I get time, I am currently in class. I will send you a message when I have edited it properly.


Re: SetWorldTime issue. - Aerotactics - 10.06.2014

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
I will re-do this script for you when I get time, I am currently in class. I will send you a message when I have edited it properly.
Ok, thanks. Everything works, but the SetWorldTime doesn't, and I'm assuming it's on a 0-23 input. The wiki isn't any help.