Payday check
#1

Hi, I was wondering if there is better method than using a 1 sec global timer for paycheck

Код:
task GlobalTimer[1000]()
{
	new H, M, S;
	gettime(H, M, S);
	
    foreach(new i: Player)
    {
        if(!PlayerInfo[i][IsLoggedIn]) continue;
       
		if(M == 0 && S == 0)
		{
		    if(PlayerInfo[i][pConnectedTime] >= 25)
		    {
		    	// If the player have at least 25 minutes played during the entire hour.
		    	PlayerInfo[i][pConnectedTime] = 0;
			}
			else
			{		
				// If not SendErrorMessage
			}
		}
		else if(S == 0)
		{
			// Add +1 each minutes
		    if(PlayerInfo[i][pConnectedTime] < 25)
		    {
		        ++PlayerInfo[i][pConnectedTime];
			}
		}
	}
	return 1;
}
Reply
#2

there is no need to do it every millisecond right? A second is enough i guess, maybe even more than a second
Reply
#3

I meant 1000 ms * 1 sec sorry
Reply
#4

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
Reply
#5

I was considering GetTickCount but I'm not quite sure how to proceed
Reply
#6

Quote:
Originally Posted by [Bios]Marcel
Посмотреть сообщение
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
This is also a correct opinion,

"This callback is called, on average, 30 times per second, per player; only use it when you know "
Reply
#7

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(newTickoldTick

    if (
oldTick && newTick >= 0) { 
        return 
newTick oldTick
    } else if (
oldTick >= && newTick || 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
Reply
#8

Quote:

4. check if the difference (in ms) is more or equal to 25 minutes (assuming u want the payday to hapen every 25 minutes)

Not every 25 minutes, every hour like so but to be eligible to get paid, he needs at least 25 minutes played during that entire hour.

That's why I need to increment PlayerInfo[playerid][pConnectedTime] every minutes then every hour server time if he played 25 minutes, it gets reset
Reply
#9

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(newTickoldTick

    if (
oldTick && newTick >= 0) { 
        return 
newTick oldTick
    } else if (
oldTick >= && newTick || oldTick newTick) { 
        return (
cellmax oldTick 1) - (cellmin newTick); 
    } 
    return 
newTick oldTick

Hope i understood your needs.
Reply
#10

Got it thanks, I knew I could do it without checking every seconds, way better every hour, thanks !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)