PDA

View Full Version : SQLite Problem.


Hardwell
29/11/2012, 09:57 PM
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!

Hardwell
30/11/2012, 10:13 AM
Up??

Ballu Miaa
30/11/2012, 10:32 AM
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.

Hardwell
30/11/2012, 10:49 AM
i checked..and it's not a problem with the calculation..

Hardwell
30/11/2012, 11:09 AM
SOLVED

Konstantinos
30/11/2012, 11:27 AM
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.

#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;
}