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



Payday check - vernz - 06.01.2017

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;
}



Re: Payday check - BiosMarcel - 06.01.2017

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


Re: Payday check - vernz - 06.01.2017

I meant 1000 ms * 1 sec sorry


Re: Payday check - BiosMarcel - 06.01.2017

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


Re: Payday check - vernz - 06.01.2017

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


Re: Payday check - ISmokezU - 06.01.2017

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 "


Re: Payday check - BiosMarcel - 06.01.2017

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


Re: Payday check - vernz - 06.01.2017

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


Re: Payday check - BiosMarcel - 06.01.2017

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.


Re: Payday check - vernz - 06.01.2017

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