How to save data on Mysql?
#1

Hello, I'm starting with Mysql r7 and so far I have kept things as data
Position, life, Armour, money and skin

I'm trying to add the following (level and weapons "with infinite ammo for all")

I tried to do it manually but too errrores
I would like to know where I can get information on this or someone who knows me explain

Here I leave the current saved data

pawn Код:
//==============
enum e_pInfo
{
    pSQLid,
    pPass[129],
    pSalt[30],
    Float:pHealth,
    Float:pArmour,
    Float:pPos[4],
    pInterior,
    pVirtualWorld,
    pSkin,
    pMoney
}

//=============================
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(11) NOT NULL, \
        `vw` int(11) NOT NULL, \
        `skin` int(11) NOT NULL, \
        `money` int(20) NOT NULL, \
        PRIMARY KEY (`id`) \
    )"
, false, "SendQuery", "");

    return 1;
}

//==================================
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);

    // Field indexes are relative to the query.
    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),
    cache_get_row(0, 13, temp), g_PlayerInfo[playerid][pMoney] = 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]);
    GivePlayerMoney(playerid, g_PlayerInfo[playerid][pMoney]);
    return 1;
}

//================================================
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, armour = %.1f, X = %.2f, Y = %.2f, Z = %.2f, A = %.2f, interior = %d, vw = %d, skin = %d, money = %d WHERE `id` = %d",
        health,
        armour,
        posArrEx{pos},
        GetPlayerInterior(playerid),
        GetPlayerVirtualWorld(playerid),
        GetPlayerSkin(playerid),
        GetPlayerMoney(playerid),
        g_PlayerInfo[playerid][pSQLid]
    );

    mysql_function_query(g_Handle, query, false, "SendQuery", "");
    return 1;
}
Greetings
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)