Saved Vehicles wont load?
#1

Okay so for some reason the vehicle system my server is running wont load the players cars after the server has been restarted. Im not sure why this is, but it compiles just fine and everything here the code to load and save the players cars

pawn Код:
stock CreatePlayerVehicle(playerid, model, Float:x, Float:y, Float:z, Float:rotation)
{
    new slot = -1;
    for (new i = 1; i < MAX_PLAYER_CARS + 1; i += 1)
    {
        if (PlayerVehicles[playerid][i][pCarOwned] == 0)
        {
            slot = i;
            break;
        }
    }
    if (slot == -1) return 0;
    new vehicleid = CreateVehicle(model, x, y, z, rotation, 1, 1, -1);
    if (vehicleid == INVALID_VEHICLE_ID) return -1;
    PlayerVehicles[playerid][slot][pCarModel] = model;
    PlayerVehicles[playerid][slot][pCarX] = x;
    PlayerVehicles[playerid][slot][pCarY] = y;
    PlayerVehicles[playerid][slot][pCarZ] = z;
    PlayerVehicles[playerid][slot][pCarRot] = rotation;
    PlayerVehicles[playerid][slot][pCarColor1] = 1;
    PlayerVehicles[playerid][slot][pCarColor2] = 1;
    PlayerVehicles[playerid][slot][pCarPaintjob] = -1;
    PlayerVehicles[playerid][slot][pCarMod1] = 0;
    PlayerVehicles[playerid][slot][pCarMod2] = 0;
    PlayerVehicles[playerid][slot][pCarMod3] = 0;
    PlayerVehicles[playerid][slot][pCarMod4] = 0;
    PlayerVehicles[playerid][slot][pCarMod5] = 0;
    PlayerVehicles[playerid][slot][pCarMod6] = 0;
    PlayerVehicles[playerid][slot][pCarMod7] = 0;
    PlayerVehicles[playerid][slot][pCarMod8] = 0;
    PlayerVehicles[playerid][slot][pCarMod9] = 0;
    PlayerVehicles[playerid][slot][pCarMod10] = 0;
    PlayerVehicles[playerid][slot][pCarMod11] = 0;
    PlayerVehicles[playerid][slot][pCarMod12] = 0;
    PlayerVehicles[playerid][slot][pCarMod13] = 0;
    PlayerVehicles[playerid][slot][pCarMod14] = 0;
    PlayerVehicles[playerid][slot][pCarMod15] = 0;
    PlayerVehicles[playerid][slot][pCarMod16] = 0;
    PlayerVehicles[playerid][slot][pCarMod17] = 0;
    PlayerVehicles[playerid][slot][pCarHasLock] = 0;
    PlayerVehicles[playerid][slot][pCarLocked] = 0;
    PlayerVehicles[playerid][slot][pCarTrunkCash] = 0;
    PlayerVehicles[playerid][slot][pCarTrunkGun1] = 0;
    PlayerVehicles[playerid][slot][pCarTrunkGun2] = 0;
    PlayerVehicles[playerid][slot][pCarTrunkGun3] = 0;
    PlayerVehicles[playerid][slot][pCarTrunkGun4] = 0;
    PlayerVehicles[playerid][slot][pCarTrunkAmmo1] = 0;
    PlayerVehicles[playerid][slot][pCarTrunkAmmo2] = 0;
    PlayerVehicles[playerid][slot][pCarTrunkAmmo3] = 0;
    PlayerVehicles[playerid][slot][pCarTrunkAmmo4] = 0;
    PlayerVehicles[playerid][slot][pCarSpawned] = 1;
    PlayerVehicles[playerid][slot][pCarOwned] = 1;
    PlayerVehicles[playerid][slot][pCarID] = vehicleid;
   
    new query[1536], query2[1536];
    format(query, sizeof(query), "INSERT INTO `VEHICLES` ");
    strcat(query, "(`Name`, `Model`, `X`, `Y`, `Z`, `Rot`, `Color1`, `Color2`, `Paintjob`, `Mod1`, `Mod2`, `Mod3`, ");
    strcat(query, "`Mod4`, `Mod5`, `Mod6`, `Mod7`, `Mod8`, `Mod9`, `Mod10`, `Mod11`, `Mod12`, `Mod13`, ");
    strcat(query, "`Mod14`, `Mod15`, `Mod16`, `Mod17`, `HasLock`, `Locked`, `TrunkCash`, ");
    strcat(query, "`TrunkGun1`, `TrunkGun2`, `TrunkGun3`, `TrunkGun4`, `TrunkAmmo1`, `TrunkAmmo2`, `TrunkAmmo3`, ");
    strcat(query, "`TrunkAmmo4`, `Spawned`, `Owned`, `Slot`) ");
   
    format(query2, sizeof(query2), "VALUES('%s', '%d', '%f', '%f', '%f', '%f', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
        DB_Escape(PlayerName(playerid)),
        PlayerVehicles[playerid][slot][pCarModel],
        PlayerVehicles[playerid][slot][pCarX],
        PlayerVehicles[playerid][slot][pCarY],
        PlayerVehicles[playerid][slot][pCarZ],
        PlayerVehicles[playerid][slot][pCarRot],
        PlayerVehicles[playerid][slot][pCarColor1],
        PlayerVehicles[playerid][slot][pCarColor2],
        PlayerVehicles[playerid][slot][pCarPaintjob],
        PlayerVehicles[playerid][slot][pCarMod1],
        PlayerVehicles[playerid][slot][pCarMod2],
        PlayerVehicles[playerid][slot][pCarMod3],
        PlayerVehicles[playerid][slot][pCarMod4],
        PlayerVehicles[playerid][slot][pCarMod5],
        PlayerVehicles[playerid][slot][pCarMod6],
        PlayerVehicles[playerid][slot][pCarMod7],
        PlayerVehicles[playerid][slot][pCarMod8],
        PlayerVehicles[playerid][slot][pCarMod9],
        PlayerVehicles[playerid][slot][pCarMod10],
        PlayerVehicles[playerid][slot][pCarMod11],
        PlayerVehicles[playerid][slot][pCarMod12],
        PlayerVehicles[playerid][slot][pCarMod13],
        PlayerVehicles[playerid][slot][pCarMod14],
        PlayerVehicles[playerid][slot][pCarMod15],
        PlayerVehicles[playerid][slot][pCarMod16],
        PlayerVehicles[playerid][slot][pCarMod17],
        PlayerVehicles[playerid][slot][pCarHasLock],
        PlayerVehicles[playerid][slot][pCarLocked],
        PlayerVehicles[playerid][slot][pCarTrunkCash],
        PlayerVehicles[playerid][slot][pCarTrunkGun1],
        PlayerVehicles[playerid][slot][pCarTrunkGun2],
        PlayerVehicles[playerid][slot][pCarTrunkGun3],
        PlayerVehicles[playerid][slot][pCarTrunkGun4],
        PlayerVehicles[playerid][slot][pCarTrunkAmmo1],
        PlayerVehicles[playerid][slot][pCarTrunkAmmo2],
        PlayerVehicles[playerid][slot][pCarTrunkAmmo3],
        PlayerVehicles[playerid][slot][pCarTrunkAmmo4],
        PlayerVehicles[playerid][slot][pCarSpawned],
        PlayerVehicles[playerid][slot][pCarOwned],
        slot);
    strcat(query, query2);
    db_query(VehicleDatabase[playerid], query);
    SavePlayerVehicle(playerid, slot);
    return 1;
}

