Health not saving in SQLite? - CrypticSin - 2022-04-14
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(playerid, bool:success) { if(success) { new query[256], field[24], field2[64]; format(query, sizeof(query), "SELECT * FROM `USERS` WHERE `NAME` = '%s' COLLATE NOCASE", DB_Escape(ReturnName(playerid))); database_result = db_query(server_database, query); if(db_num_rows(database_result)) { db_get_field_assoc(database_result, "ADMIN", field, sizeof(field)); PlayerInfo[playerid][pAdmin] = strval(field);
db_get_field_assoc(database_result, "SCORE", field, sizeof(field)); SetPlayerScore(playerid, strval(field));
db_get_field_assoc(database_result, "KILLS", field, sizeof(field)); PlayerInfo[playerid][pKills] = strval(field);
db_get_field_assoc(database_result, "DEATHS", field, sizeof(field)); PlayerInfo[playerid][pDeaths] = strval(field);
db_get_field_assoc(database_result, "SKIN", field, sizeof(field)); PlayerInfo[playerid][pSkin] = strval(field);
db_get_field_assoc(database_result, "REGISTER_DATE", field2, sizeof(field2)); PlayerInfo[playerid][pRegister] = field2;
db_get_field_assoc(database_result, "HEALTH", field, sizeof(field)); PlayerInfo[playerid][pHealth] = floatstr(field);
db_get_field_assoc(database_result, "pX", field, sizeof(field)); PlayerInfo[playerid][pX] = floatstr(field);
db_get_field_assoc(database_result, "pY", field, sizeof(field)); PlayerInfo[playerid][pY] = floatstr(field);
db_get_field_assoc(database_result, "pZ", field, sizeof(field)); PlayerInfo[playerid][pZ] = floatstr(field);
db_get_field_assoc(database_result, "pA", field, sizeof(field)); PlayerInfo[playerid][pA] = floatstr(field);
db_get_field_assoc(database_result, "INT", field, sizeof(field)); PlayerInfo[playerid][pInt] = strval(field);
db_get_field_assoc(database_result, "WORLD", field, sizeof(field)); PlayerInfo[playerid][pWorld] = strval(field); }
Inserting Health Data:
PHP Code: ? ?? new query[400]; format(query, sizeof(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)), password, PLAYER, ip, Date, GetPlayerScore(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_database, query); db_free_result(database_result);
Updating Data:
PHP Code: ? ? ? ? ? ?? stock SaveAccount(playerid) { new query[400], Float:pos[4]; if(PlayerInfo[playerid][pLoggedIn] == true) { GetPlayerPos(playerid, pos[0], pos[1], pos[2]); GetPlayerFacingAngle(playerid, pos[3]); GetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
format(query, sizeof(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_database, query); 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..
RE: Health not saving in SQLite? - Banditul - 2022-04-14
I'm suprised your create table query even runs because is so wrong
https://www.sqlitetutorial.net/sqlite-create-table/
RE: Health not saving in SQLite? - CrypticSin - 2022-04-14
(2022-04-14, 07:25 AM)Banditul Wrote: I'm suprised your create table query even runs because is so wrong
https://www.sqlitetutorial.net/sqlite-create-table/
Everything is working fine, my next step is to have the health system saved.?
I know it's not good practice but, ill fix all those later once i fix some of the features i want to add on the server.
RE: Health not saving in SQLite? - CrypticSin - 2022-04-18
I've updated the code slightly and it does run but the Health data still doesn't show on sqlite browser. Any ideas?
|