• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Health not saving in SQLite?
#1
Trying to save player health but doesn't seem to be working i'll like to know what im doing wrong?

Created a table in OnGameModeInit:
PHP Code:
db_query(server_database"CREATE TABLE IF NOT EXISTS `USERS` (`NAME`, `IP`, `REGISTER_DATE`, `PASS`, `SCORE`, `KILLS`, `DEATHS`, `SKIN`, `HEALTH`, `pX`, `pY`, `pZ`, `pA`, `INT`, `WORLD`, `ADMIN`)");; 

Selecting data:
PHP Code:
public OnPlayerLogin(playeridbool:success)
{
    if(
success)
    {
        new 
query[256], field[24], field2[64];
        
format(querysizeof(query), "SELECT * FROM `USERS` WHERE `NAME` = '%s' COLLATE NOCASE"DB_Escape(ReturnName(playerid)));
        
database_result db_query(server_databasequery);
        if(
db_num_rows(database_result))
        {
            
db_get_field_assoc(database_result"ADMIN"fieldsizeof(field));
            
PlayerInfo[playerid][pAdmin] = strval(field);

            
db_get_field_assoc(database_result"SCORE"fieldsizeof(field));
            
SetPlayerScore(playeridstrval(field));

            
db_get_field_assoc(database_result"KILLS"fieldsizeof(field));
            
PlayerInfo[playerid][pKills] = strval(field);

            
db_get_field_assoc(database_result"DEATHS"fieldsizeof(field));
            
PlayerInfo[playerid][pDeaths] = strval(field);

            
db_get_field_assoc(database_result"SKIN"fieldsizeof(field));
            
PlayerInfo[playerid][pSkin] = strval(field);

            
db_get_field_assoc(database_result"REGISTER_DATE"field2sizeof(field2));
            
PlayerInfo[playerid][pRegister] = field2;

            
db_get_field_assoc(database_result"HEALTH"fieldsizeof(field));
            
PlayerInfo[playerid][pHealth] = floatstr(field);

            
db_get_field_assoc(database_result"pX"fieldsizeof(field));
            
PlayerInfo[playerid][pX] = floatstr(field);

            
db_get_field_assoc(database_result"pY"fieldsizeof(field));
            
PlayerInfo[playerid][pY] = floatstr(field);

            
db_get_field_assoc(database_result"pZ"fieldsizeof(field));
            
PlayerInfo[playerid][pZ] = floatstr(field);

            
db_get_field_assoc(database_result"pA"fieldsizeof(field));
            
PlayerInfo[playerid][pA] = floatstr(field);

            
db_get_field_assoc(database_result"INT"fieldsizeof(field));
            
PlayerInfo[playerid][pInt] = strval(field);

            
db_get_field_assoc(database_result"WORLD"fieldsizeof(field));
            
PlayerInfo[playerid][pWorld] = strval(field);
        } 

Inserting Health Data:
PHP Code:
? ??
    new 
query[400];
    
format(querysizeof(query), "INSERT INTO `USERS` (`NAME`, `PASS`, `ADMIN`, `IP`, `REGISTER_DATE`, `SCORE`, `KILLS`, `DEATHS`, `SKIN`, `HEALTH`, `pX`, `pY`, `pZ`, `pA`, `INT`, `WORLD`) VALUES ('%s', '%s', %d, '%s', '%s', %d, %d, %d, %d, %f, %f, %f, %f, %f, %d, %d)"DB_Escape(ReturnName(playerid)), passwordPLAYERipDateGetPlayerScore(playerid), PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], GetPlayerSkin(playerid), PlayerInfo[playerid][pHealth],
    
PlayerInfo[playerid][pX],
    
PlayerInfo[playerid][pY],
    
PlayerInfo[playerid][pZ],
    
PlayerInfo[playerid][pA],
    
PlayerInfo[playerid][pInt],
    
PlayerInfo[playerid][pWorld]);
    
database_result db_query(server_databasequery);
    
db_free_result(database_result); 

Updating Data:

PHP Code:
? ? ? ? ? ??
stock SaveAccount(playerid)
{
    new 
query[400], Float:pos[4];
    if(
PlayerInfo[playerid][pLoggedIn] == true)
    {
        
GetPlayerPos(playeridpos[0], pos[1], pos[2]);
        
GetPlayerFacingAngle(playeridpos[3]);
        
GetPlayerHealth(playeridPlayerInfo[playerid][pHealth]);

        
format(querysizeof(query),
        
"UPDATE `USERS` SET `ADMIN` = %d, `SCORE` = %d, `KILLS` = %d, `DEATHS` = %d, `SKIN` = %d, `HEALTH` = %f, `pX` = %f, `pY` = %f, `pZ` = %f, `pA` = %f, `INT` = %d, `WORLD` = %d, `ADMIN` = %d WHERE `NAME` = '%s' COLLATE NOCASE",
        
PlayerInfo[playerid][pAdmin], GetPlayerScore(playerid), PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], GetPlayerSkin(playerid), PlayerInfo[playerid][pHealth], pos[0], pos[1], pos[2], pos[3], GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid), PlayerInfo[playerid][pAdmin], DB_Escape(ReturnName(playerid)));
        
database_result db_query(server_databasequery);
        
db_free_result(database_result);
    }
    return 
1;


Code runs without errors but im still unsure on why its not saving and loading the players health..
  Reply


Messages In This Thread
Health not saving in SQLite? - by CrypticSin - 2022-04-14, 12:14 AM
RE: Health not saving in SQLite? - by Banditul - 2022-04-14, 07:25 AM
RE: Health not saving in SQLite? - by CrypticSin - 2022-04-14, 08:52 AM
RE: Health not saving in SQLite? - by CrypticSin - 2022-04-18, 05:47 PM

Forum Jump: