public OnVehicleMod(playerid, vehicleid, componentid)
{
// 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 i; i < 14; i++)
{
if(GetVehicleComponentType(componentid) == i)
{
AVehicleData[vehicleid][Components][i] = componentid;
}
}
if(AVehicleData[vehicleid][Owned] == 1)
{
new query[164];
mysql_format(g_SQL, query, sizeof(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_SQL, query, "","");
}
return 1;
}
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? ![]() |
// This function returns "true" is the given player is the leader of the convoy
stock Convoy_IsLeader(playerid, Convoy)
{
// 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)
}
CMD:stopwork(playerid, params[])
{
if (APlayerData[playerid][JobStarted] == true)
{
switch (APlayerData[playerid][PlayerClass])
{
case ClassTruckDriver: Trucker_EndJob(playerid); // Stop any trucker job
case ClassBusDriver: BusDriver_EndJob(playerid); // Stop any busdriver job
case ClassPilot: Pilot_EndJob(playerid); // Stop any pilot job
case ClassMafia: Mafia_EndJob(playerid); // Stop any mafia job
case ClassCourier: Courier_EndJob(playerid);
case ClassRoadWorker: Roadworker_EndJob(playerid);
case ClassAmb: Amb_EndJob(playerid); // Stop any ice job
case ClassPboy: Pboy_EndJob(playerid);
default: SendClientMessage(playerid, 0xFF0000FF, "Clasa ta nu are work pentru al putea opri.");
}
GameTextForPlayer(playerid, "~w~Ai ~r~pierdut~w~ workul.Ai platit ~y~$5000", 5000, 4);
RewardPlayer(playerid, -5000, 0);
new Convoy = APlayerData[playerid][ConvoyID];
if(Convoy_IsLeader(playerid,Convoy))
Convoy_Cancel(Convoy);
}
return 1;
}
new Convoy = APlayerData[playerid][ConvoyID];
if(AConvoys[Convoy][Members][0] == playerid)
Convoy_Cancel(Convoy);
// 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) }
Код:
// 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) } |
[22:29:07] APlayerData[playerid][InConvoy]=1
[22:29:07] AConvoys[Convoy][Members][0]=0
if(... (AConvoys[Convoy][Members][0] = playerid))
// This callback gets called whenever a player mods his vehicle
public OnVehicleMod(playerid, vehicleid, componentid)
{
// Setup local variables
new componenttype, query[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 0: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET Spoiler = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][0], AVehicleData[vehicleid][SQLID]);
case 1: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET Hood = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][1], AVehicleData[vehicleid][SQLID]);
case 2: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET Roof = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][2], AVehicleData[vehicleid][SQLID]);
case 3: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET Sideskirt = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][3], AVehicleData[vehicleid][SQLID]);
case 4: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET Lamps = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][4], AVehicleData[vehicleid][SQLID]);
case 5: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET Nitro = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][5], AVehicleData[vehicleid][SQLID]);
case 6: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET Exhaust = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][6], AVehicleData[vehicleid][SQLID]);
case 7: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET Wheels = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][7], AVehicleData[vehicleid][SQLID]);
case 8: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET Stereo = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][8], AVehicleData[vehicleid][SQLID]);
case 9: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET Hydraulics = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][9], AVehicleData[vehicleid][SQLID]);
case 10: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET FrontBumper = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][10], AVehicleData[vehicleid][SQLID]);
case 11: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET RearBumper = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][11], AVehicleData[vehicleid][SQLID]);
case 12: mysql_format(SQL_db, query, sizeof(query), "UPDATE housevehicles SET VentRight = '%i' WHERE ID = '%i'", AVehicleData[vehicleid][Components][12], AVehicleData[vehicleid][SQLID]);
case 13: mysql_format(SQL_db, query, sizeof(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_db, query, "", "");
}
return 1;
}
// 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;
}
PHP код:
|
Directly taken from my new gamemode:
PHP код:
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 код:
No need to dig in a huge log-file to figure out if some query failed execution. |
for(new i; i < 14; i++)
{
if(GetVehicleComponentType(componentid) == i)
{
AVehicleData[vehicleid][Components][i] = componentid;
}
}
// Get the componenttype of the component
componenttype = GetVehicleComponentType(componentid);
// Store the component in the AVehicleData array
AVehicleData[vehicleid][Components][componenttype] = componentid;
// This function is used to give (or take) money to/from the player
Player_GiveMoney(playerid, amount)
{
// 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(playerid, APlayerData[playerid][Money]);
// Update money for this player in the player's account in MySQL
mysql_format(SQL_db, query, sizeof(query), "UPDATE playerdata SET Money = '%i' WHERE UserID = '%i'", APlayerData[playerid][Money], APlayerData[playerid][UserID]);
mysql_tquery(SQL_db, query, "", "");
return 1;
}
new query[164];
new query[400];