23.09.2010, 20:38
(
Последний раз редактировалось Norn; 23.09.2010 в 21:13.
)
So basically, I load my vehicles from sqlite and store the sqlite id in a variable called VehicleSQLID which I can later use to return the sqlite id depending on the vehicle id:
Basically it's always the one with the highest ID that's returning INVALID_VEHICLE_ID, here's my loading function:
Delete vehicle then deletes a random vehicle and not the one I'm on and returns "UNKNOWN COMMAND":
Coded most of this when I hadn't slept in days so there's probably a mistake on my side but I can't seem to spot it.
Basically it's always the one with the highest ID that's returning INVALID_VEHICLE_ID, here's my loading function:
pawn Код:
public LoadVehicles()
{
new DBResult:qresult, count = 0, value[128];
qresult = db_query(database, "SELECT * FROM `Vehicle`");
count = db_num_rows(qresult);
if(count == 0)
{
return print("[I:] No vehicles exist to load.");
}
for(new a=0;a<count;a++)
{
if(count >= 1 && count <= MAX_VEHICLES)
{
db_get_field_assoc(qresult, "x", value, 20); Vehicle[a][vX] = floatstr(value);
db_get_field_assoc(qresult, "y", value, 20); Vehicle[a][vY] = floatstr(value);
db_get_field_assoc(qresult, "z", value, 20); Vehicle[a][vZ] = floatstr(value);
db_get_field_assoc(qresult, "model", value, 5); Vehicle[a][vModel] = strval(value);
db_get_field_assoc(qresult, "color1", value, 5); Vehicle[a][vColor1] = strval(value);
db_get_field_assoc(qresult, "color2", value, 5); Vehicle[a][vColor2] = strval(value);
db_get_field_assoc(qresult, "angle", value, 20); Vehicle[a][vAngle] = floatstr(value);
Vehicle[a][vID] = CreateVehicle(Vehicle[a][vModel], Vehicle[a][vX], Vehicle[a][vY], Vehicle[a][vZ], Vehicle[a][vAngle], Vehicle[a][vColor1], Vehicle[a][vColor2], -1);
db_get_field_assoc(qresult, "id", value, 20); VehicleSQLID[Vehicle[a][vID]] = strval(value);
VEHICLE_COUNT++;
printf("%d (%d) loaded.", VehicleSQLID[Vehicle[a][vID]], Vehicle[a][vID]);
db_next_row(qresult);
}
}
db_free_result(qresult);
return true;
}
pawn Код:
COMMAND:vehicle_delete(playerid, params[])
{
if(IsPlayerInAnyVehicle(playerid))
{
DeleteVehicle(GetPlayerVehicleID(playerid));
}
return 1;
}
COMMAND:info(playerid, params[])
{
new string[128];
if(IsPlayerInAnyVehicle(playerid))
{
new vehicleid = GetPlayerVehicleID(playerid);
format(string,sizeof(string), "Vehicle ID: %d, Sqlite ID: %d.", vehicleid, VehicleSQLID[Vehicle[vehicleid][vID]]);
SendClientMessage(playerid, COLOR_YELLOW, string);
}
return 1;
}