SA-MP Forums Archive
Retrieving total playtime since registration! [MySQL] - 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: Retrieving total playtime since registration! [MySQL] (/showthread.php?tid=421481)



Retrieving total playtime since registration! [MySQL] - FunnyBear - 09.03.2013

Hey Guys,

I was wondering how you can record the total playtime of a player since registration. Like in hours, minutes and seconds. I would also like to add it to my MySQL database, but I'm not sure how to get the playtime since the player registered (made an account) on the server! Please help,

Thanks


Re: Retrieving total playtime since registration! [MySQL] - Squirrel - 09.03.2013

Do you have any code related to this or?

Код:
SetTimerEx("TimeOnServer", 1000, 1, "i", playerid);

forward TimeOnServer(playerid);
public TimeOnServer(playerid)
{
PlayerInfo[playerid][Sec] ++;
if(PlayerInfo[playerid][Sec]>=60)
    {
        PlayerInfo[playerid][Min]++;
        PlayerInfo[playerid][Sec]=0;
    }
if(PlayerInfo[playerid][Min]>=60)
    {
        PlayerInfo[playerid][Min]=0;
        PlayerInfo[playerid][Hour]++;
    }
}
//and that's all you need to have a timer with [hours,mins,sec]

//This is to save it
INI_WriteInt(Acc,"Min",PlayerInfo[playerid][Min]);
INI_WriteInt(Acc,"Hour",PlayerInfo[playerid][Hour]);
INI_WriteInt(Acc,"Sec",PlayerInfo[playerid][Sec]);

//To load it
PlayerInfo[playerid][Min] = GetPVarInt(playerid, "Min");
PlayerInfo[playerid][Hour] = GetPVarInt(playerid, "Hour");
PlayerInfo[playerid][Sec] = GetPVarInt(playerid, "Sec");
Just exchange that INI into the SQL or w/e. I never worked with SQL


Just add the save variables under the OnPlayerSpawn, that's why if you have for example "Force registration" system.
Basically if you have dialogs etc. and player must register, he wont be able to spawn unless he is registered


Re: Retrieving total playtime since registration! [MySQL] - FunnyBear - 09.03.2013

I get:

Код:
C:\DOCUME~1\DANNY~1.YOU\MYDOCU~1\LOSSAN~1\GAMEMO~1\MySQL.pwn(357) : error 017: undefined symbol "PlayerInfo"
C:\DOCUME~1\DANNY~1.YOU\MYDOCU~1\LOSSAN~1\GAMEMO~1\MySQL.pwn(357) : warning 215: expression has no effect
C:\DOCUME~1\DANNY~1.YOU\MYDOCU~1\LOSSAN~1\GAMEMO~1\MySQL.pwn(357) : error 001: expected token: ";", but found "]"
C:\DOCUME~1\DANNY~1.YOU\MYDOCU~1\LOSSAN~1\GAMEMO~1\MySQL.pwn(357) : error 029: invalid expression, assumed zero
C:\DOCUME~1\DANNY~1.YOU\MYDOCU~1\LOSSAN~1\GAMEMO~1\MySQL.pwn(357) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
here

pawn Код:
public TimeOnServer(playerid)
{
    pInfo[playerid][Seconds] ++;
    if(pInfo[playerid][Seconds] >=60)
    {
        pInfo[playerid][Minutes]++;
        pInfo[playerid][Seconds] =0;
    }
    if(PlayerInfo[playerid][Minutes] >=60)
    {
        pInfo[playerid][Minutes] =0;
        pInfo[playerid][Hours]++;
    }
}
plz help


Re: Retrieving total playtime since registration! [MySQL] - MP2 - 09.03.2013

I would use minutes not seconds. You don't really want to be saving many things once a second, every second. Do it once a minute.


Re: Retrieving total playtime since registration! [MySQL] - Squirrel - 09.03.2013

Regarding the pInfo
Код:
enum pInfo
{
    pWarns
}
new PlayerInfo[MAX_PLAYERS][pInfo];
//Add on the top of the script



Re: Retrieving total playtime since registration! [MySQL] - Patrick - 09.03.2013

Quote:
Originally Posted by Squirrel
Посмотреть сообщение
Regarding the pInfo
Код:
enum pInfo
{
    pWarns
}
new PlayerInfo[MAX_PLAYERS][pInfo];
//Add on the top of the script
Copy pasting much :P

it should be like this

pawn Код:
enum pInfo
{
    Sec
    Min
    Hour
}
new PlayerInfo[MAX_PLAYERS][pInfo];



Re: Retrieving total playtime since registration! [MySQL] - FunnyBear - 09.03.2013

Quote:
Originally Posted by pds2012
Посмотреть сообщение
Copy pasting much :P

it should be like this

pawn Код:
enum pInfo
{
Sec
Min
Hour
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Ok, alright. But what is the value. VARCHAR, INT, DATE? And the size (To add to MySQL)


Re: Retrieving total playtime since registration! [MySQL] - Squirrel - 09.03.2013

lmao I mixed the threads, I am trying to help other dude with pWarns. Yeah add the code he pasted.


Re: Retrieving total playtime since registration! [MySQL] - Patrick - 09.03.2013

Min= INT(11)
Sec = INT(11)
Hour = INT(11)


Re: Retrieving total playtime since registration! [MySQL] - Vince - 09.03.2013

You don't even need all those variables and timers. The only thing you need is one (1) field in your table. Save the registration timestamp in there by means of the UNIX_TIMESTAMP() functionality. This is a value that measures the seconds elapsed since the epoch on 1/1/1970.

Whenever you want to retrieve the time played, subtract the saved timestamp from the current timestamp. This will give you a value in seconds. Use an algorithm to convert it to minutes and hours.