Loading Houses from MySQL database to server
#1

Hi,

I've been trying to make a House System, but I'm stuck on loading the houses to the server from the MySQL database. Here is the function,

pawn Код:
forward LoadHouses();
public LoadHouses()
{
    for(new i=1; i<=MAX_HOUSES; i++)
    {
        new query[256];
        format(query, sizeof(query), "SELECT * FROM `"Houses_Table"` WHERE `ID` = '%i'", i);
        mysql_query(query);
        mysql_store_result();
        if(mysql_num_rows() == 0) break;
        else if(mysql_num_rows() != 0)
        {
            mysql_fetch_row_format(query);
            sscanf(query, "e<p<|>is[25]iiiiiffffff>", hInfo[i]);
            new lString[256];
            if(hInfo[i][OnSale] == 0 )
            {
                switch(hInfo[i][Owned])
                {
                    case 0:
                    {
                        format(lString, sizeof(lString), "House Owned: No\nHouse Owner: None\nHouse Price: $%i", hInfo[i][Price]);
                        hInfo[i][Label] = CreateDynamic3DTextLabel(lString, 0x00B9FFFF, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ]+0.5, 36.0);
                        hInfo[i][Icon] = CreateDynamicMapIcon(hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ], 31, -1);
                        hInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ], -1, -1, -1, 36.0);
                    }
                    case 1:
                    {
                        format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Locked: %s", hInfo[i][Owner], (hInfo[i][Locked] == 1) ? ("Yes") : ("No"));
                        hInfo[i][Label] = CreateDynamic3DTextLabel(lString, 0xFF0000FF, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ]+0.5, 36.0);
                        //hInfo[i][Icon] = CreateDynamicMapIcon(hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ], 32, -1);
                        hInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[i][OX],hInfo[i][OY], hInfo[i][OZ], -1, -1, -1, 36.0);
                    }
                }
            }
            if(hInfo[i][Owned] == 1)
            {
                if(hInfo[i][OnSale] == 1)
                {
                    format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse On Sale: Yes", hInfo[i][Owner], hInfo[i][Price]);
                    hInfo[i][Label] = CreateDynamic3DTextLabel(lString, 0xD65418FF, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ]+0.5, 36.0);
                    hInfo[i][Icon] = CreateDynamicMapIcon(hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ], 32, -1);
                    hInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[i][OX],hInfo[i][OY], hInfo[i][OZ], -1, -1, -1, 36.0);
                }
            }
            CreatedHouses++;
        }
    }
    mysql_free_result();
    printf("[House System] %i houses were created...", CreatedHouses);
    return 1;
}
And I have LoadHouses(); under OnGameModeInit. I have around 10 houses saved to the database now. But when I start the server, it says 0 houses were created. And when I go ingame, there are no houses around. How can I fix this problem?

Thanks
Reply


Messages In This Thread
Loading Houses from MySQL database to server - by FunnyBear - 01.02.2015, 09:49
Re: Loading Houses from MySQL database to server - by Goldino - 01.02.2015, 11:24
Re: Loading Houses from MySQL database to server - by FunnyBear - 01.02.2015, 11:42
Re: Loading Houses from MySQL database to server - by BroZeus - 01.02.2015, 12:09
Re: Loading Houses from MySQL database to server - by FunnyBear - 01.02.2015, 12:30

Forum Jump:


Users browsing this thread: 1 Guest(s)