Sqlite Vehicle System Bugging
#1

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.
Reply
#2

Still haven't found a solution, anyone?
Reply
#3

What do you have in DeleteVehicle?
Reply
#4

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)