Vehicle tuning not saving[MySQL]
#1

My vehicle tuning is not saving, why?
PHP код:
public OnVehicleMod(playeridvehicleidcomponentid)
{
    
// When the player changes a component of his vehicle, reduce the price of the component from the player's money
    
APlayerData[playerid][PlayerMoney] = APlayerData[playerid][PlayerMoney] - AVehicleModPrices[componentid 1000];
    
RewardPlayer(playerid,APlayerData[playerid][PlayerMoney],0);
    for(new 
i14i++) 
    {
        if(
GetVehicleComponentType(componentid) == i
        {
            
AVehicleData[vehicleid][Components][i] = componentid;
        }
    }
    if(
AVehicleData[vehicleid][Owned] == 1)
    {
        new 
query[164];
        
mysql_format(g_SQLquerysizeof(query), "UPDATE `vehicles` SET `VehicleSpoiler` = %i,`VehicleHood` = %i,`VehicleRoof` = %i,`VehicleSideSkirt` = %i,`VehicleLamps` = %i,`VehicleNitro` = %i,`VehicleExaust` = %i,`VehicleWheels` = %i,`VehicleStereo` = %i,`VehicleHydraulics` = %i, `VehicleFrontBumper` = %i,`VehicleRearBumper` = %i, `VehicleVentRigt` = %i,`VehicleVentLeft` = %i WHERE `ID` = %i",AVehicleData[vehicleid][Components][0],AVehicleData[vehicleid][Components][1],AVehicleData[vehicleid][Components][2],AVehicleData[vehicleid][Components][3],AVehicleData[vehicleid][Components][4],AVehicleData[vehicleid][Components][5],AVehicleData[vehicleid][Components][6],AVehicleData[vehicleid][Components][7],AVehicleData[vehicleid][Components][8],AVehicleData[vehicleid][Components][9],AVehicleData[vehicleid][Components][10],AVehicleData[vehicleid][Components][11],AVehicleData[vehicleid][Components][12],AVehicleData[vehicleid][Components][13],AVehicleData[vehicleid][IDD]);
        
mysql_tquery(g_SQLquery"","");
    }
    return 
1;

Reply
#2

Hello.

Do you get some information in the mysql.log?
If so can you show us this?
If not: Can you print this query and share this print with us?
Reply
#3

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello.

Do you get some information in the mysql.log?
If so can you show us this?
If not: Can you print this query and share this print with us?
Well aparently the query was too small and 2 writing mistakes......I was to blind to see those.....

But i came wit another problem , just to not open another thread....

I have this function:
PHP код:
// This function returns "true" is the given player is the leader of the convoy
stock Convoy_IsLeader(playeridConvoy)
{
    
// Check if the player is part of a convoy
    
if ((APlayerData[playerid][InConvoy] == true) && (AConvoys[Convoy][Members][0] = playerid))
        return 
true// Player is in a convoy AND he's the leader of it
    
else
        return 
false// Player is a member of the convoy (or not in the same convoy)

And i try to call it here:
PHP код:
CMD:stopwork(playeridparams[])
{
    if (
APlayerData[playerid][JobStarted] == true)
    {
        switch (
APlayerData[playerid][PlayerClass])
        {
            case 
ClassTruckDriverTrucker_EndJob(playerid); // Stop any trucker job
            
case ClassBusDriverBusDriver_EndJob(playerid); // Stop any busdriver job
            
case ClassPilotPilot_EndJob(playerid); // Stop any pilot job
            
case ClassMafiaMafia_EndJob(playerid); // Stop any mafia job
            
case ClassCourierCourier_EndJob(playerid);
            case 
ClassRoadWorkerRoadworker_EndJob(playerid);
            case 
ClassAmbAmb_EndJob(playerid); // Stop any ice job
            
case ClassPboyPboy_EndJob(playerid);
            default: 
SendClientMessage(playerid0xFF0000FF"Clasa ta nu are work pentru al putea opri.");
        }
        
GameTextForPlayer(playerid"~w~Ai ~r~pierdut~w~ workul.Ai platit ~y~$5000"50004);
        
RewardPlayer(playerid, -50000);
        new 
Convoy APlayerData[playerid][ConvoyID];
        if(
Convoy_IsLeader(playerid,Convoy))
            
Convoy_Cancel(Convoy);
    }
    return 
1;

But it's not called, but the Convoy id is corect , it can't be called at all

Edit:
If i use like this:
PHP код:
new Convoy APlayerData[playerid][ConvoyID];
       if(
AConvoys[Convoy][Members][0] == playerid)
              
Convoy_Cancel(Convoy); 
Its working
Reply
#4

Код:
// This function returns "true" is the given player is the leader of the convoy
stock Convoy_IsLeader(playerid, Convoy)
{
	printf("APlayerData[playerid][InConvoy]=%i",APlayerData[playerid][InConvoy]);
	printf("AConvoys[Convoy][Members][0]=%i",AConvoys[Convoy][Members][0]);
    // Check if the player is part of a convoy
    if ((APlayerData[playerid][InConvoy] == true) && (AConvoys[Convoy][Members][0] = playerid))
        return true; // Player is in a convoy AND he's the leader of it
    else
        return false; // Player is a member of the convoy (or not in the same convoy)
}
Check what the server log prints.
Reply
#5

Quote:
Originally Posted by Unte99
Посмотреть сообщение
Код:
// This function returns "true" is the given player is the leader of the convoy
stock Convoy_IsLeader(playerid, Convoy)
{
	printf("APlayerData[playerid][InConvoy]=%i",APlayerData[playerid][InConvoy]);
	printf("AConvoys[Convoy][Members][0]=%i",AConvoys[Convoy][Members][0]);
    // Check if the player is part of a convoy
    if ((APlayerData[playerid][InConvoy] == true) && (AConvoys[Convoy][Members][0] = playerid))
        return true; // Player is in a convoy AND he's the leader of it
    else
        return false; // Player is a member of the convoy (or not in the same convoy)
}
Check what the server log prints.
PHP код:
[22:29:07APlayerData[playerid][InConvoy]=1
[22:29:07AConvoys[Convoy][Members][0]=
Its corect, playerid = 0 , and InConvoy = true
Nothing wrong
Reply
#6

PHP код:
if(... (AConvoys[Convoy][Members][0] = playerid)) 
Uhm yeah, that's supposed to be ==. The extra set of brackets suppress the warning that you would normally get (unintended assignment).
Reply
#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
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
PHP код:
if(... (AConvoys[Convoy][Members][0] = playerid)) 
Uhm yeah, that's supposed to be ==. The extra set of brackets suppress the warning that you would normally get (unintended assignment).
Didn't see that actually

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
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.
Well i don't thinked about make that queries like that...That's something that i will do more often and try to think about make smaller queries...And of course use that callback


Thanks guys for help me and teach me good things
So wow,much apreciate
Reply
#9

PHP код:
for(new i14i++) 
{
    if(
GetVehicleComponentType(componentid) == i
    {
        
AVehicleData[vehicleid][Components][i] = componentid;
    }

Also, your for-loop wasn't required.
See my code to find out in which array index the componentid will be stored:
PHP код:
// Get the componenttype of the component
componenttype GetVehicleComponentType(componentid);
// Store the component in the AVehicleData array
AVehicleData[vehicleid][Components][componenttype] = componentid
No loop required

I've used a custom function to give a player money:
PHP код:
// This function is used to give (or take) money to/from the player
Player_GiveMoney(playeridamount)
{
    
// Setup local variables
    
new query[128];
    
// Add the given money to the player's account
    
APlayerData[playerid][Money] = APlayerData[playerid][Money] + amount;
    
// Also update the client immediately instead of waiting for the GlobalTimer1000 to update it
    
ResetPlayerMoney(playerid);
    
GivePlayerMoney(playeridAPlayerData[playerid][Money]);
    
// Update money for this player in the player's account in MySQL
    
mysql_format(SQL_dbquerysizeof(query), "UPDATE playerdata SET Money = '%i' WHERE UserID = '%i'"APlayerData[playerid][Money], APlayerData[playerid][UserID]);
    
mysql_tquery(SQL_dbquery"""");
    return 
1;

In case you wondered what it did.

You can make many little functions like this one to update stuff (change the variable and the database-value at the same time).
This also guarantees you have a minimal data-loss when your server suddenly crashes or something.
Reply
#10

PHP код:
new query[164]; 
Replace with
PHP код:
new query[400]; 
400 is approximate, you must calculate the size of that query.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)