SA-MP Forums Archive
mysql saving data 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: mysql saving data problem (/showthread.php?tid=410971)



mysql saving data problem - Maraudeur - 27.01.2013

Why doesnt it save playerpos, health, armour etc.?

pawn Code:
enum e_pInfo
{
    pSQLid,
    pPass[129],
    pSalt[30],
    Float:pHealth,
    Float:pArmour,
    Float:pPos[4],
    pInterior,
    pVirtualWorld,
    pSkin
}
pawn Code:
stock mySQL_init()
{
    mysql_debug(1);
    g_Handle = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
   
    /* Table Structure - kind of messy, I know. */
    mysql_function_query(g_Handle, "CREATE TABLE IF NOT EXISTS `users` ( \
        `id` int(11) NOT NULL AUTO_INCREMENT, \
        `name` varchar(24) NOT NULL, \
        `pass` varchar(129) NOT NULL, \
        `salt` varchar(30) NOT NULL, \
        `health` float NOT NULL, \
        `armour` float NOT NULL, \
        `X` float NOT NULL, \
        `Y` float NOT NULL, \
        `Z` float NOT NULL, \
        `A` float NOT NULL, \
        `interior` int(2) NOT NULL, \
        `vw` int(11) NOT NULL, \
        `skin` int(3) NOT NULL, \
        PRIMARY KEY (`id`) \
    )"
, false, "SendQuery", "");

    return 1;
}
Saving: (doesnt work)
pawn Code:
stock SaveAccount(playerid)
{
        new
                query[300],
                Float:pos[4],
                Float:health,
                Float:armour;
       
        GetPlayerPos(playerid, posArr{pos});
        GetPlayerFacingAngle(playerid, pos[3]);
        GetPlayerHealth(playerid, health);
        GetPlayerArmour(playerid, armour);
       
        format(query, sizeof(query), "UPDATE `users` SET health = %.1f, SET armour = %.1f, X = %.2f, Y = %.2f, Z = %.2f, A = %.2f, interior = %d, vw = %d, skin = %d WHERE `id` = %d",
                health,
                armour,
                posArrEx{pos},
                GetPlayerInterior(playerid),
                GetPlayerVirtualWorld(playerid),
                GetPlayerSkin(playerid),
                g_PlayerInfo[playerid][pSQLid]
        );
       
        mysql_function_query(g_Handle, query, false, "SendQuery", "");
        return 1;
}
Loading: (works)
pawn Code:
stock LoadAccount(playerid)
{
    new query[128];
   
    format(query, sizeof(query), "SELECT * FROM `users` WHERE `id` = %d", g_PlayerInfo[playerid][pSQLid]);
    mysql_function_query(g_Handle, query, true, "OnAccountLoad", "d", playerid);
}

forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    ToggleMainMenu(playerid, 0);
    SetCameraBehindPlayer(playerid);
   
    new temp[40];
    format(temp, sizeof(temp), "SERVER: Welcome %s", returnNameEx(playerid));
    SendClientMessage(playerid, -1, temp);

   
    cache_get_row(0, 4, temp), g_PlayerInfo[playerid][pHealth] = floatstr(temp),
    cache_get_row(0, 5, temp), g_PlayerInfo[playerid][pArmour] = floatstr(temp),
    cache_get_row(0, 6, temp), g_PlayerInfo[playerid][pPos][0] = floatstr(temp),
    cache_get_row(0, 7, temp), g_PlayerInfo[playerid][pPos][1] = strval(temp),
    cache_get_row(0, 8, temp), g_PlayerInfo[playerid][pPos][2] = strval(temp),
    cache_get_row(0, 9, temp), g_PlayerInfo[playerid][pPos][3] = strval(temp),
    cache_get_row(0, 10, temp), g_PlayerInfo[playerid][pInterior] = strval(temp),
    cache_get_row(0, 11, temp), g_PlayerInfo[playerid][pVirtualWorld] = strval(temp),
    cache_get_row(0, 12, temp), g_PlayerInfo[playerid][pSkin] = strval(temp);
   
    SetPlayerHealth(playerid, g_PlayerInfo[playerid][pHealth]);
    SetPlayerArmour(playerid, g_PlayerInfo[playerid][pArmour]);
    SetPlayerPos(playerid, posArr{g_PlayerInfo[playerid][pPos]});
    SetPlayerFacingAngle(playerid, g_PlayerInfo[playerid][pPos][3]);
    SetPlayerInterior(playerid, g_PlayerInfo[playerid][pInterior]);
    SetPlayerVirtualWorld(playerid, g_PlayerInfo[playerid][pVirtualWorld]);
    SetPlayerSkin(playerid, g_PlayerInfo[playerid][pSkin]);
    return 1;
}



Re: mysql saving data problem - FUNExtreme - 27.01.2013

UPDATE table SET variable1, variable2, variable3

You don't need to repeat the 'SET'


Re: mysql saving data problem - Maraudeur - 27.01.2013

Quote:
Originally Posted by FUNExtreme
View Post
UPDATE table SET variable1, variable2, variable3

You don't need to repeat the 'SET'
oh god, missed that, thanks ill check if it works now.


Re: mysql saving data problem - Maraudeur - 27.01.2013

Okay it works, but skin doesn't save, any idea why?