08.07.2015, 20:26
So i've made this vehicle system using MySQL R38. So far it works a little bit fine but not perfectly functions.
I have 10 vehicles per player so instead of sending loads of queries to save all 10 vehicles' data at once, i thought of sending small quries whenever the vehicle data make changes.
This is my code that updates all the components for the vehicle
It works but doesn't fully functions. Sometime one or two of the components refuse to update in the database but soemtime same component gets updated. Anyone know what's the problem here? This is the only issue i have with this system. Help please.
I have 10 vehicles per player so instead of sending loads of queries to save all 10 vehicles' data at once, i thought of sending small quries whenever the vehicle data make changes.
This is my code that updates all the components for the vehicle
pawn Код:
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
if (vInfo[vehicleid][v_Owned] == 1)
{
new query[128];
if ((vInfo[vehicleid][v_Color1] != color1) || (vInfo[vehicleid][v_Color2] != color2))
{
RewardPlayer(playerid, -2000, 0);
}
vInfo[vehicleid][v_Color1] = color1;
vInfo[vehicleid][v_Color2] = color2;
if (color1 == 0)
{
vInfo[vehicleid][v_Paint] = 0;
}
mysql_format(mysql, query, sizeof(query), "UPDATE `vehicles` SET `c1`='%d',`c2`='%d' WHERE `id`='%d'",vInfo[vehicleid][v_Color1], vInfo[vehicleid][v_Color2], vInfo[vehicleid][v_ID]);
mysql_query(mysql, query, false);
mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET `money`='%d' WHERE `id`='%d'", pInfo[playerid][p_Money], pInfo[playerid][p_ID]);
mysql_query(mysql, query, false);
}
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
pInfo[playerid][p_Money] -= g_VehicleModPrices[componentid - 1000];
vInfo[vehicleid][v_Components][GetVehicleComponentType(componentid)] = componentid;
if (vInfo[vehicleid][v_Owned] == 1)
{
new
query[128],
mods[100]
;
for(new i; i < 14; i++)
{
format(mods, sizeof(mods)"%s%i%s", mods, GetVehicleComponentInSlot(vehicleid, i), ((i != (14 - 1)) ? (":") : ("")));
}
mysql_format(mysql, query, sizeof(query), "UPDATE `vehicles` SET `mods`='%e' WHERE `id`='%d'",mods,vInfo[vehicleid][v_ID]);
mysql_query(mysql, query, false);
mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET `money`='%d' WHERE `id`='%d'",pInfo[playerid][p_Money],pInfo[playerid][p_ID]);
mysql_query(mysql, query, false);
}
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
if (vInfo[vehicleid][v_Owned] == 1)
{
new
query[100];
vInfo[vehicleid][v_Paint] = paintjobid + 1;
mysql_format(mysql, query, sizeof(query), "UPDATE `vehicles` SET `paint`='%d' WHERE `id`='%d'",vInfo[vehicleid][v_Paint],vInfo[vehicleid][v_ID]);
mysql_query(mysql, query, false);
mysql_format(mysql, query, sizeof(query), "UPDATE `users` SET `money`='%d' WHERE `id`='%d'",pInfo[playerid][p_Money],pInfo[playerid][p_ID]);
mysql_query(mysql, query, false);
}
return 1;
}