MySQL don't save player data...
#1

pawn Code:
public SavePlayerData(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        if(gPlayerLogged[playerid])
        {
            new query[MAX_STRING];
            format(query, MAX_STRING, "UPDATE players SET ");
            MySQLUpdatePlayerStr(query, PlayerInfo[playerid][pSQLID], "password", PlayerInfo[playerid][pKey]);
            PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Level", PlayerInfo[playerid][pLevel]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "AdminLevel", PlayerInfo[playerid][pAdmin]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "DonateRank", PlayerInfo[playerid][pDonateRank]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "PointsUpgrade", PlayerInfo[playerid][gPupgrade]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "ConnectedTime", PlayerInfo[playerid][pConnectTime]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Reg", PlayerInfo[playerid][pReg]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Sex", PlayerInfo[playerid][pSex]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Age", PlayerInfo[playerid][pAge]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Origin", PlayerInfo[playerid][pOrigin]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "CK", PlayerInfo[playerid][pCK]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Muted", PlayerInfo[playerid][pMuted]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Exp", PlayerInfo[playerid][pExp]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Cash", PlayerInfo[playerid][pCash]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "AccountBank", PlayerInfo[playerid][pAccount]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "CrimesComited", PlayerInfo[playerid][pCrimes]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Kills", PlayerInfo[playerid][pKills]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Deaths", PlayerInfo[playerid][pDeaths]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Arrested", PlayerInfo[playerid][pArrested]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "WantedDeaths", PlayerInfo[playerid][pWantedDeaths]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Phonebook", PlayerInfo[playerid][pPhoneBook]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "LottoNr", PlayerInfo[playerid][pLottoNr]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Fishes", PlayerInfo[playerid][pFishes]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "BiggestFish", PlayerInfo[playerid][pBiggestFish]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Job", PlayerInfo[playerid][pJob]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "PayCheck", PlayerInfo[playerid][pPayCheck]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "HeadValue", PlayerInfo[playerid][pHeadValue]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Jailed", PlayerInfo[playerid][pJailed]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "JailTime", PlayerInfo[playerid][pJailTime]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Mats", PlayerInfo[playerid][pMats]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Drugs", PlayerInfo[playerid][pDrugs]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Leader", PlayerInfo[playerid][pLeader]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Member", PlayerInfo[playerid][pMember]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "FMember", PlayerInfo[playerid][pFMember]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Rank", PlayerInfo[playerid][pRank]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Chara", PlayerInfo[playerid][pChar]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "ContractTime", PlayerInfo[playerid][pContractTime]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "DetSkill", PlayerInfo[playerid][pDetSkill]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "SexSkill", PlayerInfo[playerid][pSexSkill]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "BoxSkill", PlayerInfo[playerid][pBoxSkill]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "LawSkill", PlayerInfo[playerid][pLawSkill]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "MechSkill", PlayerInfo[playerid][pMechSkill]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "JackSkill", PlayerInfo[playerid][pJackSkill]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "CarSkill", PlayerInfo[playerid][pCarSkill]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "NewsSkill", PlayerInfo[playerid][pNewsSkill]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "DrugsSkill", PlayerInfo[playerid][pDrugsSkill]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "CookSkill", PlayerInfo[playerid][pCookSkill]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "FishSkill", PlayerInfo[playerid][pFishSkill]);
            MySQLUpdatePlayerFlo(query, PlayerInfo[playerid][pSQLID], "pHealth", PlayerInfo[playerid][pHealth]);
            MySQLUpdatePlayerFlo(query, PlayerInfo[playerid][pSQLID], "pSHealth", PlayerInfo[playerid][pSHealth]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Int", PlayerInfo[playerid][pInt]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Local", PlayerInfo[playerid][pLocal]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Team", PlayerInfo[playerid][pTeam]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Model", PlayerInfo[playerid][pModel]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Pnumber", PlayerInfo[playerid][pPnumber]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Phousekey", PlayerInfo[playerid][pPhousekey]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Pbiskey", PlayerInfo[playerid][pPbiskey]);
            if ((PlayerInfo[playerid][pPos_x]==0.0 && PlayerInfo[playerid][pPos_y]==0.0 && PlayerInfo[playerid][pPos_z]==0.0)) {
                PlayerInfo[playerid][pPos_x] = 1684.9;
                PlayerInfo[playerid][pPos_y] = -2244.5;
                PlayerInfo[playerid][pPos_z] = 13.5;
            }
            MySQLUpdatePlayerFlo(query, PlayerInfo[playerid][pSQLID], "Pos_x", PlayerInfo[playerid][pPos_x]);
            MySQLUpdatePlayerFlo(query, PlayerInfo[playerid][pSQLID], "Pos_y", PlayerInfo[playerid][pPos_y]);
            MySQLUpdatePlayerFlo(query, PlayerInfo[playerid][pSQLID], "Pos_z", PlayerInfo[playerid][pPos_z]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "CarLic", PlayerInfo[playerid][pCarLic]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "FlyLic", PlayerInfo[playerid][pFlyLic]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "BoatLic", PlayerInfo[playerid][pBoatLic]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "FishLic", PlayerInfo[playerid][pFishLic]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "GunLic", PlayerInfo[playerid][pGunLic]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Gun1", PlayerInfo[playerid][pGun1]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Gun2", PlayerInfo[playerid][pGun2]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Gun3", PlayerInfo[playerid][pGun3]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Gun4", PlayerInfo[playerid][pGun4]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Ammo1", PlayerInfo[playerid][pAmmo1]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Ammo2", PlayerInfo[playerid][pAmmo2]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Ammo3", PlayerInfo[playerid][pAmmo3]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Ammo4", PlayerInfo[playerid][pAmmo4]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "CarTime", PlayerInfo[playerid][pCarTime]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "PayDay", PlayerInfo[playerid][pPayDay]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "PayDayHad", PlayerInfo[playerid][pPayDayHad]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "CDPlayer", PlayerInfo[playerid][pCDPlayer]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Wins", PlayerInfo[playerid][pWins]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Loses", PlayerInfo[playerid][pLoses]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "AlcoholPerk", PlayerInfo[playerid][pAlcoholPerk]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "DrugPerk", PlayerInfo[playerid][pDrugPerk]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "MiserPerk", PlayerInfo[playerid][pMiserPerk]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "PainPerk", PlayerInfo[playerid][pPainPerk]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "TraderPerk", PlayerInfo[playerid][pTraderPerk]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Tut", PlayerInfo[playerid][pTut]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "MissionNr", PlayerInfo[playerid][pMissionNr]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Warns", PlayerInfo[playerid][pWarns]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Adjustable", PlayerInfo[playerid][pAdjustable]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Fuel", PlayerInfo[playerid][pFuel]);
            MySQLUpdatePlayerInt(query, PlayerInfo[playerid][pSQLID], "Married", PlayerInfo[playerid][pMarried]);
            MySQLUpdatePlayerStr(query, PlayerInfo[playerid][pSQLID], "MarriedTo", PlayerInfo[playerid][pMarriedTo]);
            MySQLUpdateFinish(query, PlayerInfo[playerid][pSQLID]);
        }
    }
    return 1;
}
[
functions :

pawn Code:
public MySQLUpdateFinish(query[], sqlplayerid)
{
    if (strcmp(query, "WHERE id=", false) == 0) mysql_query(query);
    else
    {
        new whereclause[32];
        format(whereclause, sizeof(whereclause), " WHERE id=%d", sqlplayerid);
        strcat(query, whereclause, MAX_STRING);
        mysql_query(query);
        format(query, MAX_STRING, "UPDATE players SET ");
    }
    return 1;
}

public MySQLUpdatePlayerInt(query[], sqlplayerid, sqlvalname[], sqlupdateint)
{
    MySQLUpdateBuild(query, sqlplayerid);
    new updval[64];
    format(updval, sizeof(updval), "%s=%d", sqlvalname, sqlupdateint);
    strcat(query, updval, MAX_STRING);
    return 1;
}

public MySQLUpdatePlayerFlo(query[], sqlplayerid, sqlvalname[], Float:sqlupdateflo)
{
/*  new query[128];
    format(query, sizeof(query), "UPDATE players SET %s=%f WHERE id=%d", sqlvalname, sqlupdateflo, sqlplayerid);
    samp_mysql_query(query);*/

    new flotostr[32];
    format(flotostr, sizeof(flotostr), "%f", sqlupdateflo);
    MySQLUpdatePlayerStr(query, sqlplayerid, sqlvalname, flotostr);
    return 1;
}

public MySQLUpdatePlayerStr(query[], sqlplayerid, sqlvalname[], sqlupdatestr[])
{
    MySQLUpdateBuild(query, sqlplayerid);
    new escstr[128];
    new updval[128];
    mysql_real_escape_string(sqlupdatestr, escstr);
    format(updval, sizeof(updval), "%s='%s'", sqlvalname, escstr);
    strcat(query, updval, MAX_STRING);
    return 1;
}

public MySQLUpdatePlayerIntSingle(sqlplayerid, sqlvalname[], sqlupdateint)
{
    new query[128];
    format(query, sizeof(query), "UPDATE players SET %s=%d WHERE id=%d", sqlvalname, sqlupdateint, sqlplayerid);
    mysql_query(query);
    return 1;
}

public MySQLUpdateBuild(query[], sqlplayerid)
{
    new querylen = strlen(query);
    //new querymax = sizeof(query);
    new querymax = MAX_STRING;
    if (querylen < 1) format(query, querymax, "UPDATE players SET ");
    else if (querymax-querylen < 50) // make sure we're being safe here
    {
        // query is too large, send this one and reset
        new whereclause[32];
        format(whereclause, sizeof(whereclause), " WHERE id=%d", sqlplayerid);
        strcat(query, whereclause, querymax);
        mysql_query(query);
        format(query, querymax, "UPDATE players SET ");
    }
    else if (strfind(query, "=", true) != -1) strcat(query, ",", MAX_STRING);
    return 1;
}
Reply
#2

Check mysql logs, if it gives any erorrs.
Reply
#3

don't errors
Reply
#4

Print out the query before executing it. You're missing a few blank spaces
Reply
#5

huh, my database > AdminLevel default 0, can it?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)