SQL Help
#1

I've got an SQL database and system up and running, just one problem.


When I have got this:

pawn Код:
enum _PSTATS
{
    pLayaName[24],
    pPassword[35],
    pKills,
    pDeaths,
    pMoney,
    pAdminLevel,
    pSkin,
    Float:pLastX,
    Float:pLastY,
    Float:pLastZ,
    pInt,
    pDonatorLevel,
    pLevel // Add more info
}
new Player[MAX_PLAYERS][_PSTATS];
I've added a few things to it: Here is what else I have:

pawn Код:
stock SavePInfo(playerid)
{
    if(GetPVarInt(playerid, "LoggedIN") == 1)
    {
        new Float:x, Float:y, Float: z;
        GetPlayerPos(playerid, x, y, z);
        new
            Query[600];

        format(Query, sizeof(Query), "UPDATE `playerinfo` SET `kills` = %d, `deaths` = %d, `money` = %d, `AdminLevel` = %d, `Skin` = %d, `Last Pos X` = %f, `Last Pos Y` = %f, `Last Pos Z` = %f, `Interior` = %d, `DonatorLevel` = %d, `Level` = %d WHERE `user` = '%s'",

        Player[playerid][pKills],
        Player[playerid][pDeaths],
        GetPlayerMoney(playerid),
        Player[playerid][pAdminLevel],
        GetPlayerSkin(playerid),
        x,
        y,
        z,
        GetPlayerInterior(playerid),
        Player[playerid][pDonatorLevel],
        GetPlayerScore(playerid),
        pName(playerid));

        mysql_query(Query);
        mysql_free_result();
        return 1;
    }
    else return 0;
}
And this:

pawn Код:
stock LoadPlayerInfo(iPlayer)
{
    new
        Query[700];

    if(mysql_fetch_row(Query))
    {
        mysql_query("SELECT * FROM `playerinfo`");
        sscanf(Query, "e<p<|>s[24]s[35]dddddfffddd>", Player[iPlayer]); // Remember to update this if you add more info...
        mysql_free_result();
        GivePlayerMoney(iPlayer, Player[iPlayer][pMoney]);
        SetPlayerScore(iPlayer, Player[iPlayer][pLevel]);
        SetSpawnInfo(iPlayer, 0, Player[iPlayer][pSkin], Player[iPlayer][pLastX], Player[iPlayer][pLastY], Player[iPlayer][pLastZ], 90, 0, 0, 0, 0, 0, 0);
    }
    return 1;
}
In my SQL database, I have got all the required table things, with "DonatorLevel" "Skin" "Level" and things, but I just can't seem to get it to save/load them parts?

Is there anything I am missing?

Thanks.

All help is appreciated and Reputation will be rewarded.
Reply
#2

Anybody? Is there anything missing from any of that code?
Reply
#3

You forgot the WHERE clause in your SELECT query, also you are trying to retrieve the row BEFORE the query and you are not storing the result

pawn Код:
stock LoadPlayerInfo(iPlayer)
{
    new
        Query[700];

    format(Query, sizeof(Query), "SELECT * FROM `playerinfo` WHERE `user` = '%s';", pName(iPlayer));
    mysql_query(Query);

    mysql_store_result();

    if(mysql_fetch_row(Query))
    {
        sscanf(Query, "e<p<|>s[24]s[35]dddddfffddd>", Player[iPlayer]); // Remember to update this if you add more info...
        GivePlayerMoney(iPlayer, Player[iPlayer][pMoney]);
        SetPlayerScore(iPlayer, Player[iPlayer][pLevel]);
        SetSpawnInfo(iPlayer, 0, Player[iPlayer][pSkin], Player[iPlayer][pLastX], Player[iPlayer][pLastY], Player[iPlayer][pLastZ], 90, 0, 0, 0, 0, 0, 0);
    }

    mysql_free_result();
    return 1;
}
And here there is no need of using mysql_free_result since you don't store anything

pawn Код:
stock SavePInfo(playerid)
{
    if(GetPVarInt(playerid, "LoggedIN") == 1)
    {
        new Float:x, Float:y, Float: z;
        GetPlayerPos(playerid, x, y, z);
        new
            Query[600];

        format(Query, sizeof(Query), "UPDATE `playerinfo` SET `kills` = %d, `deaths` = %d, `money` = %d, `AdminLevel` = %d, `Skin` = %d, `Last Pos X` = %f, `Last Pos Y` = %f, `Last Pos Z` = %f, `Interior` = %d, `DonatorLevel` = %d, `Level` = %d WHERE `user` = '%s'",

        Player[playerid][pKills],
        Player[playerid][pDeaths],
        GetPlayerMoney(playerid),
        Player[playerid][pAdminLevel],
        GetPlayerSkin(playerid),
        x,
        y,
        z,
        GetPlayerInterior(playerid),
        Player[playerid][pDonatorLevel],
        GetPlayerScore(playerid),
        pName(playerid));

        mysql_query(Query);
       
        return 1;
    }
    else return 0;
}
Reply
#4

I've also got this:

