for(new i; i < MAX_VEHICLES; i++)
{
new a = DB::Fetch("Vehicle", _, _, _, "`ID` = '%d'", i);
//printf("fetch; %i - %i - %i", fetch_rows_count(), i, a);
if (fetch_rows_count() > 0)
{
vStats[i][vSQLIB] = fetch_row_id();
vStats[i][vID] = fetch_int("VehicleID");
vStats[i][vX] = fetch_float("x");
vStats[i][vY] = fetch_float("y");
vStats[i][vZ] = fetch_float("z");
vStats[i][vColor1] = fetch_int("Color1");
vStats[i][vColor2] = fetch_int("Color2");
vStats[i][vHealth] = fetch_float("Health");
vStats[i][vModel] = fetch_int("Model");
vStats[i][vRespawn] = fetch_int("Respawn");
vStats[i][vZr] = fetch_float("Angle");
fetch_string("Plate", vStats[i][vPlate], 20);
new vehicleid = CreateVehicle(vStats[vehicleid][vModel], vStats[vehicleid][vX], vStats[vehicleid][vY], vStats[vehicleid][vZ], vStats[vehicleid][vZr], vStats[vehicleid][vColor1], vStats[vehicleid][vColor2], vStats[vehicleid][vRespawn]);
SetVehicleHealth(vehicleid, vStats[vehicleid][vHealth]);
SetVehicleNumberPlate(vehicleid, vStats[vehicleid][vPlate]);
}
}
new cache = DB::Fetch("Vehicle");
do
{
// retrieve data and create vehicle..
}
while (fetch_next_row(cache));
Something like this would work I suppose:
pawn Код:
|
I didn't, sorry.
This is working but can you explain the code.. I mean, how this work? Goddamn, MySQL is so hard to understand. >.< |
DB::Fetch("Vehicles");
DB::Fetch("Vehicles");
fetch_row_id(); // this is the 1st row
fetch_int("data");
fetch_next_row(); // skipped to next row
fetch_row_id(); // this will now return 2 i.e. 2nd row
fetch_int("data");
fetcher_close();
DB::Fetch("Vehicles", MAX_VEHICLES); // since we have a limit on vehicles
do
{
// fetch data here
}
while (fetch_next_row());
fetcher_close();
CMD:garer(playerid)
{
if(pAccount[playerid][pAdmin] < SADMIN) return ErrorMsg(playerid, _, false);
new vehicleid = GetPlayerVehicleID(playerid),
Float:x,
Float:y,
Float:z;
if(vehicleid == INVALID_VEHICLE_ID) return ErrorMsg(playerid, "Vous devez кtre dans un vйhicule.");
GetVehiclePos(vehicleid, x, y, z);
DB::Fetch("Vehicle", _, _, _, "`ID` = '%d'", vehicleid);
if (fetch_rows_count() > 0)
{
AdminMessage(playerid, "Changement des stats du vйhicule ID: %i.", vehicleid);
DB::Update("ID", vStats[vehicleid][vSQLIB], 3,
"x", FLOAT, x,
"y", FLOAT, y,
"z", FLOAT, z);
}
else
{
vStats[vehicleid][vSQLIB] = fetch_row_id();
DB::CreateRow("Vehicle",
"ID", INTEGER, vStats[vehicleid][vSQLIB],
"Model", INTEGER, GetVehicleModel(vehicleid),
"VehicleID", INTEGER, vehicleid);
AdminMessage(playerid, "Vйhicule ID:%i en cours de crйation ...", vehicleid);
AdminMessage(playerid, "Enregistrement des donnйes ...");
vStats[vehicleid][vSQLIB] = fetch_row_id();
vStats[vehicleid][vID] = vehicleid;
vStats[vehicleid][vX] = x;
vStats[vehicleid][vY] = y;
vStats[vehicleid][vZ] = z;
vStats[vehicleid][vColor1] = random(150);
vStats[vehicleid][vColor2] = random(150);
vStats[vehicleid][vHealth] = 1500.0;
vStats[vehicleid][vModel] = GetVehicleModel(vehicleid);
vStats[vehicleid][vRespawn] = 1800;
format(vStats[vehicleid][vPlate], 10, GetARandomPlate());
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.");
}
fetcher_close();
return 1;
}
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 код:
|
GetVehicleArrayID(vehicleid)
{
for (new i; i < MAX_VEHICLES; i++)
{
if (vStats[i][vID] == vehiclid)
return i;
}
return -1;
}
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;
}
Since SAMP has a limit on vehicles, you cannot use vehicle ids as array's indexes as long as you don't keep the vehicle when the owner disconnects.
DB::Fetch("Vehicle", 1, _, _, "`x` = %f, `y` = %f, `z` = %f", x, y, z);