[HELP] in mysql log it load house data but on server no houses
#1

Hello I was create 3 houses in my database and turn off server and again turn on and it says in mysql log dat is data fine loaded position owner of the house etc... but I was enter in my server and go to that place where I create house and house isn't on that place where I put it

so this is on ongamemodeinit


pawn Код:
format(szString,sizeof szString,"SELECT * FROM `houses`");
    mysql_tquery(mysql,szString,"LoadHouses","");

and here is LoadHouses

pawn Код:
public LoadHouses()
{
    new rows,fields,str[800];
    cache_get_data(rows,fields,mysql);
    if(rows)
    {
        new i = 0;
        while(rows > i < MAX_HOUSES)
        {
            KucaInfo[i][ID] = cache_get_field_content_int(0,"ID");
            KucaInfo[i][hUlazX] = cache_get_field_content_float(0,"UlazX");
            KucaInfo[i][hUlazY] = cache_get_field_content_float(0,"UlazY");
            KucaInfo[i][hUlazZ] = cache_get_field_content_float(0,"UlazZ");
            KucaInfo[i][hIzlazX] = cache_get_field_content_float(0,"IzlazX");
            KucaInfo[i][hIzlazY] = cache_get_field_content_float(0,"IzlazY");
            KucaInfo[i][hIzlazZ] = cache_get_field_content_float(0,"IzlazZ");
            KucaInfo[i][hTip] = cache_get_field_content_int(0,"Tip");
            KucaInfo[i][hLevel] = cache_get_field_content_int(0,"Level");
            KucaInfo[i][hRooms] = cache_get_field_content_int(0,"BrojSoba");
            KucaInfo[i][hInt] = cache_get_field_content_int(0,"Interior");
            KucaInfo[i][hHel] = cache_get_field_content_int(0,"hHel");
            KucaInfo[i][hArm] = cache_get_field_content_int(0,"hArm");
            KucaInfo[i][hImaVlasnika] = cache_get_field_content_int(0,"ImaVlasnika");
            KucaInfo[i][hWorld] = cache_get_field_content_int(0,"hWorld");
            KucaInfo[i][hCijena] = cache_get_field_content_int(0,"Cijena");
            cache_get_field_content(0,"Opis",KucaInfo[i][hOpis],mysql,128);
            cache_get_field_content(0,"Vlasnik",KucaInfo[i][hVlasnik],mysql,128);
            KucaInfo[i][hRentabil] = cache_get_field_content_int(0,"DostupnoZaRent");
            KucaInfo[i][hRent] = cache_get_field_content_int(0,"Rent");
            KucaInfo[i][hLock] = cache_get_field_content_int(0,"Zakljucano");
            cache_get_field_content(0,"Adresa",KucaInfo[i][hAdresa],mysql,128);
            KucaInfo[i][hSef] = cache_get_field_content_int(0,"hSef");
            KucaInfo[i][hDroga] = cache_get_field_content_int(0,"hDroga");
            KucaInfo[i][hMats] = cache_get_field_content_int(0,"hMats");
            KucaInfo[i][Oruzje1] = cache_get_field_content_int(0,"Oruzje1");
            KucaInfo[i][Municija1] = cache_get_field_content_int(0,"Municija1");
            KucaInfo[i][Oruzje2] = cache_get_field_content_int(0,"Oruzje2");
            KucaInfo[i][Municija2] = cache_get_field_content_int(0,"Municija2");
            KucaInfo[i][Oruzje3] = cache_get_field_content_int(0,"Oruzje3");
            KucaInfo[i][Municija3] = cache_get_field_content_int(0,"Municija3");
            i++;
            if(KucaInfo[i][hImaVlasnika] == 0)
            {
                format(str,sizeof(str),"{0ed400}Na Prodaju\n{0ed400}Opis: {FFFFFF}%s\n{0ed400}Level: {FFFFFF}%d\n{0ed400}Adresa: {FFFFFF}%s\n{0ed400}Cijena: {FFFFFF}%d$",KucaInfo[i][hOpis],KucaInfo[i][hLevel],KucaInfo[i][hAdresa],KucaInfo[i][hCijena]);
                UpdateDynamic3DTextLabelText(KucaLabel[i],0x00FFFFFF,str);
                DestroyDynamicPickup(KucaPickup[i]);
                KucaPickup[i] = CreateDynamicPickup(1273,1,KucaInfo[i][hUlazX],KucaInfo[i][hUlazY],KucaInfo[i][hUlazZ]);
            }
            if(KucaInfo[i][hImaVlasnika] == 1)
            {
                if(KucaInfo[i][hRentabil] == 0)
                {
                    format(str,800,"{0ed400}Vlasnik Kuce: {FFFFFF}%s\n{0ed400}Opis: {FFFFFF}%s\n{0ed400}Level: {FFFFFF}%d\n{0ed400}Adresa: {FFFFFF}%s",KucaInfo[i][hVlasnik],KucaInfo[i][hOpis],KucaInfo[i][hLevel],KucaInfo[i][hAdresa]);
                }
                else if(KucaInfo[i][hRentabil] == 1)
                {
                    format(str,800,"{0ed400}Vlasnik Kuce: {FFFFFF}%s\n{0ed400}Opis: {FFFFFF}%s\n{0ed400}Level: {FFFFFF}%d\n{0ed400}Adresa: {FFFFFF}%s\n{0ed400}Rent: {FFFFFF}%d$\n{0ed400}Najam: {FFFFFF}/rentroom",KucaInfo[i][hVlasnik],KucaInfo[i][hOpis],KucaInfo[i][hLevel],KucaInfo[i][hAdresa],KucaInfo[i][hRent]);
                }
                UpdateDynamic3DTextLabelText(KucaLabel[i],0x00FF00AA,str);
                DestroyDynamicPickup(KucaPickup[i]);
                KucaPickup[i] = CreateDynamicPickup(1239,1,KucaInfo[i][hUlazX],KucaInfo[i][hUlazY],KucaInfo[i][hUlazZ]);
            }
        }
    }
    return 1;
}
Reply
#2

