Posts: 1,219
Threads: 51
Joined: Jul 2012
there is no need to do it every millisecond right? A second is enough i guess, maybe even more than a second
Posts: 230
Threads: 36
Joined: Dec 2010
Reputation:
0
I meant 1000 ms * 1 sec sorry
Posts: 1,219
Threads: 51
Joined: Jul 2012
Well so basically, there are some ways:
1. Use a global timer, like you do
2. Per player timers
3. OnPlayerUpdate
I'd consider a global timer using foreach (like u do), that's just my opinion though
Posts: 230
Threads: 36
Joined: Dec 2010
Reputation:
0
I was considering GetTickCount but I'm not quite sure how to proceed
Posts: 1,219
Threads: 51
Joined: Jul 2012
Well, basically you have to do five things
1. Get the TickCount under OnPlayerConnect (furthermore at the point where he actually logs in)
2. Get the TickCount inside of your timer function
3. Get the difference using for example this method:
PHP код:
stock getTickDiff(newTick, oldTick)
{
if (oldTick < 0 && newTick >= 0) {
return newTick - oldTick;
} else if (oldTick >= 0 && newTick < 0 || oldTick > newTick) {
return (cellmax - oldTick + 1) - (cellmin - newTick);
}
return newTick - oldTick;
}
4. check if the difference (in ms) is more or equal to 25 minutes (assuming u want the payday to hapen every 25 minutes)
5. reset the "connectedTickCount" and do the payout
OR you just create a playertimer doing a payout every 25 minutes, as soon he connects
Posts: 1,219
Threads: 51
Joined: Jul 2012
You could do this:
PHP код:
new connectTick[MAX_PLAYERS];
public OnGameModeInit()
{
SetTimer("paydaycheck", 3600000/*1 Hour*/, true);
}
public OnPlayerConnect(playerid)
{
connectTick[playerid] = GetTickCount();
}
forward paydaycheck();
public paydaycheck()
{
foreach(new player : Player)
{
new tickDifference = getTickDiff(GetTickCount(), connectTick[playerid]);
if(tickDifference >= 1500000/*25 Minutes*/)
{
PAYDAY();
}
}
}
stock getTickDiff(newTick, oldTick)
{
if (oldTick < 0 && newTick >= 0) {
return newTick - oldTick;
} else if (oldTick >= 0 && newTick < 0 || oldTick > newTick) {
return (cellmax - oldTick + 1) - (cellmin - newTick);
}
return newTick - oldTick;
}
Hope i understood your needs.
Posts: 230
Threads: 36
Joined: Dec 2010
Reputation:
0
Got it thanks, I knew I could do it without checking every seconds, way better every hour, thanks !