SA-MP Forums Archive
Possible to save timer? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Possible to save timer? (/showthread.php?tid=102249)



Possible to save timer? - cepiokas - 14.10.2009

Hey. Look, can i make to save timer time? Say that i set timer to 100 hour, and after that something happen. But i didn't believe, that player play 100 hour's without DC, sleep and other stuf.. So, can i make that Dini saving timer time? And after login timer continue.


Re: Possible to save timer? - MenaceX^ - 14.10.2009

Yea, possible.


Re: Possible to save timer? - shady91 - 14.10.2009

can make so every hour it ++ if you know what i mean, then when player login's in it reads how much time he has say 46 it add's on from there and when it hit's 100 make it do what you do if you dont get it i can write it down for you later to night when im on my PC as im on my phone.


Re: Possible to save timer? - cepiokas - 14.10.2009

Quote:
Originally Posted by Shady91
can make so every hour it ++ if you know what i mean, then when player login's in it reads how much time he has say 46 it add's on from there and when it hit's 100 make it do what you do if you dont get it i can write it down for you later to night when im on my PC as im on my phone.
I think i got your idea.. But i'm not good on English speak. So better be for me, that you write script or explain with codes..


Re: Possible to save timer? - cepiokas - 14.10.2009

Can someone show me example of that?


Re: Possible to save timer? - [nl]daplayer - 14.10.2009

pawn Код:
new pOnlineTime[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
  pOnlineTime[playerid] = GetTickCount();
  return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  new time = pOnlineTime[playerid] - GetTickCount();
  // time = the time the player was online in milliseconds.
  // Do saving stuff here.
  return 1;
}
Not compiled or anything, so there could be some typos


Re: Possible to save timer? - cepiokas - 14.10.2009

Ok. Say that i make it. But now how set, that when i reached 100 hours, i can to use some command?


Re: Possible to save timer? - [nl]daplayer - 14.10.2009

pawn Код:
new pOnlineTime[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
  pOnlineTime[playerid] = GetTickCount();
  // Maybe do some loading when the play logs in.
  return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  new time = pOnlineTime[playerid] - GetTickCount();
  // time = the time the player was online in milliseconds.
  // Do saving stuff here.
  return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
  if (!strcmp(cmdtext, "/command") && GetPlayingHours(playerid) >= 100)
  {
    SendClientMessage(playerid, 0x000000FF, "You have reached 100 hours!!");
    return 1;
  }
  return 1;
}

stock GetPlayingHours(playerid)
{
   return (pOnlineTime[playerid] - GetTickCount()) / 60 / 60);
}
Not compiled and tested or anything so there could be some typos

Use GetPlayingHours to get the total playing hours the person is playing.