SA-MP Forums Archive
clock - 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: clock (/showthread.php?tid=413979)



clock - sscarface - 07.02.2013

clock is going so fast like this > 2:00 and then 2:20 > 2:40 > 3:00 > 3:20 > 3:40 >4:00 like this

here is script.

PHP код:
#include <a_samp>
forward RealHourUpdate();
new 
T_MIN=0T_HOUR=23T_DAY=0;
new 
WorldTime;
new 
Text:DAN;
new 
Text:Clock;
public 
OnPlayerSpawn(playerid)
{
TextDrawShowForAll(DAN);
TextDrawShowForAll(Clock);
return 
1;
}
public 
OnGameModeInit()
{
SetTimer("SetRandomWeather"420000true);
SetTimer("RealHourUpdate"1000true);
DAN TextDrawCreate(497.0000005.000000"/");
TextDrawFont(DAN3);
TextDrawLetterSize(DAN0.61.5);
TextDrawSetOutline(DAN2);
TextDrawSetProportional(DAN1);
TextDrawSetShadow(DAN1);
Clock TextDrawCreate(546.921.0"/");
TextDrawSetShadow(Clock1);
TextDrawSetOutline(Clock2);
TextDrawLetterSize(Clock0.62.4);
TextDrawFont(Clock3);
TextDrawSetProportional(Clock1);
return 
1;
}
public 
RealHourUpdate()
{
new 
hmsc;
gettime(hmsc);
if(
WorldTime != h)
{
WorldTime h;
SetWorldTime(T_HOUR);
}
T_MIN++;
if(
T_MIN == 60)
{
T_MIN=0;
T_HOUR++;
}
if(
T_HOUR == 24)
{
T_HOUR=0;
T_DAY++;
}
if(
T_DAY == 7)
{
T_DAY=0;
}
if(
T_DAY == 0)
{
TextDrawSetString(DAN,"Monday");
new 
string[]="Monday";
new 
result[156];
format(resultsizeof(result), "worldtime %s %02d:%02d",stringT_HOURT_MIN);
SendRconCommand(result);
}
if(
T_DAY == 1)
{
TextDrawSetString(DAN,"Tuesday");
new 
string[]="Tuesday";
new 
result[156];
format(resultsizeof(result), "worldtime %s %02d:%02d",stringT_HOURT_MIN);
SendRconCommand(result);
}
if(
T_DAY == 2)
{
TextDrawSetString(DAN,"Wednesday");
new 
string[]="Wednesday";
new 
result[156];
format(resultsizeof(result), "worldtime %s %02d:%02d",stringT_HOURT_MIN);
SendRconCommand(result);
}
if(
T_DAY == 3)
{
TextDrawSetString(DAN,"Thursday");
new 
string[]="Thursday";
new 
result[156];
format(resultsizeof(result), "worldtime %s %02d:%02d",stringT_HOURT_MIN);
SendRconCommand(result);
}
if(
T_DAY == 4)
{
TextDrawSetString(DAN,"Friday");
new 
string[]="Friday";
new 
result[156];
format(resultsizeof(result), "worldtime %s %02d:%02d",stringT_HOURT_MIN);
SendRconCommand(result);
}
if(
T_DAY == 5)
{
TextDrawSetString(DAN,"Saturday");
new 
string[]="Saturday";
new 
result[156];
format(resultsizeof(result), "worldtime %s %02d:%02d",stringT_HOURT_MIN);
SendRconCommand(result);
}
if(
T_DAY == 6)
{
TextDrawSetString(DAN,"Sunday");
new 
string[]="Sunday";
new 
result[156];
format(resultsizeof(result), "worldtime %s %02d:%02d",stringT_HOURT_MIN);
SendRconCommand(result);
}
new 
string[256];
if(
T_MIN 10)
    {
        if(
T_HOUR 10)
        {
            
format(string,sizeof(string),"0%d:0%d",T_HOUR,T_MIN);
            
TextDrawSetString(Clock,string);
        }
        else
        {
            
format(string,sizeof(string),"%d:0%d",T_HOUR,T_MIN);
            
TextDrawSetString(Clock,string);
        }
        }
        else
        {
        if(
T_HOUR 10)
        {
            
format(string,sizeof(string),"0%d:%d",T_HOUR,T_MIN);
            
TextDrawSetString(Clock,string);
        }
        else
        {
            
format(string,sizeof(string),"%d:%d",T_HOUR,T_MIN);
            
TextDrawSetString(Clock,string);
        }
        }
        
/*new str[256];
format(str, 256, "worldtime %02d:%02d", T_HOUR, T_MIN);
SendRconCommand(str);*/
for(new g=0;g<200;g++)
{
}




Re: clock - Scenario - 07.02.2013

pawn Код:
SetTimer("RealHourUpdate", 1000, true);
You're calling this timer every second...? I think you want to call it every MINUTE, not every SECOND. So, change 1000 to 60000.

Timers are in milliseconds, so 500 is 500ms (which is 1/2 of a second). So, 30000 is 30 seconds, 60000 is 60 seconds (or one minute).

See if that helps. Your code is confusing the hell out of me, probably because I'm just now waking up.


Re: clock - sscarface - 07.02.2013

sorry for late reply but i know about the timer and i set it and now time is going to slow but the problem is

the time is going like this > > 2:00 and then 2:20 > 2:40 > 3:00 > 3:20 > 3:40 >4:00 l

and i want like this > > 2:00 and 2:01 > 2:02 > 2:03 l


Re: clock - Misiur - 07.02.2013

Your code hurts my eyes

pawn Код:
#include <a_samp>

forward RealHourUpdate();
new T_DAY = 0, WorldTime, Text:DAN, Text:Clock;

public OnPlayerSpawn(playerid)
{
    TextDrawShowForAll(DAN);
    TextDrawShowForAll(Clock);
    return 1;
}

public OnGameModeInit()
{
    SetTimer("SetRandomWeather", 420000, true);
    SetTimer("RealHourUpdate", 1000, true);

    DAN = TextDrawCreate(497.000000, 5.000000, "/");
    TextDrawFont(DAN, 3);
    TextDrawLetterSize(DAN, 0.6, 1.5);
    TextDrawSetOutline(DAN, 2);
    TextDrawSetProportional(DAN, 1);
    TextDrawSetShadow(DAN, 1);

    Clock = TextDrawCreate(546.9, 21.0, "/");
    TextDrawSetShadow(Clock, 1);
    TextDrawSetOutline(Clock, 2);
    TextDrawLetterSize(Clock, 0.6, 2.4);
    TextDrawFont(Clock, 3);
    TextDrawSetProportional(Clock, 1);

    return 1;
}

public RealHourUpdate()
{
    new h, m, sc;
    gettime(h, m, sc);
    if(WorldTime != h)
    {
        WorldTime = h;
        SetWorldTime(WorldTime);
    }
   
    if(0 == h && 0 == m && 0 == sc) ++T_DAY;
   
    new string[16];
    switch(T_DAY) {
        case 0: strcat(string, "Monday");
        case 1: strcat(string, "Tuesday");
        case 2: strcat(string, "Wednesday");
        case 3: strcat(string, "Thursday");
        case 4: strcat(string, "Friday");
        case 5: strcat(string, "Saturday");
        case 6: strcat(string, "Sunday");
    }
    TextDrawSetString(DAN, string);
   
    new result[33];
    format(result, sizeof(result), "worldtime %s %02d:%02d",string, h, m);
    SendRconCommand(result);
   
    format(string,sizeof(string),"%02d:%02d",h,m);
    TextDrawSetString(Clock, string);
}
@e: removed unnecessary boolean


Re: clock - sscarface - 07.02.2013

worked and thanx its slow running i want make it fast like second so should i increased timer?


Re: clock - Misiur - 07.02.2013

Nope, timer is fine

pawn Код:
//change
    new result[33];
    format(result, sizeof(result), "worldtime %s %02d:%02d",string, h, m);
    SendRconCommand(result);
   
    format(string,sizeof(string),"%02d:%02d",h,m);
    TextDrawSetString(Clock, string);

//to
    new result[40];
    format(result, sizeof(result), "worldtime %s %02d:%02d:%02d",string, h, m, sc);
    SendRconCommand(result);
   
    format(string,sizeof(string),"%02d:%02d:%02d", h, m, sc);
    TextDrawSetString(Clock, string);
@e: Ok, so you want minute ingame equal to second in real world. We can't use gettime then

pawn Код:
#include <a_samp>

forward RealHourUpdate();
new T_DAY, h, m, WorldTime, Text:DAN, Text:Clock;

public OnPlayerSpawn(playerid)
{
    TextDrawShowForAll(DAN);
    TextDrawShowForAll(Clock);
    return 1;
}

public OnGameModeInit()
{
    SetTimer("SetRandomWeather", 420000, true);
    SetTimer("RealHourUpdate", 1000, true);

    DAN = TextDrawCreate(497.000000, 5.000000, "/");
    TextDrawFont(DAN, 3);
    TextDrawLetterSize(DAN, 0.6, 1.5);
    TextDrawSetOutline(DAN, 2);
    TextDrawSetProportional(DAN, 1);
    TextDrawSetShadow(DAN, 1);

    Clock = TextDrawCreate(546.9, 21.0, "/");
    TextDrawSetShadow(Clock, 1);
    TextDrawSetOutline(Clock, 2);
    TextDrawLetterSize(Clock, 0.6, 2.4);
    TextDrawFont(Clock, 3);
    TextDrawSetProportional(Clock, 1);

    return 1;
}

public RealHourUpdate()
{
    //No need for flooring, as the integer will do it itself
    m++;
    m %= 60;   
    h = (sc / 60) % 24;

    if(WorldTime != h)
    {
        WorldTime = h;
        SetWorldTime(WorldTime);
    }
   
    if(0 == h && 0 == m) ++T_DAY;
   
    new string[16];
    switch(T_DAY) {
        case 0: strcat(string, "Monday");
        case 1: strcat(string, "Tuesday");
        case 2: strcat(string, "Wednesday");
        case 3: strcat(string, "Thursday");
        case 4: strcat(string, "Friday");
        case 5: strcat(string, "Saturday");
        case 6: strcat(string, "Sunday");
    }
    TextDrawSetString(DAN, string);
   
    new result[33];
    format(result, sizeof(result), "worldtime %s %02d:%02d",string, h, m);
    SendRconCommand(result);
   
    format(string,sizeof(string),"%02d:%02d",h,m);
    TextDrawSetString(Clock, string);
}



Re: clock - sscarface - 07.02.2013

thanx


Re: clock - Misiur - 07.02.2013

Oh, there is an error in my code:
pawn Код:
h = (sc / 60) % 24;
//changes to
h = (m / 60) % 24;
also
pawn Код:
if(0 == h && 0 == m) ++T_DAY;
//add below
T_DAY %= 7;
Regarding your question on my wall - could you explain it a little more?


Re: clock - sscarface - 07.02.2013

let me explain,

time going like this > 2:01 >2:02 >2:03 > 2:04 >2:05 > 2:06 > 2:07 >2:9 > 2:10 > 2:11 >2:12 > 2:13 > 2:14 >2:15 > 2:16 > 2:17 >2:18 > 2:20 > 2:21 >2:22 >

note it on 2:9 they ignore 2:08 and 2:19 this is example but they are ignoring 1 number alwayz in count.

and i don't understand you're code like this?

PHP код:
public RealHourUpdate()
{
    
m++;
    
%= 60;
    
= (sc 60) % 24;
    new 
hmsc;
    
gettime(hmsc);
    if(
WorldTime != h)
    {
        
WorldTime h;
        
SetWorldTime(WorldTime);
    }

    if(
== && == && == sc) ++T_DAY %= 7;

    new 
string[16];
    switch(
T_DAY) {
        case 
0strcat(string"Monday");
        case 
1strcat(string"Tuesday");
        case 
2strcat(string"Wednesday");
        case 
3strcat(string"Thursday");
        case 
4strcat(string"Friday");
        case 
5strcat(string"Saturday");
        case 
6strcat(string"Sunday");
    }
    
TextDrawSetString(DANstring);

    new 
result[40];
    
format(resultsizeof(result), "worldtime %s %02d:%02d",stringmsc);
    
SendRconCommand(result);

    
format(string,sizeof(string),"%02d:%02d"msc);
    
TextDrawSetString(Clockstring);