stock SavePlayerVehicle(playerid, slot)
{
    if (PlayerVehicles[playerid][slot][pCarOwned])
    {
        new query[1536], query2[1536];
        format(query, sizeof(query), "UPDATE `VEHICLES` SET ");
        format(query2, sizeof(query2), "Name = '%s', Model = '%d', X = '%f', Y = '%f', Z = '%f', Rot = '%f', Color1 = '%d', Color2 = '%d', Paintjob = '%d', Mod1 = '%d', Mod2 = '%d', Mod3 = '%d', ",
            DB_Escape(PlayerName(playerid)),
            PlayerVehicles[playerid][slot][pCarModel],
            PlayerVehicles[playerid][slot][pCarX],
            PlayerVehicles[playerid][slot][pCarY],
            PlayerVehicles[playerid][slot][pCarZ],
            PlayerVehicles[playerid][slot][pCarRot],
            PlayerVehicles[playerid][slot][pCarColor1],
            PlayerVehicles[playerid][slot][pCarColor2],
            PlayerVehicles[playerid][slot][pCarPaintjob],
            PlayerVehicles[playerid][slot][pCarMod1],
            PlayerVehicles[playerid][slot][pCarMod2],
            PlayerVehicles[playerid][slot][pCarMod3]);
        strcat(query, query2);

        format(query2, sizeof(query2), "Mod4 = '%d', Mod5 = '%d', Mod6 = '%d', Mod7 = '%d', Mod8 = '%d', Mod9 = '%d', Mod10 = '%d', Mod11 = '%d', Mod12 = '%d', Mod13 = '%d', Mod14 = '%d', Mod15 = '%d', ",
            PlayerVehicles[playerid][slot][pCarMod4],
            PlayerVehicles[playerid][slot][pCarMod5],
            PlayerVehicles[playerid][slot][pCarMod6],
            PlayerVehicles[playerid][slot][pCarMod7],
            PlayerVehicles[playerid][slot][pCarMod8],
            PlayerVehicles[playerid][slot][pCarMod9],
            PlayerVehicles[playerid][slot][pCarMod10],
            PlayerVehicles[playerid][slot][pCarMod11],
            PlayerVehicles[playerid][slot][pCarMod12],
            PlayerVehicles[playerid][slot][pCarMod13],
            PlayerVehicles[playerid][slot][pCarMod14],
            PlayerVehicles[playerid][slot][pCarMod15]);
        strcat(query, query2);

        format(query2, sizeof(query2), "Mod16 = '%d', Mod17 = '%d', HasLock = '%d', Locked = '%d', TrunkCash = '%d', TrunkGun1 = '%d', TrunkGun2 = '%d', TrunkGun3 = '%d', TrunkGun4 = '%d', TrunkAmmo1 = '%d', TrunkAmmo2 = '%d', TrunkAmmo3 = '%d', ",
            PlayerVehicles[playerid][slot][pCarMod16],
            PlayerVehicles[playerid][slot][pCarMod17],
            PlayerVehicles[playerid][slot][pCarHasLock],
            PlayerVehicles[playerid][slot][pCarLocked],
            PlayerVehicles[playerid][slot][pCarTrunkCash],
            PlayerVehicles[playerid][slot][pCarTrunkGun1],
            PlayerVehicles[playerid][slot][pCarTrunkGun2],
            PlayerVehicles[playerid][slot][pCarTrunkGun3],
            PlayerVehicles[playerid][slot][pCarTrunkGun4],
            PlayerVehicles[playerid][slot][pCarTrunkAmmo1],
            PlayerVehicles[playerid][slot][pCarTrunkAmmo2],
            PlayerVehicles[playerid][slot][pCarTrunkAmmo3]);
        strcat(query, query2);
       
        format(query2, sizeof(query2), "TrunkAmmo4 = '%d', Spawned = '%d', Owned = '%d', Slot = '%d' WHERE Name = '%s' AND Slot = '%d'",
            PlayerVehicles[playerid][slot][pCarTrunkAmmo4],
            PlayerVehicles[playerid][slot][pCarSpawned],
            PlayerVehicles[playerid][slot][pCarOwned],
            slot,
            DB_Escape(PlayerName(playerid)),
            slot);
        strcat(query, query2);
        db_query(VehicleDatabase[playerid], query);
    }
    return 1;
}

