11.02.2015, 19:14
(
Последний раз редактировалось iOxide; 12.02.2015 в 21:41.
)
Hello,
I've made this to load and save my vehicle system using BlueG's MySQL R38. My question is, is it done efficiently? If no, can someone tell me how can i make it work efficiently? The current system doesn't work properly, like vehicle's spawning coordinates are mixing up with each other and sometimes, vehicle is losing its paindjob. I want to know whats wrong and how to make it work efficiently, thanks.
I've made this to load and save my vehicle system using BlueG's MySQL R38. My question is, is it done efficiently? If no, can someone tell me how can i make it work efficiently? The current system doesn't work properly, like vehicle's spawning coordinates are mixing up with each other and sometimes, vehicle is losing its paindjob. I want to know whats wrong and how to make it work efficiently, thanks.
pawn Код:
//Under OnPlayerDisconect, when they disconnect to save all the owned vehicles. The MAX_VEHICLES_PER_PLAYER is set to 10.
if (houseid != 0)
{
for (new i; i<MAX_VEHICLES_PER_PLAYER; i++)
{
if (gHouseData[houseid][PlayerVehicles][i] != 0)
{
new vid = gHouseData[houseid][PlayerVehicles][i];
Vehicles_Save(vid);
}
}
}
//Saving function
Vehicles_Save(vehicleid)
{
new query[1000], components[100];
for(new i; i < 14; i++)
{
format:components("%s%i%s", components, GetVehicleComponentInSlot(vehicleid, i), ((i != (14 - 1)) ? (":") : ("")));
}
mysql_format(mysql, query, sizeof(query), "%sUPDATE `vehicles` SET `Fuel`='%f',`SpawnX`='%f',`SpawnY`='%f',`SpawnZ`='%f',`SpawnAngle`='%f',`Color1`='%d',`Color2`='%d',`Clamped`='%d',`Paint`='%d',`Components`='%e' WHERE `vDB_ID`='%d'", query,
gVehicleInfo[vehicleid][Fuel], gVehicleInfo[vehicleid][SpawnX], gVehicleInfo[vehicleid][SpawnY], gVehicleInfo[vehicleid][SpawnZ], gVehicleInfo[vehicleid][SpawnRot], gVehicleInfo[vehicleid][Color1],
gVehicleInfo[vehicleid][Color2], gVehicleInfo[vehicleid][Clamped], gVehicleInfo[vehicleid][PaintJob], components, gVehicleInfo[vehicleid][DB_ID]);
mysql_query(mysql, query, false);
}
//Loading function
LoadVehicles()
{
new query[128];
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `vehicles`");
mysql_tquery(mysql, query, "LoadOwnedVehicles", "", "");
}
Function:LoadOwnedVehicles()
{
new rows, fields;
cache_get_data(rows, fields);
if (rows != 0)
{
new db_id, Float:fuel, Float:x, Float:y, Float:z, Float:a, c1, c2;
new clamped, paint, str[100], mods[14], houseid, owner[24], model;
for (new i; i < rows; i++)
{
db_id = cache_get_field_content_int(i, "vDB_ID", mysql);
model = cache_get_field_content_int(i, "Model", mysql);
houseid = cache_get_field_content_int(i, "LinkedHouseID", mysql);
fuel = cache_get_field_content_float(i, "Fuel", mysql);
x = cache_get_field_content_float(i, "SpawnX", mysql);
y = cache_get_field_content_float(i, "SpawnY", mysql);
z = cache_get_field_content_float(i, "SpawnZ", mysql);
a = cache_get_field_content_float(i, "SpawnAngle", mysql);
c1 = cache_get_field_content_int(i, "Color1", mysql);
c2 = cache_get_field_content_int(i, "Color2", mysql);
clamped = cache_get_field_content_int(i, "Clamped", mysql);
paint = cache_get_field_content_int(i, "Paint", mysql);
cache_get_field_content(i, "Owner", owner, mysql, 24);
cache_get_field_content(i, "Components", str, mysql, 100);
sscanf(str, "p<:>a<i>[100]", mods);
new vehicleid = AddOwnedVehicle(houseid, owner, model, paint, mods, x, y, z, a, c1, c2);
gVehicleInfo[vehicleid][DB_ID] = db_id;
gVehicleInfo[vehicleid][Clamped] = clamped;
if (gVehicleInfo[vehicleid][Fuel] == -1)
gVehicleInfo[vehicleid][Fuel] = MAX_FUEL;
else
gVehicleInfo[vehicleid][Fuel] = fuel;
}
}
else return 0;
return 1;
}