SA-MP Forums Archive
SQLite Problem. - 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: SQLite Problem. (/showthread.php?tid=396226)



SQLite Problem. - Hardwell - 29.11.2012

Hello,i created a script for save hours/minutes/seconds on sqlite.but i have a problem..when i join the server..is saved thousands of hours..and tens of minutes.
IMAGE: http://postimage.org/image/ynjak5vcr/
SCRIPT: http://pastebin.com/Nk77TJaa

How to solve this problem?

Thanks!


Re : SQLite Problem. - Hardwell - 30.11.2012

Up??


Re: SQLite Problem. - Ballu Miaa - 30.11.2012

Your doing a mistake within the calculation. Its better that you check the whole code properly and compile it again!

Always remember the logic on which your programming or coding.


Re : SQLite Problem. - Hardwell - 30.11.2012

i checked..and it's not a problem with the calculation..


Re : SQLite Problem. - Hardwell - 30.11.2012

SOLVED


Re: SQLite Problem. - Konstantinos - 30.11.2012

I know it's solved, but you can save only the total time and then convert it, even if you want it on disconnect; on command. I just made it and I don't want to tell to myself that it was waste of time; it might be helpfull for some people, so here it is.
pawn Код:
#define FILTERSCRIPT

#include <a_samp>

enum PlayerData
{
    Hours,
    Minutes,
    Seconds,
    TotalTime,
    ConnectTime
};

new
    P_DATA[MAX_PLAYERS][PlayerData],
    DB:DB
;

public OnFilterScriptInit()
{
    DB = db_open("DB.db");
    db_free_result( db_query( DB, "CREATE TABLE IF NOT EXISTS `Users` (`Name`, `Total_Time`)"));
    return 1;
}

public OnFilterScriptExit()
{
    db_close(DB);
    return 1;
}

public OnPlayerConnect(playerid)
{
    P_DATA[playerid][Hours] = 0;
    P_DATA[playerid][Minutes] = 0;
    P_DATA[playerid][Seconds] = 0;
    P_DATA[playerid][TotalTime] = 0;
    P_DATA[playerid][ConnectTime] = gettime();

    new
        Query[256],
        DBResult:Result
    ;
    format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Name` = '%s'",Name(playerid));
    Result = db_query(DB,Query);
    if(db_num_rows(Result))
    {
        new
            Field[ 30 ]
        ;
        db_get_field_assoc(Result,"Total_Time",Field,30);

        P_DATA[playerid][TotalTime] = strval(Field);
       
       
        GetOnlineTime( P_DATA[playerid][TotalTime], P_DATA[playerid][Hours], P_DATA[playerid][Minutes], P_DATA[playerid][Seconds] );
    }
    else
    {
        format(Query,sizeof(Query),"INSERT INTO `Users`(`Name`,`Total_Time`) VALUES ('%s','%d')",Name(playerid),P_DATA[playerid][TotalTime]);
        db_free_result(db_query(DB,Query));
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new
        Query2[256]
    ;
    new time = gettime() - P_DATA[playerid][ConnectTime];
    GetOnlineTime(time,P_DATA[playerid][Hours], P_DATA[playerid][Minutes], P_DATA[playerid][Seconds]);
    printf("Online for; Hours: %d - Minutes: %d - Seconds: %d", P_DATA[playerid][Hours], P_DATA[playerid][Minutes], P_DATA[playerid][Seconds]);
    P_DATA[playerid][TotalTime] = P_DATA[playerid][TotalTime] + time;
    printf("Total time = %d", P_DATA[playerid][TotalTime]);
    format(Query2,sizeof(Query2),"UPDATE `Users` SET Total_Time = '%d' WHERE `Name` = '%s'",P_DATA[playerid][TotalTime],Name(playerid));
    db_free_result(db_query(DB,Query2));
    return 1;
}

stock Name(i)
{
    new n[24];
    GetPlayerName(i,n,24);
    return n;
}

stock GetOnlineTime(var, &h, &m, &s)
{
    h = (var / (60 * 60)) % 24;
    m = (var / 60) % 60;
    s = var % 60;
}