stock LoadPlayerVehicles(playerid)
{
    new DBResult:result;
    new query[192], field[64];
    for (new i = 1; i < MAX_PLAYER_CARS + 1; i += 1)
    {
        format(query, sizeof(query), "SELECT * FROM `VEHICLES` WHERE `Name` = '%s' COLLATE NOCASE AND `Slot` = '%d'", PlayerName(playerid), i);
        result = db_query(VehicleDatabase[playerid], query);
        if (db_num_rows(result))
        {
            db_get_field_assoc(result, "Model", field, sizeof(field)); PlayerVehicles[playerid][i][pCarModel] = strval(field);
            db_get_field_assoc(result, "X", field, sizeof(field)); PlayerVehicles[playerid][i][pCarX] = floatstr(field);
            db_get_field_assoc(result, "Y", field, sizeof(field)); PlayerVehicles[playerid][i][pCarY] = floatstr(field);
            db_get_field_assoc(result, "Z", field, sizeof(field)); PlayerVehicles[playerid][i][pCarZ] = floatstr(field);
            db_get_field_assoc(result, "Rot", field, sizeof(field)); PlayerVehicles[playerid][i][pCarRot] = floatstr(field);
            db_get_field_assoc(result, "Color1", field, sizeof(field)); PlayerVehicles[playerid][i][pCarColor1] = strval(field);
            db_get_field_assoc(result, "Color2", field, sizeof(field)); PlayerVehicles[playerid][i][pCarColor2] = strval(field);
            db_get_field_assoc(result, "Paintjob", field, sizeof(field)); PlayerVehicles[playerid][i][pCarPaintjob] = strval(field);
            db_get_field_assoc(result, "Mod1", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod1] = strval(field);
            db_get_field_assoc(result, "Mod2", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod2] = strval(field);
            db_get_field_assoc(result, "Mod3", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod3] = strval(field);
            db_get_field_assoc(result, "Mod4", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod4] = strval(field);
            db_get_field_assoc(result, "Mod5", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod5] = strval(field);
            db_get_field_assoc(result, "Mod6", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod6] = strval(field);
            db_get_field_assoc(result, "Mod7", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod7] = strval(field);
            db_get_field_assoc(result, "Mod8", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod8] = strval(field);
            db_get_field_assoc(result, "Mod9", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod9] = strval(field);
            db_get_field_assoc(result, "Mod10", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod10] = strval(field);
            db_get_field_assoc(result, "Mod11", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod11] = strval(field);
            db_get_field_assoc(result, "Mod12", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod12] = strval(field);
            db_get_field_assoc(result, "Mod13", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod13] = strval(field);
            db_get_field_assoc(result, "Mod14", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod14] = strval(field);
            db_get_field_assoc(result, "Mod15", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod15] = strval(field);
            db_get_field_assoc(result, "Mod16", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod16] = strval(field);
            db_get_field_assoc(result, "Mod17", field, sizeof(field)); PlayerVehicles[playerid][i][pCarMod17] = strval(field);
            db_get_field_assoc(result, "HasLock", field, sizeof(field)); PlayerVehicles[playerid][i][pCarHasLock] = strval(field);
            db_get_field_assoc(result, "Locked", field, sizeof(field)); PlayerVehicles[playerid][i][pCarLocked] = strval(field);
            db_get_field_assoc(result, "TrunkCash", field, sizeof(field)); PlayerVehicles[playerid][i][pCarTrunkCash] = strval(field);
            db_get_field_assoc(result, "TrunkGun1", field, sizeof(field)); PlayerVehicles[playerid][i][pCarTrunkGun1] = strval(field);
            db_get_field_assoc(result, "TrunkGun2", field, sizeof(field)); PlayerVehicles[playerid][i][pCarTrunkGun2] = strval(field);
            db_get_field_assoc(result, "TrunkGun3", field, sizeof(field)); PlayerVehicles[playerid][i][pCarTrunkGun3] = strval(field);
            db_get_field_assoc(result, "TrunkGun4", field, sizeof(field)); PlayerVehicles[playerid][i][pCarTrunkGun4] = strval(field);
            db_get_field_assoc(result, "TrunkAmmo1", field, sizeof(field)); PlayerVehicles[playerid][i][pCarTrunkAmmo1] = strval(field);
            db_get_field_assoc(result, "TrunkAmmo2", field, sizeof(field)); PlayerVehicles[playerid][i][pCarTrunkAmmo2] = strval(field);
            db_get_field_assoc(result, "TrunkAmmo3", field, sizeof(field)); PlayerVehicles[playerid][i][pCarTrunkAmmo3] = strval(field);
            db_get_field_assoc(result, "TrunkAmmo4", field, sizeof(field)); PlayerVehicles[playerid][i][pCarTrunkAmmo4] = strval(field);
            db_get_field_assoc(result, "Spawned", field, sizeof(field)); PlayerVehicles[playerid][i][pCarSpawned] = strval(field);
            db_get_field_assoc(result, "Owned", field, sizeof(field)); PlayerVehicles[playerid][i][pCarOwned] = strval(field);
        }
        if (PlayerVehicles[playerid][i][pCarOwned])
        {
            if (PlayerVehicles[playerid][i][pCarSpawned])
            {
                PlayerVehicles[playerid][i][pCarID] = CreateVehicle(PlayerVehicles[playerid][i][pCarModel], PlayerVehicles[playerid][i][pCarX], PlayerVehicles[playerid][i][pCarY], PlayerVehicles[playerid][i][pCarZ], PlayerVehicles[playerid][i][pCarRot], PlayerVehicles[playerid][i][pCarColor1], PlayerVehicles[playerid][i][pCarColor2], -1);
                ModifyVehicle(playerid, i);
            }
        }
        db_free_result(result);
    }
    return 1;
}
It all saves in SQlite btw.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)