how to make a simple house system
#7

I've got no clue what SII is, for a database it's preferable to use MySQL or SQLite, as they are considered to be one of the best ones.

Anyway, the steps to making a house system is simple,
- Create an enumerator storing all the information you would want the house to have, and then create an array, for example:
Код:
#define MAX_HOUSES (100)

enum hEnum
{
     hExists,
     hID,
     hOwnerID,
     hOwner[MAX_PLAYER_NAME],
     Float: hPosX,
     Float: hPosY,
     Float: hPosZ,
};

new HouseInfo[MAX_HOUSES][hEnum];
- After doing that, you should create a new table in your preferred database and add the columns you would like to save, so in this case we would save the automatically incremented ID, the owner, his name, and the position of where the pickup would spawn.
- Make a system for saving the houses into your preferred database, store the same variables I mentioned above, or whatever variables you have in your database. This can be easily done by using:
Код:
mysql_format(connectionID, queryBuffer, sizeof(queryBuffer), "INSERT INTO houses VALUES(NULL, '%i', '%s', '%f', '%f', '%f')", userid, username, position_x, position_y, position_z);
mysql_tquery(connectionID, queryBuffer);
The above code inserts a new row into your database creating a new house.
- Obviously after saving and creating a house you need to load it, for example:
Код:
enum
{
     THREAD_LOAD_HOUSES = 1,
}

public OnGameModeInit()
{
     mysql_tquery(connectionID, "SELECT * FROM houses*, "OnQueryFinished", "ii", THREAD_LOAD_HOUSES, 0);
     return 1;
}

public OnQueryFinished(threadid, addid)
{
     new rows = cache_get_row_count(connectionID);
     switch(threadid)
     {
          case THREAD_LOAD_HOUSES:
          {
               if(rows)
               {
                    for(new i = 0; i < rows; ++i)
                    {
                         // Load the houses. An example would be to get the house's unique identification:
                         HouseInfo[i][hID] = cache_get_field_content_int(i, "id");
                    }
               }
          }
     }
}
connectionID substitutes to the connection you made in OnGameModeInit() with the database. In this case mine is named that way.
queryBuffer substitutes as a global string mainly used for formating queries, they are both defined like this (above everything else, below the includes):

Код:
new connectionID;
new queryBuffer[1024];
- After doing all of that, you should make commands to create the houses, destroy houses, change something about the houses and so on.

Hope this helped you at least a little bit.
Reply


Messages In This Thread
how to make a simple house system - by Jithu - 17.03.2018, 13:19
Re: how to make a simple house system - by Jithu - 17.03.2018, 13:25
Re: how to make a simple house system - by Jithu - 17.03.2018, 13:48
Re: how to make a simple house system - by 10MIN - 17.03.2018, 14:33
Re: how to make a simple house system - by iKarim - 17.03.2018, 14:45
Re: how to make a simple house system - by jasperschellekens - 17.03.2018, 15:08
Re: how to make a simple house system - by m1kas - 17.03.2018, 23:19
Re: how to make a simple house system - by Jithu - 18.03.2018, 03:14

Forum Jump:


Users browsing this thread: 1 Guest(s)