MYSQL Vehicles
#1

Having a little bit of an issue with my saving and loading of my cars in my mysql database. The cars are getting added as they should be. Vehicleid's start with id 0 in the database, when they should start with id 1.

PHP код:
forward loadStaticVehicles();
public 
loadStaticVehicles()
{
    static 
rows,fields;
    
cache_get_data(rowsfieldsdbHandle);
    
StaticVehicleRows rows;
    
printf("\nStatic Vehicle Amount:%d",StaticVehicleRows);
    for (new 
0StaticVehicleRows++)
    {
        
StaticCars[i][sMysqlId] = cache_get_field_content_int(i"StaticMysqlId");
          
StaticCars[StaticCars[i][sMysqlId]][scX] = cache_get_field_content_float(i"StaticVehicleX");
        
StaticCars[StaticCars[i][sMysqlId]][scY] = cache_get_field_content_float(i"StaticVehicleY");
        
StaticCars[StaticCars[i][sMysqlId]][scZ] = cache_get_field_content_float(i"StaticVehicleZ");
        
StaticCars[StaticCars[i][sMysqlId]][scA] = cache_get_field_content_float(i"StaticAngle");
        
StaticCars[StaticCars[i][sMysqlId]][sColor1] = cache_get_field_content_int(i"StaticColor1");
        
StaticCars[StaticCars[i][sMysqlId]][sColor2] = cache_get_field_content_int(i"StaticColor2");
        
StaticCars[StaticCars[i][sMysqlId]][sCclass] = cache_get_field_content_int(i"StaticClass");
        
StaticCars[StaticCars[i][sMysqlId]][sLock] = cache_get_field_content_int(i"StaticLock");
        
StaticCars[StaticCars[i][sMysqlId]][sEngine] = cache_get_field_content_int(i"StaticEngine");
        
StaticCars[StaticCars[i][sMysqlId]][sLights] = cache_get_field_content_int(i"StaticLights");
        
StaticCars[StaticCars[i][sMysqlId]][sDamage] = cache_get_field_content_float(i"StaticDamage");
        
StaticCars[StaticCars[i][sMysqlId]][sFuel] = cache_get_field_content_int(i"StaticFuel");
        
StaticCars[StaticCars[i][sMysqlId]][sMiles] = cache_get_field_content_float(i"StaticMiles");
        
StaticCars[StaticCars[i][sMysqlId]][sKmh] = cache_get_field_content_float(i"StaticKMH");
        
StaticCars[StaticCars[i][sMysqlId]][sKnots] = cache_get_field_content_float(i"StaticKnots");
         
StaticCars[StaticCars[i][sMysqlId]][sSlots] = cache_get_field_content_int(i"StaticSlots");
        
cache_get_field_content(i"StaticStorage"StaticCars[StaticCars[i][sMysqlId]][sStorage], dbHandle,128);
        
StaticCars[StaticCars[i][sMysqlId]][sModel] = cache_get_field_content_int(i"StaticModel");
        
StaticCars[StaticCars[i][sMysqlId]][staticVehicleId] = AddStaticVehicleEx(StaticCars[StaticCars[i][sMysqlId]][sModel],StaticCars[StaticCars[i][sMysqlId]][scX],StaticCars[StaticCars[i][sMysqlId]][scY],StaticCars[StaticCars[i][sMysqlId]][scZ],StaticCars[StaticCars[i][sMysqlId]][scA],StaticCars[StaticCars[i][sMysqlId]][sColor1],StaticCars[StaticCars[i][sMysqlId]][sColor2],-1,0);
        return 
1;

PHP код:
forward SaveStaticVehicles(vehicleid);
public 
SaveStaticVehicles(vehicleid)
{
    
format(Querysizeof(Query), "UPDATE staticvehicles SET StaticVehicleId = %d, StaticEngine = %d, StaticLights = %d, StaticMiles = '%.1f', StaticKMH = '%.1f', StaticKnots = '%.1f' WHERE StaticMysqlId = %d",
    
vehicleid,
    
StaticCars[vehicleid][sEngine],
    
StaticCars[vehicleid][sLights],
    
StaticCars[vehicleid][sMiles],
    
StaticCars[vehicleid][sKmh],
    
StaticCars[vehicleid][sKnots],
    
StaticCars[vehicleid][sMysqlId]);
    
mysql_query(dbHandleQueryfalse);
    
printf("%d",vehicleid);
    return 
1;

Reply
#2

No response, i guess i'll stick to trying to troubleshoot it myself.
Reply
#3

Did you add "AUTO_INCREMENT" to database?
Reply
#4

Quote:
Originally Posted by Stev
Посмотреть сообщение
Did you add "AUTO_INCREMENT" to database?
Yes, StaticMysqlId Is my AUTO_INCREMENT.

It seems to set, vehicleid 1 to vehicleid 2, while vehicleid 1 still remains in the server.

If i don't add +1 to vehicleids in savestaticvehicles, then it starts the id's off at 0.

This is the loop that saves the vehicles when the server restarts.

PHP код:
    for(new 0StaticVehicleRowsv++)
    {
        
SaveStaticVehicles(v);
    } 
if i change the 0 to 1, then i get 2 number 1 vehicleid's
Reply
#5

So no one knows why it would be causing my vehicleid's to be messed up, cause i can't either. It's weird tbh with you, like vehicleid 104 and another id don't seem to work either. I use this to get the vehicleinfo and vehicleid 1 and 10 return blankinfo.

PHP код:
forward GetCarInfo(playerid,vehicleid);
public 
GetCarInfo(playerid,vehicleid)
{
    new 
string[400];
    
format(stringsizeof(string), "VehicleId: %d\nLocationX: %.1f\nLocationY: %.1f\nLoctionZ: %.1f\nAngle %.1f\nColor1: %d\nColor2 %d\nVehicle Class: %d\nVehicle Lock: %d\nVehicle Engine: %d\nVehicle Lights: %d\nVehicle Damage: %f\nVehicle Fuel %d\nVehicle Miles %.1f\nVehicle Kilometers %.1f\nVehicle Knots %.1f\nVehicle Slots: %d\nVehicle Storage: %s\nVehicle Model: %d\n",
    
StaticCars[vehicleid][staticVehicleId],
    
StaticCars[vehicleid][scX],
    
StaticCars[vehicleid][scY],
    
StaticCars[vehicleid][scZ],
    
StaticCars[vehicleid][scA],
    
StaticCars[vehicleid][sColor1],
    
StaticCars[vehicleid][sColor2],
    
StaticCars[vehicleid][sCclass],
    
StaticCars[vehicleid][sLock],
    
StaticCars[vehicleid][sEngine],
    
StaticCars[vehicleid][sLights],
    
StaticCars[vehicleid][sDamage],
    
StaticCars[vehicleid][sFuel],
    
StaticCars[vehicleid][sMiles],
    
StaticCars[vehicleid][sKmh],
    
StaticCars[vehicleid][sKnots],
    
StaticCars[vehicleid][sSlots],
    
StaticCars[vehicleid][sStorage],
    
StaticCars[vehicleid][sModel]);
    
ShowPlayerDialog(playerid,12,DIALOG_STYLE_LIST,"CarInfo",string,"Edit","Close");
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)