Get the unix timestamp of the user when he connects, and then get it again on payday.
Subtract the one you got on the payday from the one when he connected, and than divide it by 60, that'll be the total amount of minutes he's been connected
Heres a quick example i wrote, haven't tested it but it should work
pawn Код:
//This goes at the top of the script or something, you can use whatever variables you'd like
enum data
{
connect
};
new Player[MAX_PLAYERS][data];
//Get the player time and save it to variable
public OnPlayerConnect(playerid)
{
//save the timestamp when player connects, you can use whatever variable you like
Player[playerid][connect] = gettime();
}
//a little function i just wrote to get us either playing time in seconds, minutes, hours, or days
//f signifies what format you want the time in:
// 0 = seconds
// 1 = minutes
// 2 = hours
// 3 = days
stock getPlayerPlayingTime(playerid, pConnect, f)
{
if(f == 0)
return gettime() - pConnect; //seconds
else if(f == 1)
return (gettime() - pConnect) / 60; //minutes
else if(f == 2)
return (gettime() - pConnect) / 3600; //hours
else
return (gettime() - pConnect) / 86400; //days
}
//i dont know how you call payday, i'm going to assume that there is a function called payday but you can change it how you wish..
stock payday(playerid)
{
if(getPlayerPlayingTime(playerid, Player[playerid][connect], 1) >= 20) //if player has been playing for more than or exactly 20 minutes
{
//payday code here
}
else
{
SendClientMessage(playerid, 0xFFFFFFCC, "Error : You havent been playing for at least 20 minutes!");
}
}
PS : If you didnt know, a unix timestamp returns a timestamp of how many seconds have passed by since the start of the 'Unix Epoch' (January 1st, 1970)