SA-MP Forums Archive
help change to sqlite - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: help change to sqlite (/showthread.php?tid=481612)



help change to sqlite - Cerealguy - 16.12.2013

hi $:, someone explain to me how to change it please sqlite

pawn Код:
stock GetFreeHouseID()
{
    Loop(h, MAX_HOUSES, 0)
    {
        if(!fexist(HouseFile(h)))
        {
            return h;
        }
    }
    return -1;
}



Re: help change to sqlite - dominik523 - 16.12.2013

I recently switched from dini to SQLite and my CreateHouse command searches for house level that is equal to 0, and then it change it to some other. You need to use saving and loading only with SQLite, you don't need to do anything with it while you are creating/deleting houses or anything.
But if you want really want to it while you are creating a house, you should search for the first empty row in your database.
Here is the example:
pawn Код:
for(new i = 0; i< MAX_HOUSES, i++)
{
     format(string, sizeof(string), "SELECT ID FROM `houses` WHERE `ID`='%d'", i);
        dbresult = db_query(Database, string);
        if(!db_num_rows(dbresult))
        {
            // code for creating the house
            return 1;
        }
            db_free_result(dbresult);
}



Respuesta: help change to sqlite - Cerealguy - 16.12.2013

Thanks friend, I want to achieve is that if I have 100 houses and 80 delete the id I get to look again create an empty space in such a case would be 80. and not follow 101.

Sorry use translate


Re: help change to sqlite - dominik523 - 16.12.2013

so you want to check the first ID that is unused?


Respuesta: help change to sqlite - Cerealguy - 16.12.2013

If bone, Guide createhouse command:

id = GetFreeHouseID ();

so take some ID, this is not another home using


Respuesta: help change to sqlite - Cerealguy - 18.12.2013

small bump