Payday isn't working
#1

Hey, I've had this payday timer for a while and not got it working, so I am resorting to here.

Код:
forward Payday();
public Payday() {
	new hour, minute, second, String[200];
	gettime(hour, minute, second);
	if(minute == 0 && second == 0) {
		foreach(new i : Player) {
		    if(IsPlayerConnected(i)) {
				PlayerInfo[i][pBank] += 5*PlayerInfo[i][pLevel];
				SendClientMessage(i, COLOR_WHITE, "{006AFF}_____|{0048AD}PAYDAY{006AFF}|_____");
		        format(String, sizeof String, "{006AFF}New Balance: {ADADAD}$%d", PlayerInfo[i][pBank]);
		        SendClientMessage(i, COLOR_WHITE, String);

				format(String, sizeof String, "SERVER: {FFFFFF}New server time, %02d:%02d.", hour, minute);
				SendClientMessage(i, COLOR_TANNED, String);
			}
		}
	  	FixHour(hour);
		SetWorldTime(hour);
	}
	return 1;
}
That code runs on a timer for each minute, I know that's a bad idea, can you see any reasons why it doesn't trigger on each hour?
Reply
#2

For example:

you timer call Payday every 60sek and you start you timer at 22:31:15
after 60sek
Quote:

//time is 22:32:15
//minute is 32 and second is 15
if(minute == 0 && second == 0)
//after 28min
//time is 23:00:15
//minute is 00 and second is 15
if(minute == 0 && second == 0)

i hope you understand this is not best way to test is one hour pass
may be this way
Quote:

// public new OLD_HOUR;
if(hour != OLD_HOUR)
OLD_HOUR = hour;

Reply
#3

I have no idea what you just said. Sorry.
Reply
#4

VV there you go. ;\
Reply
#5

What he means is your calling every 60 seconds which means if you start the timer at say 8:31:34 you'll never get minutes and seconds 0 it will always be some value well it is possible I suppose since 60000 ticks is really about 1:07. Anyways you got a couple of options here set your update timer to 49170 (55 seconds approx) then simply check for when the minute is zero and ignore the second as mentioned by infinity (his solution will create other problems without doing what I am explaining)

To make sure it doesn't activate twice in a minute which is possible use this...

LastPayDayTime = GetTickCount()

Then check..... if(GetTickCount() - LastPayDayTime > 60000) when your minute is zero hope that helps! Just remember it won't give the pay day on exactly when the hour hits but will sometime during that minute.
Reply
#6

Ah, I see! I'll tinker about with it and post back some result, thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)