16.09.2016, 21:32
(
Последний раз редактировалось Gammix; 17.09.2016 в 04:17.
Причина: There was a mistake in DB::Update
)
Quote:
Alright. I'll keep your post in bookmark. Thanks.
I seem barely but.. I'm trying to do my best. x) This code doesn't work. PHP код:
|
Anyways, here is how you should detect the ID:
PHP код:
GetVehicleArrayID(vehicleid)
{
for (new i; i < MAX_VEHICLES; i++)
{
if (vStats[i][vID] == vehiclid)
return i;
}
return -1;
}
PHP код:
CMD:garer(playerid)
{
if(pAccount[playerid][pAdmin] < SADMIN) return ErrorMsg(playerid, _, false);
new vehicleid = GetPlayerVehicleID(playerid);
if(vehicleid == INVALID_VEHICLE_ID) return ErrorMsg(playerid, "Vous devez кtre dans un vйhicule.");
new Float: x, Float: y, Float: z;
GetVehiclePos(vehicleid, x, y, z);
new idx = GetVehicleArrayID(vehicleid);
if (idx != -1)
{
AdminMessage(playerid, "Changement des stats du vйhicule ID: %i.", vehicleid);
DB::Update("Vehicle", vStats[idx][vSQLIB], 1,
"x", FLOAT, x,
"y", FLOAT, y,
"z", FLOAT, z);
return 1;
}
for (new i; i < MAX_VEHICLES; i++)
{
if (vStats[vehicleid][vSQLIB] == 0)
{
idx = i;
break;
}
}
if (idx == -1)
{
// for some reason the array isn't empty
// make sure you set the "vSQLIB" to 0 when the owner disconnects or vehicle is destroyed
return 1;
}
AdminMessage(playerid, "Vйhicule ID:%i en cours de crйation ...", vehicleid);
AdminMessage(playerid, "Enregistrement des donnйes ...");
vStats[idx][vID] = vehicleid;
vStats[idx][vX] = x;
vStats[idx][vY] = y;
vStats[idx][vZ] = z;
vStats[idx][vColor1] = random(150);
vStats[idx][vColor2] = random(150);
vStats[idx][vHealth] = 1500.0;
vStats[idx][vModel] = GetVehicleModel(vehicleid);
vStats[idx][vRespawn] = 1800;
format(vStats[idx][vPlate], 10, GetARandomPlate());
DB::CreateRow("Vehicle",
"x", FLOAT, vStats[idx][vX],
"y", FLOAT, vStats[idx][vY],
"z", FLOAT, vStats[idx][vZ],
"Angle", FLOAT, 90.0,
"color1", INTEGER, vStats[idx][vColor1],
"color2", INTEGER, vStats[idx][vColor2],
"Health", FLOAT, vStats[idx][vHealth],
"Model", INTEGER, vStats[idx][vModel],
"Plate", STRING, vStats[idx][vPlate]
);
DB::Fetch("Vehicle", 1, _, _, "`x` = %f, `y` = %f, `z` = %f", x, y, z);
vStats[idx][vSQLIB] = fetch_row_id();
fetcher_close();
AdminMessage(playerid, "Donnйes enregistrйes. Attributions des nouvelles donйes au vйhicule.");
ChangeVehicleColor(vehicleid, vStats[vehicleid][vColor1], vStats[vehicleid][vColor2]);
RepairVehicle(vehicleid);
SetVehicleHealth(vehicleid, vStats[vehicleid][vHealth]);
SaveVehicleStats(vehicleid);
AdminMessage(playerid, "Attributions terminйes.");
return 1;
}