Sqlite Vehicle System Bugging - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Sqlite Vehicle System Bugging (
/showthread.php?tid=178748)
Sqlite Vehicle System Bugging -
Norn - 23.09.2010
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:
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;
}
Delete vehicle then deletes a random vehicle and not the one I'm on and returns "UNKNOWN COMMAND":
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;
}
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.
Re: Sqlite Vehicle System Bugging -
Norn - 01.10.2010
Still haven't found a solution, anyone?
Re: Sqlite Vehicle System Bugging -
Finn - 01.10.2010
What do you have in DeleteVehicle?
Re: Sqlite Vehicle System Bugging -
Norn - 02.10.2010
pawn Код:
public DeleteVehicle(vehicleid)
{
new query[512];
if(VehicleExists(VehicleSQLID[Vehicle[vehicleid][vID]]))
{
format(query, sizeof(query), "DELETE FROM `Vehicle` WHERE `id` = '%d'", VehicleSQLID[Vehicle[vehicleid][vID]]);
db_free_result(db_query(database,query));
DestroyVehicle(Vehicle[vehicleid][vID]);
Vehicle[vehicleid][vX] = 0;
Vehicle[vehicleid][vY] = 0;
Vehicle[vehicleid][vZ] = 0;
Vehicle[vehicleid][vModel] = 0;
Vehicle[vehicleid][vColor1] = 0;
Vehicle[vehicleid][vColor2] = 0;
Vehicle[vehicleid][vAngle] = 0;
Vehicle[vehicleid][vID] = INVALID_VEHICLE_ID;
VehicleSQLID[Vehicle[vehicleid][vID]] = -1;
VEHICLE_COUNT--;
}
return false;
}