SA-MP Forums Archive
MySQL - 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: MySQL (/showthread.php?tid=339273)



MySQL - N0FeaR - 02.05.2012

I have building system on MySQL but the bulilding id 10 wont come in come and the script load 10 buildings

10 Buildings loaded from database

MySQL load

pawn Код:
}

forward LoadBuilding();
public LoadBuilding()
{
    new arrCoords[11][64];
    new sql[80], row[512];
    format(sql, sizeof(sql), "SELECT COUNT(*) FROM Buildings");
    mysql_query(sql);
    mysql_store_result();
    mysql_fetch_row(row);
    totalbuildings = 10;
    mysql_free_result();

    for (new idx=0; idx<totalbuildings; idx++)
    {
        format(sql, sizeof(sql), "SELECT * FROM Buildings WHERE BuildingID=%d", idx);
        mysql_query(sql);
        mysql_store_result();
        if (mysql_num_rows() > 0)
        {
            mysql_fetch_row(row);
            split(row, arrCoords, '|');
            mysql_free_result();
            Building[idx][EnterX] = floatstr(arrCoords[1]);
            Building[idx][EnterY] = floatstr(arrCoords[2]);
            Building[idx][EnterZ] = floatstr(arrCoords[3]);
            Building[idx][PickupID] = strval(arrCoords[4]);
            Building[idx][ExitX] = floatstr(arrCoords[5]);
            Building[idx][ExitY] = floatstr(arrCoords[6]);
            Building[idx][ExitZ] = floatstr(arrCoords[7]);
            strmid(Building[idx][BuildingName], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            Building[idx][ExitInterior] = strval(arrCoords[9]);
            Building[idx][Custom] = strval(arrCoords[10]);

            //Building[idx][PickupID] = CreateStreamPickup(1239, 1, Building[idx][EnterX], Building[idx][EnterY], Building[idx][EnterZ],15);
            CreateDynamicPickup(1318, 1, Building[idx][EnterX], Building[idx][EnterY], Building[idx][EnterZ], -1, -1, -1, 40.0);
        }
    }
    mysql_free_result();
    printf("%d Buildings loaded from database", totalbuildings);
    return true;
}



Re: MySQL - WackoX - 02.05.2012

Код:
totalbuildings = 11;
Or just use <= instead of <.


Re: MySQL - N0FeaR - 02.05.2012

Quote:
Originally Posted by WackoX
Посмотреть сообщение
Код:
totalbuildings = 11;
Or just use <= instead of <.
Still same, anyone else can help me?


Re: MySQL - MadeMan - 03.05.2012

pawn Код:
mysql_query(sql);
mysql_store_result();
totalbuildings = mysql_fetch_int();
mysql_free_result();



Re: MySQL - N0FeaR - 03.05.2012

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
pawn Код:
mysql_query(sql);
mysql_store_result();
totalbuildings = mysql_fetch_int();
mysql_free_result();
Same, what is the problem ?


Re: MySQL - MadeMan - 03.05.2012

Quote:
Originally Posted by N0FeaR
Посмотреть сообщение
Same, what is the problem ?
You tell me.


Re: MySQL - N0FeaR - 03.05.2012

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
You tell me.
Is not working building 10 is no come up in game but says they load 10 buildings.

Here is the load again

pawn Код:
forward LoadBuilding();
public LoadBuilding()
{
    new arrCoords[11][64];
    new sql[80], row[512];
    format(sql, sizeof(sql), "SELECT COUNT(*) FROM Buildings");
    mysql_query(sql);
    mysql_fetch_row(row);
    mysql_store_result();
    totalbuildings = mysql_fetch_int();
    mysql_free_result();

    for (new idx=0; idx<totalbuildings; idx++)
    {
        format(sql, sizeof(sql), "SELECT * FROM Buildings WHERE BuildingID=%d", idx);
        mysql_query(sql);
        mysql_store_result();
        if (mysql_num_rows() > 0)
        {
            mysql_fetch_row(row);
            split(row, arrCoords, '|');
            mysql_free_result();
            Building[idx][EnterX] = floatstr(arrCoords[1]);
            Building[idx][EnterY] = floatstr(arrCoords[2]);
            Building[idx][EnterZ] = floatstr(arrCoords[3]);
            Building[idx][PickupID] = strval(arrCoords[4]);
            Building[idx][ExitX] = floatstr(arrCoords[5]);
            Building[idx][ExitY] = floatstr(arrCoords[6]);
            Building[idx][ExitZ] = floatstr(arrCoords[7]);
            strmid(Building[idx][BuildingName], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            Building[idx][ExitInterior] = strval(arrCoords[9]);
            Building[idx][Custom] = strval(arrCoords[10]);

            //Building[idx][PickupID] = CreateStreamPickup(1239, 1, Building[idx][EnterX], Building[idx][EnterY], Building[idx][EnterZ],15);
            CreateDynamicPickup(1318, 1, Building[idx][EnterX], Building[idx][EnterY], Building[idx][EnterZ], -1, -1, -1, 40.0);
        }
    }
    mysql_free_result();
    printf("%d Buildings loaded from database", totalbuildings);
    return true;
}



Re: MySQL - Calgon - 03.05.2012

Are you sure buildings don't start off at 0?


Re: MySQL - N0FeaR - 03.05.2012

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Are you sure buildings don't start off at 0?
Nope, start with 1


Re: MySQL - MadeMan - 03.05.2012

Quote:
Originally Posted by N0FeaR
Посмотреть сообщение
Nope, start with 1
They start with 0 here

pawn Код:
for (new idx=0; idx<totalbuildings; idx++)