House system - using Mysql
#1

Well, as some of you might know if you've seen some of my threads I made that needed help with mysql, I am a "newb" at scripting with mysql. I made a house system (not all of it) and I wanted to make it so it shows the pickup and shit, but it doesn't even show it, and it doesn't save the houses. These are the scripts:

pawn Код:
//Top
#define MAX_HOUSES 100

enum hInfo
{
    Owner[24],
    Owned,
    Float:EnterPos[3],
    Float:ExitPos[3],
    Interior,
    World,
    Price,
    Pickup,
    Text3D:Label
}
new HouseInfo[MAX_HOUSES][hInfo];

//OnGameModeInit
mysql_query("CREATE TABLE IF NOT EXISTS housedata(houseid INT(3), owner VARCHAR(24), price INT(10), enterx FLOAT(20), entery FLOAT(20), enterz FLOAT(20), exitx FLOAT(20), exity FLOAT(20), exitz FLOAT(20), interior INT(2), virtualworld INT(2) )");
LoadHouses();

// Command

CMD:createhouse(playerid, params[])
{
    new houseid, houseprice, houseenterpos[3], houseexitpos[3], interior, vw, hCount;
    if(PlayerInfo[playerid][pAdmin] >= 4)
    {
        if(sscanf(params, "iiffffffii", houseid, houseprice, houseenterpos[0], houseenterpos[1], houseenterpos[2], houseexitpos[0], houseexitpos[1], houseexitpos[2], interior, vw))
        return SendClientMessage(playerid, COLOR_GREY, "Usage: /createhouse [houseid] [price] [enterx] [entery] [enterz] [exitx] [exity] [exitz] [interior] [virtualworld]");
        new rows, query[300];
        format(query, sizeof(query), "SELECT * FROM housedata");
        mysql_query(query);
        mysql_store_result();
        rows = mysql_num_rows();
        mysql_free_result();
        for(new i = 1; i < rows; i++)
        {
            hCount ++;
        }
        if(houseid < hCount) return SendClientMessage(playerid, COLOR_WHITE, "That houseid is in use!");
        CreateHouse(houseid, houseprice, houseenterpos[0], houseenterpos[1], houseenterpos[2], houseexitpos[0], houseexitpos[1], houseexitpos[2], interior, vw);
    }
    else return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command!");
    return 1;
}

//Bottom, stocks

