MySQL Load car problems
#1

pawn Код:
forward LoadCityCars();
public LoadCityCars()
{
    new sql[64], car[10][64], row[255];
    new totalcars;
    format(sql, sizeof(sql), "SELECT COUNT(*) FROM Vehicles");
    mysql_query(sql);
    mysql_store_result();
    mysql_fetch_row(row);
    totalcars = strvalEx(row);
    mysql_free_result();
    for (new i=0; i<=totalcars; i++)
    {
        format(sql, sizeof(sql), "SELECT * FROM Vehicles WHERE carid=%d", i);
        mysql_query(sql);
        mysql_store_result();
        mysql_fetch_row(row);
        split(row, car, '|');
        mysql_free_result();
        AddStaticVehicleEx(strvalEx(car[1]), strvalEx(car[2]), strvalEx(car[3]), strvalEx(car[4]), strvalEx(car[5]),strvalEx(car[6]), strvalEx(car[7]), 2500000);
        VehicleInfo[i][CarModel] = strvalEx(car[1]);
        VehicleInfo[i][CarX] = strvalEx(car[2]);
        VehicleInfo[i][CarY] = strvalEx(car[3]);
        VehicleInfo[i][CarZ] = strvalEx(car[4]);
        VehicleInfo[i][CarAngle] = strvalEx(car[5]);
        VehicleInfo[i][CarColor1] = strvalEx(car[6]);
        VehicleInfo[i][CarColor2] = strvalEx(car[7]);
        VehicleInfo[i][FactionCar] = strvalEx(car[8]);
        VehicleInfo[i][CarType] = strvalEx(car[9]);
    }
}
This isn't working as it should, it sets the FactionCar to every vehicle that spawns, so i cant enter any vehicles.
I know i did a fix for this in my old mysql load thing, could anybody help me out ?
Reply
#2

Okay, first of all:
This script wont work anymore when a car get's removed in-game (like selling a car) because it will take the number of rows in the database. So you have id 1 to 5, 4 get's removed, and 6 is bought. It will take id 1-5, and not 1-6. So, use a while loop.
pawn Код:
new query[100], data[100];
mysql_query("SELECT model, x, y, z FROM vehicles");
mysql_store_result();
while(mysql_fetch_row(data))
{
This will loop untill there are no more row's in the database.
sscanf(data, "p<|>ifff", VehicleInfo[i][CarModel], VehicleInfo[i][CarX], VehicleInfo[i][CarY], VehicleInfo[i][CarZ]); //dont know if you know how sscanf works
}
Still not working? Pm me
Reply
#3

mmm your mysql debug log make errors on query?
Reply
#4

// Nevermind, rewrote it all and it worked.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)