Every hour and half a hour
#1

Hi guys

I want to make timer with which I will be able to do some thing every hour and half a hour.
For example( 00:00 00:30 01:00 01:30 02:00 ... 06:00 06:30 etc )

I want to start an race event in 00:00 ,in 00:30 i want to start derby event etc...it's example.


I'm use this:

Код:
task OneMinuteTimer[60000]()
{
	new hours,minutes,seconds;
	gettime(hours,minutes,seconds);
	if(minutes == 30)
	{
		if(hours == 1)
		{
		//This is 01:30
		}
		else if(hours == 2)
		{
		//This is 02:30
		}
	else if(minutes == 0)
	{
		if(hours == 1)
		{
		//This is 01:00
		}
		else if(hours == 2)
		{
		//This is 02:00
		}
	}
	return 1;
}
Now,problem is that sometimes happend that timer omissions some hour.
If timer is called in 02:59:59 and next time in 03:01:01 i can't do anything in 03:00 ..Because my code don't will work in it case.

Do you have any better suggestion?
Reply
#2

includes your code in an already created timer that works from second to second.
Reply
#3

Quote:
Originally Posted by Florin48
Посмотреть сообщение
includes your code in an already created timer that works from second to second.
If i'm understand you..You think that i check every second if is now xx:00 or xx:30? But if i do it 'n one-second timer i will have true case 59 times on minute...
Reply
#4

try a 35-second timer, it's going to go wrong and there's no error.

or try to make a half-hour timer.
Reply
#5

this is a timer that runs every 35 seconds, try it.

PHP код:
task OneMinuteTimer[35000]()
{
    new 
hours,minutes,seconds;
    
gettime(hours,minutes,seconds);
    switch(
hours)
    {
        case 
0:
        {
            switch(
minutes)
            {
                case 
0:
                case 
30:
            }
        }
        case 
1:
        {
            switch(
minutes)
            {
                case 
0:
                case 
30:
            }
        }
        case 
2:
        case 
3:
        case 
4:
        case 
5:
        case 
6:
    }
    return 
1;

the code was not tested, try it.
Reply
#6

Thank you.But problem with sa-mp is which timer are not exact..It can vary in few seconds.With my code,it will miss some hours,but with 35 seconds I fear that may it can be called 2 times...But i will test it
Reply
#7

Quote:
Originally Posted by GospodinX
Посмотреть сообщение
Thank you.But problem with sa-mp is which timer are not exact..It can vary in few seconds.With my code,it will miss some hours,but with 35 seconds I fear that may it can be called 2 times...But i will test it
uses a timerfix to be more accurate timer.
Reply
#8

Still don't know how to make it..I'm test with 35 seconds but :

Timer is call two times in one hour

Quote:

15:00:02
15:00:38

I need just one time in one hour...
Reply
#9

Why don't you make the timer every 1 second?? And use timerfix plugin, and check if the time is XX:00 or XX:30 and done..
Reply
#10

Quote:
Originally Posted by JasonRiggs
Посмотреть сообщение
Why don't you make the timer every 1 second?? And use timerfix plugin, and check if the time is XX:00 or XX:30 and done..
Hah..
But if i set it on 1 second,it will be called 60 times on minute

Код:
if(hours == 15 && minute == 0) // 15:00 
{
//This will be called 60 times,i need it just one time...
//If I here start event in this code,it will be started 60 times..
}
Reply
#11

try to add second in verification

if(hours == 15 && minute == 0 && second == 0) // 15:00
{
Reply
#12

Quote:
Originally Posted by Florin48
Посмотреть сообщение
try to add second in verification

if(hours == 15 && minute == 0 && second == 0) // 15:00
{
Timers are not 100% correct..Sometimes it don't will work..sometimes it will be called for example:
Quote:

14:59:59
and next time in
15:00:01

(tested)
Reply
#13

use a timerfix or try

if(hours == 15 && minute == 0 && (second == 0 || second == 1) // 15:00
{
...
}

or you can use a global variable. ex:

PHP код:
new YourVariableName 0;
if(
hours == 15 && minute == && YourVariableName == 0// 15:00 
{
YourVariableName =1;
...

there are different ways to solve a problem.
Reply
#14

That's WHY I'm saying set a 1 second timer! To be more accurate..
Reply
#15

Quote:
Originally Posted by JasonRiggs
Посмотреть сообщение
That's WHY I'm saying set a 1 second timer! To be more accurate..
As he said, timers are not accurate.


Why not do it this way?
PHP код:
task JustARandomTimer[1000]()
{
    static 
pastMinutes = -1;
    new 
hoursminutesseconds;
    
gettime(hoursminutesseconds);
    
// Initial pastMinutes variable
    
if (pastMinutes == -1) {
        
pastMinutes minutes;
    }
    if (
minutes 30 && pastMinutes >= 30) {
        
pastMinutes 0;
        
// Do something under xx:30, called once.
    
}
    else if (
minutes >= 30 && pastMinutes 30) {
        
pastMinutes 30;
        
// Do something above xx:30, called once.
    
}
    return 
1;

Reply
#16

Why are you using shorter and shorter timers? If you want something to happen once an hour, use a one hour timer:

Код:
task RaceTimer[60 * 60 * 1000]()
{
    // Called once an hour - no messing, no misses!
}
Simple!

Then use the timerfix plugin to improve the accuracy. Don’t use ad-hoc half-baked pawn solutions that just end up vastly more complex code.
Reply
#17

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
Why are you using shorter and shorter timers? If you want something to happen once an hour, use a one hour timer:

Код:
task RaceTimer[60 * 60 * 1000]()
{
    // Called once an hour - no messing, no misses!
}
Simple!

Then use the timerfix plugin to improve the accuracy. Don’t use ad-hoc half-baked pawn solutions that just end up vastly more complex code.
but if I start the server at 13:26 and I want the event to start at 13:30, this one-hour timer will not start when the server is opened at 13:26 and the next time it is accessed will be at 14: 26 and I wanted it at 13:30.
Or y_timer library works differently?
Reply
#18

The fact that you wanted it ON the hour was not clear at all from your initial post. You did say "for example", but that doesn't to me mean "exclusively". In that case, timers are not at all the right way to go about this - you should be using `gettime`.
Reply
#19

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
The fact that you wanted it ON the hour was not clear at all from your initial post. You did say "for example", but that doesn't to me mean "exclusively". In that case, timers are not at all the right way to go about this - you should be using `gettime`.
I did not create the original post, I just said the requirements that the one who needed the help wanted, gave an example at first you had to look and see that one hour timer would be useless for him.
Reply
#20

Quote:

In that case, timers are not at all the right way to go about this - you should be using `gettime`.

But where to use gettime? I don't understand.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)