MYSQL data saving problem.

not490

Well-Known Member
Joined
Feb 8, 2014
Messages
438
Likes
3
Points
163
#1
So, i have problem with saving players data correctly. I can't figure out the problem. Anyone got clue?

PHP:
stock Saveplayersdata(playerid, registered, logged, closemysql = 0)
{
    new query[1000], weaponid, ammo, ps = GetPlayerState(playerid);
    if(Info[playerid][Logged] == 1 && ps != PLAYER_STATE_WASTED && ps != PLAYER_STATE_SPECTATING)
    {
        new Float:px, Float:py, Float:pz, Float:xHP, Float:xArmour;
        GetPlayerPos(playerid, px, py, pz);
        GetPlayerHealth(playerid, xHP);
        GetPlayerArmour(playerid, xArmour);
        GetPlayerIp(playerid, Info[playerid][IP], 16);

        Info[playerid][PlayerTeam] = pTeam[playerid];
        Info[playerid][Money] = GetPlayerCash(playerid);
        Info[playerid][FightStyle] = GetPlayerFightingStyle(playerid);
        Info[playerid][Skin] = GetPlayerSkin(playerid);
        Info[playerid][Interior] = GetPlayerInterior(playerid);
        Info[playerid][pHealth] = xHP;
        Info[playerid][pArmour] = xArmour;

        if(Info[playerid][InDM] == 1 || InEvent[playerid] == 1 || InDerby[playerid] == 1 || InTDM[playerid] == 1 || InParkour[playerid] == 1 || InSkydive[playerid] == 1 || InDuel[playerid] == 1)
        {
            Info[playerid][PosX] = LastPosX[playerid];
            Info[playerid][PosY] = LastPosY[playerid];
            Info[playerid][PosZ] = LastPosZ[playerid];
            Info[playerid][pHealth] = LastHealth[playerid];
            Info[playerid][pArmour] = LastArmour[playerid];
            Info[playerid][Interior] = LastInterior[playerid];
        }

        if(Info[playerid][InDM] == 0 && InEvent[playerid] == 0 && InDerby[playerid] == 0 && InTDM[playerid] == 0 && InParkour[playerid] == 0 && InSkydive[playerid] == 0 && InDuel[playerid] == 0)
        {
            Info[playerid][PosX] = px;
            Info[playerid][PosY] = py;
            Info[playerid][PosZ] = pz;
        }

        if(Info[playerid][InDM] == 0 && InEvent[playerid] == 0 && InDerby[playerid] == 0 && InTDM[playerid] == 0 && InParkour[playerid] == 0 && InSkydive[playerid] == 0 && InDuel[playerid] == 0)
        {
            for(new i; i < 13; i++)
            {
                GetPlayerWeaponData(playerid, i, weaponid, ammo);

                if(!weaponid) continue;

                mysql_format(mysql, query, sizeof(query), "INSERT INTO `Weapons` (ID, Weapon, Ammo) VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE `Ammo` = %d", Info[playerid][ID], weaponid, ammo, ammo);
                mysql_tquery(mysql, query);
            }
        }

        mysql_format(mysql, query, sizeof(query), "UPDATE `playersdata` SET `LastSeen` = UNIX_TIMESTAMP(), `IP` = '%e', `AutoLogin` = %i, `Level` = %i, `Money` = %i, `Tokens` = %i, `Kills` = %i,\
        `Deaths` = %i, `Suicides` = %i, `Hours` = %i, `Minutes` = %i, `Seconds` = %i, `Marijuana` = %i, `Seeds` = %i, `Cocaine` = %i, `Premium` = %i, `PremiumExpires` = %i, `FightStyle` = %i,\
        `xLevel` = %i, `XP` = %i, `Muted` = %i, `Hitman` = %i, `gSkills` = %i, `bSkills` = %i, `vSkills` = %i, `aSkills` = %i, `rSkills` = %i, `tSkills` = %i, `mSkills` = %i, `dSkills` = %i,\
        `PlayerTeam` = %i, `MoneyBags` = %i, `Skin` = %i, `PosX` = %f, `PosY` = %f, `PosZ` = %f, `Interior` = %i, `Health` = %f, `Armour` = %f, `Jetpack` = %i, `JetpackExpire` = %i,\
        `Friends` = %i, `Vehicles` = %i, `InHouse` = %i, `PlayerColor` = '%e', `TextColor` = '%e', `MapHide` = %i  WHERE `ID` = %d",
        Info[playerid][IP], Info[playerid][AutoLogin], Info[playerid][Level], Info[playerid][Money], Info[playerid][Tokens], Info[playerid][Kills], Info[playerid][Deaths], Info[playerid][Suicides], Info[playerid][Hours],
        Info[playerid][Minutes], Info[playerid][Seconds], Info[playerid][Marijuana], Info[playerid][Seeds], Info[playerid][Cocaine], Info[playerid][Premium], Info[playerid][PremiumExpires], Info[playerid][FightStyle],
        Info[playerid][xLevel], Info[playerid][XP], MuteCounter[playerid], Info[playerid][Hitman], Info[playerid][Skills][GROVE], Info[playerid][Skills][BALLAS], Info[playerid][Skills][VAGOS], Info[playerid][Skills][AZTECAS],
        Info[playerid][Skills][BIKERS], Info[playerid][Skills][TRIADS], Info[playerid][Skills][MAFIA], Info[playerid][Skills][NANG], Info[playerid][PlayerTeam], Info[playerid][MoneyBags], Info[playerid][Skin], Info[playerid][PosX],
        Info[playerid][PosY], Info[playerid][PosZ], Info[playerid][Interior], Info[playerid][pHealth], Info[playerid][pArmour], Info[playerid][Jetpack], Info[playerid][JetpackExpire], Info[playerid][Friends], Info[playerid][vehLimit],
        InHouse[playerid], Info[playerid][playerColor], Info[playerid][textColor], Info[playerid][MapHide], Info[playerid][ID]);
        mysql_tquery(mysql, query);

        Info[playerid][Registered] = registered;
        Info[playerid][Logged] = logged;
    }
    if(closemysql == 1) mysql_close(mysql);
    return true;
 
Top