How can I check how many hours was player online??
#1

Hello, I need your help!
I have payday command, and it works good...
But how can I make it like if player didn't play for at least 20 minutes he wont get paday in return send him message "You didn't play enough time to receive payday" or something like that...

How can I check if player played for at least 20mins, to receive payday
Reply
#2

Check the time when player connects (OnPlayerConnect) and save it. Then just check if the player has been online for 20 minutes.

This is very simple thing to do.
Reply
#3

Uhmm can you explain me how to check and save the time when player connects?
Reply
#4

Код:
static n_PlayerOnline[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
  n_PlayerOnline[playerid] = GetTickCount();
}

stock GetOnlineSeconds(playerid)
{
  return GetTickCount() - n_PlayerOnline[playerid] * 1000;
}
That will check seconds. I've made a function in the Useful Functions topic for converting seconds to hours / minutes.
Reply
#5

And then I just add if(GetOnlineSeconds(playerid) = Number to return client message??
Reply
#6

I just found this on SA:MP wiki about GetTickCount() function...

Код:
Important Note: GetTickCount will cause problems on servers with uptime of over 24 days (physical server, not SA:MP server) as GetTickCount will eventually warp past the integer size constraints
What that means, I don't want any problems on server??
Reply
#7

Quote:
Originally Posted by watzab
Quote:
Originally Posted by Finn
Check the time when player connects (OnPlayerConnect) and save it. Then just check if the player has been online for 20 minutes.

This is very simple thing to do.
Thats right

--------------------------------------------------------------------------------
gtamaps.freeforums.org
Pro mapper
+
Can script houses,casinos,restaurants,clubs, Everything!!
Why don't you explain me then, if it's that easy!?!
Reply
#8

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)
Reply
#9

Thank you for the reply iLinx, I'm gonna try your code, hope it works..
Reply
#10

Quote:
Originally Posted by HeGe
Thank you for the reply iLinx, I'm gonna try your code, hope it works..
np, let me know if it works ^^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)