Cars ain't loading, MySQL
#1

Hey folks,

I've been scripting a MySQL vehicle system, the problem is the vehicles aren't loading.


This is what I have done so far.

pawn Код:
stock LoadPlayerCars(playerid)
{
    new query[120];
    new name[MAX_PLAYER_NAME];
    new rows = cache_num_rows();
    GetPlayerName(playerid,name,sizeof(name));
    mysql_format(mysql,query,sizeof(query),"SELECT * FROM `cars` WHERE `Owner` = '%s'",name);
    mysql_tquery(mysql,query);
    printf("%s",query);

    for (new i = 0; i < rows; i ++)  // Ejemplo
    {
        CarInfo[i][cID] = cache_get_field_content_int(0, "ID");
        CarInfo[i][cOwner] = cache_get_field_content(0, "Owner", CarInfo[i][cOwner]);
        CarInfo[i][cModel] = cache_get_field_content_int(0, "Model");
        CarInfo[i][cColor1] = cache_get_field_content_int(0, "VehicleColor1");
        CarInfo[i][cColor2] = cache_get_field_content_int(0, "VehicleColor2");
        CarInfo[i][cXPos] = cache_get_field_content_float(0, "XCoord");
        CarInfo[i][cYPos] = cache_get_field_content_float(0, "YCoord");
        CarInfo[i][cZPos] = cache_get_field_content_float(0, "ZCoord");
        CarInfo[i][cPlate] = cache_get_field_content(0, "VehiclePlate", CarInfo[i][cPlate]);
        validcar[i] = true;
        CreateVehicle(CarInfo[i][cModel], CarInfo[i][cXPos], CarInfo[i][cYPos], CarInfo[i][cYPos], 266, CarInfo[i][cColor1], CarInfo[i][cColor2], -1);
    }
}
Still can't figure out why it doesn't load the vehicle.

Any help will be appreciated
Reply
#2

You have used the threaded queries in wrong way, you should call the syntax text(Query) in a callback, and load (cache_get etc.. ) in another callback, example:
pawn Код:
public OnPlayerConnect(playerid)
{
new query[120];
    new name[MAX_PLAYER_NAME];
    new rows = cache_num_rows();
    GetPlayerName(playerid,name,sizeof(name));
    mysql_format(mysql,query,sizeof(query),"SELECT * FROM `cars` WHERE `Owner` = '%s'",name);
    mysql_tquery(mysql,query);
    printf("%s",query);
    return 1;
That was query's callback, now ,lets do the loading info callback.
pawn Код:
forward LoadPlayerCars(playerid)
public LoadPlayerCars(playerid)
{
        for (new i; i < rows; i++)  // Ejemplo
       {
            if(rows) // check if there are rows or not, to not return bugs..
            {
             CarInfo[i][cID] = cache_get_field_content_int(0, "ID");
             CarInfo[i][cOwner] = cache_get_field_content(0, "Owner", CarInfo[i][cOwner]);
             CarInfo[i][cModel] = cache_get_field_content_int(0, "Model");
             CarInfo[i][cColor1] = cache_get_field_content_int(0, "VehicleColor1");
             CarInfo[i][cColor2] = cache_get_field_content_int(0, "VehicleColor2");
             CarInfo[i][cXPos] = cache_get_field_content_float(0, "XCoord");
             CarInfo[i][cYPos] = cache_get_field_content_float(0, "YCoord");
             CarInfo[i][cZPos] = cache_get_field_content_float(0, "ZCoord");
             CarInfo[i][cPlate] = cache_get_field_content(0, "VehiclePlate", CarInfo[i][cPlate]);
           validcar[i] = true;
           CreateVehicle(CarInfo[i][cModel], CarInfo[i][cXPos], CarInfo[i][cYPos], CarInfo[i][cYPos], 266, CarInfo[i]                  [cColor1], CarInfo[i][cColor2], -1);
        }
    }
    return 1;
}
.
Reply
#3

Quote:
Originally Posted by Sawalha
Посмотреть сообщение
You have used the threaded queries in wrong way, you should call the syntax text(Query) in a callback, and load (cache_get etc.. ) in another callback, example:
pawn Код:
public OnPlayerConnect(playerid)
{
new query[120];
    new name[MAX_PLAYER_NAME];
    new rows = cache_num_rows();
    GetPlayerName(playerid,name,sizeof(name));
    mysql_format(mysql,query,sizeof(query),"SELECT * FROM `cars` WHERE `Owner` = '%s'",name);
    mysql_tquery(mysql,query);
    printf("%s",query);
    return 1;
That was query's callback, now ,lets do the loading info callback.
pawn Код:
forward LoadPlayerCars(playerid)
public LoadPlayerCars(playerid)
{
        for (new i; i < rows; i++)  // Ejemplo
       {
            if(rows) // check if there are rows or not, to not return bugs..
            {
             CarInfo[i][cID] = cache_get_field_content_int(0, "ID");
             CarInfo[i][cOwner] = cache_get_field_content(0, "Owner", CarInfo[i][cOwner]);
             CarInfo[i][cModel] = cache_get_field_content_int(0, "Model");
             CarInfo[i][cColor1] = cache_get_field_content_int(0, "VehicleColor1");
             CarInfo[i][cColor2] = cache_get_field_content_int(0, "VehicleColor2");
             CarInfo[i][cXPos] = cache_get_field_content_float(0, "XCoord");
             CarInfo[i][cYPos] = cache_get_field_content_float(0, "YCoord");
             CarInfo[i][cZPos] = cache_get_field_content_float(0, "ZCoord");
             CarInfo[i][cPlate] = cache_get_field_content(0, "VehiclePlate", CarInfo[i][cPlate]);
           validcar[i] = true;
           CreateVehicle(CarInfo[i][cModel], CarInfo[i][cXPos], CarInfo[i][cYPos], CarInfo[i][cYPos], 266, CarInfo[i]                  [cColor1], CarInfo[i][cColor2], -1);
        }
    }
    return 1;
}
.
Thanks dude, It works now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)