Does your ID start at 1?
Also, is that column set to auto_increment?
Reply
#3

yes and yes that column is set to auto_increment and it go first house id 1 then id 2 etc...
Reply
#4

Why do you destroy the pickups first before re-creating it?
When the server is started (OnGameModeInit), there are no pickups yet, and there is nothing to destroy.
Unless you create them first for all house-slots of your array before you load the data (which would be weird as you don't know how many houses are stored in your database before loading the data).
You wouldn't know at which coordinates you need to create the pickups because your data isn't loaded yet.

Also, why is the i++ in the middle of the code?
You're first loading data, you store it in the array, then when you start creating the pickups and updating textlabels (which is also weird as the textlabels don't exist yet, unless you filled the array with empty labels as well before loading the houses), you store the ID's of those things in the next array index.

For the first house, you store the data in index 0.
Then you increase i by 1 using i++;
The pickup and textlabels would be inside index 1, according to your code (because of the i++ between the code).
And while you have selected the next index of your array before creating the pickups/textlabels, you always get coordinates 0, 0, 0, as there is no data yet in this array-index.
The code may still create the pickups, but they're all at coordinates 0, 0, 0.
This is near Easterboard Farm, below the ground.

Also, you still load the first house's data over and over again, because you always specify "0" as row in every cache_get_field_content_int, cache_get_field_content_float and cache_get_field_content.

If you have 20 houses, you would load the data of the first house 20 times and ignore the next 19 houses.
You'll in fact create 20 identical houses, all on the same location with the same data.

Just as a test: make a quick command that teleports your char to coordinates 0, 0, 0.
You'll start to fall as you teleported below the ground, but you should be able to see the pickups/textlabels below the ground at those coordinates while falling.



You could remove the auto_increment from that column and use the ID of the house as index for the array.
Don't use HouseID 0, start at ID 1 (like you already do).
Then, use the same query to load the data.
The first value to read is the ID from your query.
Use this ID to access your array for storing the rest of the data (position, house-level and whatever comes next) and to create your pickup and textlabel.

You could also use a check to see if the ID lies between 1 and (MAX_HOUSES - 1).
If it is, load the data and create the house.
If the ID is outside this range (which would result in array-out-of-bounds errors), ignore the data and continue with the next house.
Reply
#5

So know I increase i instead 0 to 1 like this new i = 1; and I'm I for every house this new i = 1 inrease on 2 3 etc or. I put i++ on the end of code and I creating 3dtextlabel and know it load all fine but it load just one house on server not three like in database. I'm

pawn Код:
if(KucaInfo[i][hImaVlasnika] == 0)
            {
                format(str,sizeof(str),"{0ed400}Na Prodaju\n{0ed400}Opis: {FFFFFF}%s\n{0ed400}Level: {FFFFFF}%d\n{0ed400}Adresa: {FFFFFF}%s\n{0ed400}Cijena: {FFFFFF}%d$",KucaInfo[i][hOpis],KucaInfo[i][hLevel],KucaInfo[i][hAdresa],KucaInfo[i][hCijena]);
                UpdateDynamic3DTextLabelText(KucaLabel[i],0x00FFFFFF,str);
                DestroyDynamicPickup(KucaPickup[i]);
                KucaPickup[i] = CreateDynamicPickup(1273,1,KucaInfo[i][hUlazX],KucaInfo[i][hUlazY],KucaInfo[i][hUlazZ]);
            }
            if(KucaInfo[i][hImaVlasnika] == 1)
            {
                if(KucaInfo[i][hRentabil] == 0)
                {
                    format(str,800,"{0ed400}Vlasnik Kuce: {FFFFFF}%s\n{0ed400}Opis: {FFFFFF}%s\n{0ed400}Level: {FFFFFF}%d\n{0ed400}Adresa: {FFFFFF}%s",KucaInfo[i][hVlasnik],KucaInfo[i][hOpis],KucaInfo[i][hLevel],KucaInfo[i][hAdresa]);
                }
                else if(KucaInfo[i][hRentabil] == 1)
                {
                    format(str,800,"{0ed400}Vlasnik Kuce: {FFFFFF}%s\n{0ed400}Opis: {FFFFFF}%s\n{0ed400}Level: {FFFFFF}%d\n{0ed400}Adresa: {FFFFFF}%s\n{0ed400}Rent: {FFFFFF}%d$\n{0ed400}Najam: {FFFFFF}/rentroom",KucaInfo[i][hVlasnik],KucaInfo[i][hOpis],KucaInfo[i][hLevel],KucaInfo[i][hAdresa],KucaInfo[i][hRent]);
                }
                UpdateDynamic3DTextLabelText(KucaLabel[i],0x00FF00AA,str);
                DestroyDynamicPickup(KucaPickup[i]);
                KucaPickup[i] = CreateDynamicPickup(1239,1,KucaInfo[i][hUlazX],KucaInfo[i][hUlazY],KucaInfo[i][hUlazZ]);
            }//under this I put i++;
