Problem with syntax "TIME" on MySQL.
#1

Hi, I want to make tops on my server, with best players by time spent on server. I have a field, named: "Online" where I save the times spent on server, for each player.

10-11 players, has online time +800.

Also, I had more that 850, and, after I changed the syntax in the database, for "Online" field, my hours was changed into: "838:59:59" ... I don't know the reason. When I enter on the server, the hours/mins/secs continue to counting, but when i exit, still the time will save into: "838:59:59".

Ideas? Thanks.
Reply
#2

I want to save each player time spent on server, and make a top.
Reply
#3

You mean make the top just for the users who are online, or offline too?

If you want it for everybody, online and offline, you must save how much they played in the server. With SQL is pretty easy, and in my opinion the best way to to this in PAWN in save the current time into a variable when they join (OnPlayerConnect with gettime) and when they disconnect (OnPlayerDisconnect with gettime) get the current time and rest the first variable.

Then add the result to the field. I think it's one of the best free lagg ways.

Now, to group them, use GROUP BY and LIMIT. If you have more doubts just ask.

Best regards!
Reply
#4

What is the unit of time that variable holds? Seconds? Minutes? Hours?
Reply
#5

Quote:
Originally Posted by irinel1996
Посмотреть сообщение
You mean make the top just for the users who are online, or offline too?

If you want it for everybody, online and offline, you must save how much they played in the server. With SQL is pretty easy, and in my opinion the best way to to this in PAWN in save the current time into a variable when they join (OnPlayerConnect with gettime) and when they disconnect (OnPlayerDisconnect with gettime) get the current time and rest the first variable.

Then add the result to the field. I think it's one of the best free lagg ways.

Now, to group them, use GROUP BY and LIMIT. If you have more doubts just ask.

Best regards!
I have that function, what are in LAdmin:
Код:
TotalGameTime( playerid, &h=0, &m=0, &s=0 )
{
    PlayerInfo[ playerid ][ TotalTime ] = ( ( gettime( ) - PlayerInfo[ playerid ][ ConnectTime ] ) + ( PlayerInfo[ playerid ][ hours ]*60*60 ) + ( PlayerInfo[ playerid ][ mins ]*60 ) + ( PlayerInfo[ playerid ][ secs ] ) );

    h = floatround( PlayerInfo[ playerid ][ TotalTime ] / 3600, floatround_floor );
    m = floatround( PlayerInfo[ playerid ][ TotalTime ] / 60,   floatround_floor ) % 60;
    s = floatround( PlayerInfo[ playerid ][ TotalTime ] % 60,   floatround_floor );

    return PlayerInfo[ playerid ][ TotalTime ];
}
And when I save the player time on the server, I use:
Код:
new
    li_H,
    li_H,
    li_H
;
TotalGameTime( playerid, li_H, li_M, li_S );

format( gsQuery, 256, "UPDATE `Accounts` SET `Online` = '%d:%d:%d' ...", li_H, li_M, li_S );
mysql_query( gsQuery );
Reply
#6

As you see TotalGameTime returns PlayerInfo[ playerid ][ TotalTime ], you should save that one and order players by its value.
pawn Код:
public OnPlayerDisconnect(playerid, reason) {
    new query[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(query,128,"UPDATE Accounts SET totaltime = %d WHERE nickname = '%s'",TotalGameTime(playerid),name);
    mysql_query(query);
    return 1;
}
As you see I used totaltime, a simple integer.
Then for the Top.
pawn Код:
mysql_query("SELECT nickname FROM accounts ORDER BY totaltime LIMIT 5");
LIMIT 5 is the max rows will be returned, I mean, 5 players.
Reply
#7

You can use SetTimer();

pawn Код:
forward MinuteTimer();
new pTime[MAX_PLAYERS]
pawn Код:
public OnGameModeInit()
{
    SetTimer("MinuteTimer", 1000 * 60, 1);
    return 1;
}
pawn Код:
public MinuteTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && pInfo[i][pLogged] == 1)
        {
            pTime[i]++;
        }
    }
    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new query[128];
    format(query, sizeof(query), "UPDATE users SET times = '%d'", pTime[playerid]);
    mysql_query(query);
    pTime[playerid] = 0;
    return 1;
}
Reply
#8

Quote:
Originally Posted by MouseBreaker
Посмотреть сообщение
You can use SetTimer();

pawn Код:
forward MinuteTimer();
new pTime[MAX_PLAYERS]
pawn Код:
public OnGameModeInit()
{
    SetTimer("MinuteTimer", 1000 * 60, 1);
    return 1;
}
pawn Код:
public MinuteTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && pInfo[i][pLogged] == 1)
        {
            pTime[i]++;
        }
    }
    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new query[128];
    format(query, sizeof(query), "UPDATE users SET times = '%d'", pTime[playerid]);
    mysql_query(query);
    pTime[playerid] = 0;
    return 1;
}
Yeah, 1 more timer for anything ... )

@irinel, thanks for your help I forgot about TotalTime Now i know how to do the top.
Reply
#9

It was just my suggestion, if you hae a secondTimer in your script you can use.

pawn Код:
new pSecTime[MAX_PLAYERS];

public SecondTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && pInfo[playerid][pLogged] == 1)
        {
            pSecTime[i]++;
            if(pSecTime[i] == 60)
            {
                pSecTime[i] = 0;
                pTime[i]++;
            }
        }
    }
}
Like i said it's just my suggestion
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)