pawn Код:
stock AddHouseToFile(HouseName, HouseOwner, HousePrice, Float:ExteriorX, Float:ExteriorY, Float:ExteriorZ, Float:InteriorX, Float:InteriorY, Float:InteriorZ)
{
    new
        Query[1024];

    format(Query, sizeof(Query), "INSERT INTO `houses` (HouseName, HouseOwner, HousePrice, ExteriorX, ExteriorY, ExteriorZ, InteriorX, InteriorY, InteriorZ) VALUES(%s[24], %s[24, %d, %f, %f, %f, %f, %f, %f)",
    HouseName, HouseOwner, HousePrice, ExteriorX, ExteriorY, ExteriorZ, InteriorX, InteriorY, InteriorZ);

    mysql_query(Query);
    mysql_free_result();
    return 1;
}
&

pawn Код:
stock AddHousesFromFiles()
{
    new
        Str[67],
        HouseName[24],
        HouseOwner[24],
        HousePrice,
        Float:ExteriorX,
        Float:ExteriorY,
        Float:ExteriorZ,
        Float:InteriorX,
        Float:InteriorY,
        Float:InteriorZ,
        hTotal;
       
    mysql_query("SELECT * FROM `houses`");
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        while(mysql_fetch_row(Str))
        {
            sscanf(Str, "s[24]s[24]dffffff", HouseName, HouseOwner, HousePrice, ExteriorX, ExteriorY, ExteriorZ, InteriorX, InteriorY, InteriorZ);
            CreatePickup(1273, 1, ExteriorX, ExteriorY, ExteriorZ, 0);
            Create3DTextLabel(HouseName, COLOR_GREY, ExteriorX, ExteriorY, ExteriorZ, 5.0, 0);
            hTotal++;
        }
    }
    mysql_free_result();
    printf("** %i\t<->\tHouses Loaded From\t<->\tMySQL\t\t   **", hTotal);
    return 1;
}
With this command:

pawn Код:
command(createhouse, playerid, params[])
{
    new Usage[128];
    if(sscanf(params, "s", Usage))
    {
        if(Player[playerid][pAdminLevel] >= 10)
        {
            SendClientMessage(playerid, GREY, "Server:  /createhouse [usage]");
            SendClientMessage(playerid, GREY, "Usage: Interior, Exterior or Complete.");
        }
    }
    else
    {
        if(Player[playerid][pAdminLevel] >= 10)
        {
            if(strcmp(Usage, "exterior", true) == 0)
            {
                new Float:X, Float:Y, Float:Z, NewHouseID;
                GetPlayerPos(playerid, X, Y, Z);
                SendFMessage(playerid, COLOR_GREY, "You have created a house at %f, %f, %f", X, Y, Z);
                Houses[NewHouseID][pHouseExteriorX] = X;
                Houses[NewHouseID][pHouseExteriorY] = Y;
                Houses[NewHouseID][pHouseExteriorZ] = Z;
            }
            if(strcmp(Usage, "interior", true) == 0)
            {
                new Float:X, Float:Y, Float:Z, NewHouseID;
                GetPlayerPos(playerid, X, Y, Z);
                SendFMessage(playerid, COLOR_GREY, "You have created a house interior at %f, %f, %f", X, Y, Z);
                Houses[NewHouseID][pHouseInteriorX] = X;
                Houses[NewHouseID][pHouseInteriorY] = Y;
                Houses[NewHouseID][pHouseInteriorZ] = Z;
            }
            if(strcmp(Usage, "complete", true) == 0)
            {
                new NewHouseID, HouseName, HouseOwner, HousePrice, Float:ExteriorX, Float:ExteriorY, Float:ExteriorZ, Float:InteriorX, Float:InteriorY, Float:InteriorZ;
                InteriorX = Houses[NewHouseID][pHouseInteriorX];
                InteriorY = Houses[NewHouseID][pHouseInteriorY];
                InteriorZ = Houses[NewHouseID][pHouseInteriorZ];
                ExteriorX = Houses[NewHouseID][pHouseExteriorX];
                ExteriorY = Houses[NewHouseID][pHouseExteriorY];
                ExteriorZ = Houses[NewHouseID][pHouseExteriorZ];
                SetPlayerPos(playerid, Houses[NewHouseID][pHouseExteriorX], Houses[NewHouseID][pHouseExteriorY], Houses[NewHouseID][pHouseExteriorZ]);
                HousePrice = 50000;
                Houses[NewHouseID][pHouseName] = HouseName;
                SendClientMessage(playerid, GREY, "House has been added.");
                AddHouseToFile(HouseName, HouseOwner, HousePrice, Float:ExteriorX, Float:ExteriorY, Float:ExteriorZ, Float:InteriorX, Float:InteriorY, Float:InteriorZ);
                CreatePickup(1273, 1, ExteriorX, ExteriorY, ExteriorZ, 0);
                Create3DTextLabel(Houses[NewHouseID][pHouseName], COLOR_GREY, Houses[NewHouseID][pHouseExteriorX], Houses[NewHouseID][pHouseExteriorY], Houses[NewHouseID][pHouseExteriorZ], 5.0, 0, 1);
            }
        }
    }
    return 1;
}
The houses don't save?

What's wrong with that?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)