SA-MP Forums Archive
Playing hours not working - 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: Playing hours not working (/showthread.php?tid=544569)



Playing hours not working - GwENiko - 02.11.2014

its not incrementing by minutes as intended

pawn Код:
public PlayingHours(playerid)
{

      playerVariables[playerid][pMinutes]++;
      if(playerVariables[playerid][pMinutes] == 60)
      {
      playerVariables[playerid][pPlayingHours]++;
      playerVariables[playerid][pMinutes] = 0;
      }
      return 1;

public OnPlayerConnect(playerid)
{
    SetTimerEx("PlayingHours", 60000, true, "i", playerid);
    return 1;
}



Re: Playing hours not working - TheSimpleGuy - 02.11.2014

Try to replace SetTimerEx("PlayingHours", 60000, true, "i", playerid); with SetTimerEx("PlayingHours", 10000, true, "i", playerid); and add a new variable, second?

pawn Код:
public PlayingHours(playerid)
{
playerVariables[playerid][pSeconds]++;
if(playerVariables[playerid][pSeconds] == 60)
{
      playerVariables[playerid][pMinutes]++;
      playerVariables[playerid][pSeconds] = 0;
}
      if(playerVariables[playerid][pMinutes] == 60)
      {
      playerVariables[playerid][pPlayingHours]++;
      playerVariables[playerid][pMinutes] = 0;
      }
      return 1;
}



Re: Playing hours not working - GwENiko - 02.11.2014

a timer that repeats every 1 second? i doubt thats an efficient way to do it


Re: Playing hours not working - TheSimpleGuy - 02.11.2014

I use it. I could give you my script of it.
And it's working.


Re: Playing hours not working - GwENiko - 02.11.2014

Well, i prefer a more if not the most efficient way to work with this snippet


Re: Playing hours not working - Quickie - 03.11.2014

most simple/efficient/reliable/less memory usage connected time check
NetStats_GetConnectedTime(playerid);

returns the players connected time for the session in milli seconds 1000ms/sec

EX:
(this is just an example and i havent tested it yet but you can use my stock BTW)
pawn Код:
enum PLAYER_ENUM{ // change this to your own enum
pMinutes,
pPlayingHours,
pMilliseconds, // add this one to your player enum
...
}



CMD:mytime(playerid,params[])
{
    new Float:hours,Float:minutes,Float:seconds,msg[128];
    MyTimeInHMS(playerid,hours,minutes,seconds);
    format(msg,sizeof(msg),"Your connected time Hour:%0.f Minutes:%0.f Seconds:%0.f",hours,minutes,seconds);
    return 1;
}

stock MyTimeInHMS(playerid,&Float:hours,&Float:minutes,&Float:seconds)
{
    new Float:milliseconds=NetStats_GetConnectedTime(playerid)+playerVariables[playerid][pMilliseconds];
    hours=milliseconds/3600000;
    milliseconds%=36000000;
    minutes=milliseconds/60000;
    milliseconds%=60000;
    seconds=milliseconds/1000;
}