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
#2

Hmm... I don't get it. Can you explain it abit more?
Reply
#3

Quote:
Originally Posted by Goldino
Посмотреть сообщение
Hmm... I don't get it. Can you explain it abit more?
I have a loadhouse functions which loads the houses from the MySQL database when the server starts. However, it doesn't work, I've tried other ways aswell, but I can't get it to work
Reply
#4

paste this OnGameModeInit
pawn Код:
mysql_log(LOG_ALL);
Compile the script
Run the script
then see mysql_log.txt in server directory to see if any query has error..
Reply
#5

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
paste this OnGameModeInit
pawn Код:
mysql_log(LOG_ALL);
Compile the script
Run the script
then see mysql_log.txt in server directory to see if any query has error..
I've looked in the debug, but I can't seem to find the query which selects everything from the database, I tried using CTRL + F to search but I couldn't find anything. When I start up the server, it says [House System] 0 houses were created. So no houses have been loaded. I've also tried many other methods of trying to load the houses but none of them work.

I'm really confused now
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)