Reply
#6

pawn Код:
KucaInfo[i][ID] = cache_get_field_content_int(0,"ID");
            KucaInfo[i][hUlazX] = cache_get_field_content_float(0,"UlazX");
            KucaInfo[i][hUlazY] = cache_get_field_content_float(0,"UlazY");
            KucaInfo[i][hUlazZ] = cache_get_field_content_float(0,"UlazZ");
            KucaInfo[i][hIzlazX] = cache_get_field_content_float(0,"IzlazX");
            KucaInfo[i][hIzlazY] = cache_get_field_content_float(0,"IzlazY");
            KucaInfo[i][hIzlazZ] = cache_get_field_content_float(0,"IzlazZ");
            KucaInfo[i][hTip] = cache_get_field_content_int(0,"Tip");
            KucaInfo[i][hLevel] = cache_get_field_content_int(0,"Level");
            KucaInfo[i][hRooms] = cache_get_field_content_int(0,"BrojSoba");
            KucaInfo[i][hInt] = cache_get_field_content_int(0,"Interior");
            KucaInfo[i][hHel] = cache_get_field_content_int(0,"hHel");
            KucaInfo[i][hArm] = cache_get_field_content_int(0,"hArm");
            KucaInfo[i][hImaVlasnika] = cache_get_field_content_int(0,"ImaVlasnika");
            KucaInfo[i][hWorld] = cache_get_field_content_int(0,"hWorld");
            KucaInfo[i][hCijena] = cache_get_field_content_int(0,"Cijena");
            cache_get_field_content(0,"Opis",KucaInfo[i][hOpis],mysql,128);
            cache_get_field_content(0,"Vlasnik",KucaInfo[i][hVlasnik],mysql,128);
            KucaInfo[i][hRentabil] = cache_get_field_content_int(0,"DostupnoZaRent");
            KucaInfo[i][hRent] = cache_get_field_content_int(0,"Rent");
            KucaInfo[i][hLock] = cache_get_field_content_int(0,"Zakljucano");
            cache_get_field_content(0,"Adresa",KucaInfo[i][hAdresa],mysql,128);
            KucaInfo[i][hSef] = cache_get_field_content_int(0,"hSef");
            KucaInfo[i][hDroga] = cache_get_field_content_int(0,"hDroga");
            KucaInfo[i][hMats] = cache_get_field_content_int(0,"hMats");
            KucaInfo[i][Oruzje1] = cache_get_field_content_int(0,"Oruzje1");
            KucaInfo[i][Municija1] = cache_get_field_content_int(0,"Municija1");
            KucaInfo[i][Oruzje2] = cache_get_field_content_int(0,"Oruzje2");
            KucaInfo[i][Municija2] = cache_get_field_content_int(0,"Municija2");
            KucaInfo[i][Oruzje3] = cache_get_field_content_int(0,"Oruzje3");
            KucaInfo[i][Municija3] = cache_get_field_content_int(0,"Municija3");

Replace the "0" in each line by "i".
This is what causes your code to load the first house and not the rest.


Look at a query-result like you look on a piece of paper with lines.
You asked MySQL to write all house-data on that piece of paper, where every house has it's data on 1 line.
You have 3 houses in your database, so MySQL will return you a piece of paper with 3 lines of data.
The first line has row-number 0, then 1 and 2.

But your code always reads the data from row 0 (the first row = the first house).
pawn Код:
KucaInfo[i][hUlazX] = cache_get_field_content_float(0,"UlazX");
For every house, you need to get the data from the next row.
So:
pawn Код:
KucaInfo[i][hUlazX] = cache_get_field_content_float(i,"UlazX");
This would be correct.
Since your loop increases "i" for every house, you should also use this "i" to load the rows separately for every house.
Reply
#7

Ok the houses are on places where I create them just one more thing how you mean this:


you should also use this "i" to load the rows separately for every house.

Thanks very much.
Reply
#8

Quote:
Originally Posted by Luca12
Посмотреть сообщение
Ok the houses are on places where I create them just one more thing how you mean this:


you should also use this "i" to load the rows separately for every house.

Thanks very much.
I just meant, every house has it's own row with data.
Always loading row 0 means that you always read the data from the first house, and ignore the rest.

Using the "i" as row-number to load the data, that will mean that with every loop, the next row is selected in the query-result to read the data from that row.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)