stock CreateHouse(houseid, houseprice, houseenterposx, houseenterposy, houseenterposz, houseexitposx, houseexitposy, houseexitposz, houseinterior, housevw)
{
    new query[2000];
    format(query, sizeof(query), "INSERT INTO housedata (houseid, owner, owned, price, enterx, entery, enterz, exitx, exity, exitz, interior, virtualworld) VALUES(%i,'None', %i, %i, %f, %f, %f, %f, %f, %f, %i, %i)", houseid, 0, houseprice, houseenterposx, houseenterposy, houseenterposz, houseexitposx, houseexitposy, houseexitposz, houseinterior, housevw);
    mysql_query(query);
    format(HouseInfo[houseid][Owner], 24, "None");
    HouseInfo[houseid][Owned] = 0;
    ReloadHouses();
}
stock SaveHouses()
{
    new hCount, rows;
    rows = mysql_num_rows();
    for(new i = 1; i < rows; i++)
    {
        hCount ++;
        new Query[1000];
        format(Query, 1000, "UPDATE `housedata` SET `owner` = '%s', 'owned' = '%i', `price` = '%i', `enterx` = '%f', `entery` = '%f', `enterz` = '%f', `exitx` = '%f', `exity` = '%f', `exitz` = '%f', 'interior' = '%i', 'virtualworld' = '%i' WHERE `houseid` = '%i'",
        HouseInfo[i][Owner], HouseInfo[i][Owned], HouseInfo[i][Price], HouseInfo[i][EnterPos][0], HouseInfo[i][EnterPos][1], HouseInfo[i][EnterPos][2], HouseInfo[i][ExitPos][0], HouseInfo[i][ExitPos][1],HouseInfo[i][ExitPos][2], HouseInfo[i][Interior], HouseInfo[i][World], i);
        mysql_query(Query);
    }
    printf( "%i house(s) have been saved", hCount);
}
stock ReloadHouses()
{
    for(new i = 1; i < MAX_HOUSES; i++)
    {
        DestroyDynamic3DTextLabel(HouseInfo[i][Label]);
        DestroyDynamicPickup(HouseInfo[i][Pickup]);
    }
    LoadHouses();
}
stock LoadHouses()
{
    new rows, query[600];
    format(query, sizeof(query), "SELECT * FROM housedata");
    mysql_query(query);
    mysql_store_result();
    rows = mysql_num_rows();
    mysql_free_result();
    for(new i = 1; i < rows; i++)
    {
        new fquery[200];
        format(fquery, sizeof(fquery), "SELECT * FROM housedata WHERE id = %i", i);
        mysql_query(fquery);
        mysql_store_result();
        new savingstring[64];
        while(mysql_fetch_row_format(fquery, "|"))
        {
            mysql_fetch_field_row(HouseInfo[i][Owner], "owner");
            mysql_fetch_field_row(savingstring, "owned"); HouseInfo[i][Owned] = strval(savingstring);
            mysql_fetch_field_row(savingstring, "price"); HouseInfo[i][Price] = strval(savingstring);
            mysql_fetch_field_row(savingstring, "enterx"); HouseInfo[i][EnterPos][0] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "entery"); HouseInfo[i][EnterPos][1] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "enterz"); HouseInfo[i][EnterPos][2] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "exitx"); HouseInfo[i][ExitPos][0] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "exity"); HouseInfo[i][ExitPos][1] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "exitz"); HouseInfo[i][ExitPos][2] = floatstr(savingstring);
            mysql_fetch_field_row(savingstring, "interior"); HouseInfo[i][Interior] = strval(savingstring);
            mysql_fetch_field_row(savingstring, "virtualworld"); HouseInfo[i][World] = strval(savingstring);
            new message[100];
            format(message, sizeof(message), "House is owned by %s", HouseInfo[i][Owner]);
            HouseInfo[i][Pickup] = CreateDynamicPickup(1273, 1, HouseInfo[i][EnterPos][0], HouseInfo[i][EnterPos][1], HouseInfo[i][EnterPos][2]);
            HouseInfo[i][Label] = CreateDynamic3DTextLabel(message, COLOR_YELLOW, HouseInfo[i][EnterPos][0], HouseInfo[i][EnterPos][1], HouseInfo[i][EnterPos][2], 30.0, 0);
        }
        mysql_free_result();
    }
    printf("%i houses have been loaded!", rows);
}
If you guys could help me, it would be appreciated.
Reply
#2

EDIT: nevermind, I didn't read correctly.
Reply
#3

Thanks, changed it, but now I get obvious errors.

pawn Код:
mysql_fetch_field_row(savingstring, "owned"); HouseInfo[i][Owned] = strval(savingstring);
Since i is there, and it is no longer a created variable, what might I replace it with?

Again, thanks.

EDIT: mysql_fetch_row isn't even working, did you write it wrong?

EDIT2: Should I then use this?

pawn Код:
while(mysql_fetch_row(rows))
{
    for(new i = 1; i < MAX_HOUSES; i++)
    {
        //blablabla
Reply
#4

BUMP, really need assistance. Been really wanting to figure this out.
Reply
#5

What MySQL plugin are you using? If Its BlueG's r7 you MUST thread the queries.
Reply
#6

I'm using BlueG's any way I can accomplish this?

Would really appreciate assistance.

PS: Would love it if you fixed the code, showed it, and possibly explain part of what you edited and what they do.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)