Vehicle tuning not saving[MySQL]
#7

Directly taken from my new gamemode:
PHP код:
// This callback gets called whenever a player mods his vehicle
public OnVehicleMod(playeridvehicleidcomponentid)
{
    
// Setup local variables
    
new componenttypequery[100];
    
// Get the componenttype of the component
    
componenttype GetVehicleComponentType(componentid);
    
// Let the player pay for applying the component to his vehicle
    
Player_GiveMoney(playerid, -AVehicleModPrices[componentid 1000]);
    
// Store the component in the AVehicleData array
    
AVehicleData[vehicleid][Components][componenttype] = componentid;
    
// If the vehicletype is a house-vehicle, save the component to the database
    
if (AVehicleData[vehicleid][VehicleType] == VEHICLETYPE_HOUSE)
    {
        
// Construct the query based on the componenttype
        
switch (componenttype)
        {
            case 
0mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET Spoiler = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][0], AVehicleData[vehicleid][SQLID]);
            case 
1mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET Hood = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][1], AVehicleData[vehicleid][SQLID]);
            case 
2mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET Roof = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][2], AVehicleData[vehicleid][SQLID]);
            case 
3mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET Sideskirt = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][3], AVehicleData[vehicleid][SQLID]);
            case 
4mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET Lamps = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][4], AVehicleData[vehicleid][SQLID]);
            case 
5mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET Nitro = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][5], AVehicleData[vehicleid][SQLID]);
            case 
6mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET Exhaust = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][6], AVehicleData[vehicleid][SQLID]);
            case 
7mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET Wheels = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][7], AVehicleData[vehicleid][SQLID]);
            case 
8mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET Stereo = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][8], AVehicleData[vehicleid][SQLID]);
            case 
9mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET Hydraulics = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][9], AVehicleData[vehicleid][SQLID]);
            case 
10mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET FrontBumper = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][10], AVehicleData[vehicleid][SQLID]);
            case 
11mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET RearBumper = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][11], AVehicleData[vehicleid][SQLID]);
            case 
12mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET VentRight = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][12], AVehicleData[vehicleid][SQLID]);
            case 
13mysql_format(SQL_dbquerysizeof(query), "UPDATE housevehicles SET VentLeft = '%i' WHERE ID = '%i'"AVehicleData[vehicleid][Components][13], AVehicleData[vehicleid][SQLID]);
        }
        
// Execute the query to save the applied component for the vehicle
        
mysql_tquery(SQL_dbquery"""");
    }
    return 
1;

This code uses much smaller queries.
The callback is called with every modification done to just one component, why update them all?
If you tune a vehicle completely, you would send 14 queries where every value is updated again 14 times in a row, where only 1 value changes.

Smaller queries = smaller problems = faster script = less stress on your MySQL server.

Also, place this code in your gamemode as well:
PHP код:
// This will print the query and all related data to the server's console in case there is an error, useful for debugging
public OnQueryError(errorid, const error[], const callback[], const query[], MySQL:handle)
{
    
printf(" ");
    
printf("[ERROR MYSQL]");
    
printf("Error id: %i"errorid);
    
printf("Error message: %s"error);
    
printf("Query: %s"query);
    
printf("Callback: %s"callback);
    
printf(" ");
    return 
1;

If an error occurs with a query, this code will print it directly to the server console.
No need to dig in a huge log-file to figure out if some query failed execution.
Reply


Messages In This Thread
Vehicle tuning not saving[MySQL] - by Banditul18 - 21.02.2017, 17:05
Re: Vehicle tuning not saving[MySQL] - by Mencent - 21.02.2017, 17:55
Re: Vehicle tuning not saving[MySQL] - by Banditul18 - 21.02.2017, 18:54
Re: Vehicle tuning not saving[MySQL] - by Unte99 - 21.02.2017, 19:13
Re: Vehicle tuning not saving[MySQL] - by Banditul18 - 21.02.2017, 19:37
Re: Vehicle tuning not saving[MySQL] - by Vince - 21.02.2017, 20:17
Re: Vehicle tuning not saving[MySQL] - by PowerPC603 - 21.02.2017, 20:44
Re: Vehicle tuning not saving[MySQL] - by Banditul18 - 21.02.2017, 21:30
Re: Vehicle tuning not saving[MySQL] - by PowerPC603 - 21.02.2017, 22:00
Respuesta: Vehicle tuning not saving[MySQL] - by ErickV - 21.02.2017, 22:35

Forum Jump:


Users browsing this thread: 2 Guest(s)