Issue with Vehicle Saving [+Rep]
#1

Hello SA:MP community,

I have ran into a rather strange bug. I have a vehicle system and when you create a vehicle, you should be able to move it and it saves the location; however the vehicle moves when you use the command /permcarloc but does not save in the database. The saving function is not the problem, I've already looked into that.

pawn Код:
dcmd_permcarloc(playerid, params[])
{
    new vehicleid;
    if(PlayerInfo[playerid][pAdmin] < 1337) return ErrorMessage(playerid, "You cannot use this command.");
    if(sscanf(params, "d", vehicleid)) return SyntaxMessage(playerid, "/permcarloc [vehicle id]");
    if(PermanentVehicleStatistics[vehicleid][IsPermCar])
    {
        new Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, a);
        SetVehiclePos(vehicleid, x, y, z);
        PutPlayerInVehicle(playerid, vehicleid, 0);
        SetVehicleZAngle(vehicleid, a);
        SetPlayerPosEx(playerid, x, y, z);

        // reset the vehicle
        new
            vehicle,
            sql = PermanentVehicleStatistics[vehicleid][PermCarSQL],
            color1 = PermanentVehicleStatistics[vehicleid][PermCarColors][1],
            color2 = PermanentVehicleStatistics[vehicleid][PermCarColors][2],
            faction = PermanentVehicleStatistics[vehicleid][PermCarFaction],
            family = PermanentVehicleStatistics[vehicleid][PermCarFamily],
            vip = PermanentVehicleStatistics[vehicleid][PermCarVIP],
            model = PermanentVehicleStatistics[vehicleid][PermCarModel],
            interior = PermanentVehicleStatistics[vehicleid][PermCarInt],
            world = PermanentVehicleStatistics[vehicleid][PermCarVW];

        DestroyVehicleEx(vehicleid);
        PermanentVehicleStatistics[vehicleid][IsPermCar] = 0;
        PermanentVehicleStatistics[vehicleid][PermCarModel] = 0;
        PermanentVehicleStatistics[vehicleid][PermCarFamily] = 0;
        PermanentVehicleStatistics[vehicleid][PermCarX] = 0.0;
        PermanentVehicleStatistics[vehicleid][PermCarY] = 0.0;
        PermanentVehicleStatistics[vehicleid][PermCarZ] = 0.0;
        PermanentVehicleStatistics[vehicleid][PermCarRot] = 0.0;
        PermanentVehicleStatistics[vehicleid][PermCarColors][1] = 0;
        PermanentVehicleStatistics[vehicleid][PermCarColors][2] = 0;
        PermanentVehicleStatistics[vehicleid][PermCarVIP] = 0;
        PermanentVehicleStatistics[vehicleid][PermCarFaction] = 0;
        PermanentVehicleStatistics[vehicleid][PermCarSQL] = 0;

        vehicle = AddStaticVehicleEx(model, x, y, z, a, color1, color2, 1800);
        PermanentVehicleStatistics[vehicle][IsPermCar] = 1;
        PermanentVehicleStatistics[vehicle][PermCarID] = vehicleid;
        PermanentVehicleStatistics[vehicle][PermCarX] = x;
        PermanentVehicleStatistics[vehicle][PermCarY] = y;
        PermanentVehicleStatistics[vehicle][PermCarZ] = z;
        PermanentVehicleStatistics[vehicle][PermCarRot] = a;
        PermanentVehicleStatistics[vehicle][PermCarColors][1] = color1;
        PermanentVehicleStatistics[vehicle][PermCarColors][2] = color2;
        PermanentVehicleStatistics[vehicle][PermCarFaction] = faction;
        PermanentVehicleStatistics[vehicle][PermCarFamily] = family;
        PermanentVehicleStatistics[vehicle][PermCarModel] = model;
        PermanentVehicleStatistics[vehicle][PermCarVIP] = vip;
        PermanentVehicleStatistics[vehicle][PermCarInt] = interior;
        PermanentVehicleStatistics[vehicle][PermCarVW] = world;
        PermanentVehicleStatistics[vehicle][PermCarSQL] = sql;

        LinkVehicleToInterior(vehicle, interior);
        SetVehicleVirtualWorld(vehicle, world);

        SetPlayerPos(playerid, x, y, z + 2);
        TogglePlayerControllable(playerid, 0);
        SetTimerEx("UnfreezeMeNow", 800, false, "i", playerid);
        SavePermanentVehicle(vehicle);
        return 1;
    }
    else { SendClientMessage(playerid, GREY, "This vehicle is not a permanent vehicle."); }
    return 1;
}
Anyone who can provide a (valid) answer on how to fix this will be rewarded with a reputation point.

Best Wishes,
Nmader
Scripter
Reply
#2

Cam you show us the Saving function as I can't see why it's not saving.
Reply
#3

pawn Код:
stock SavePermanentVehicles()
{
    for (new i = 1; i < MAX_VEHICLES; i ++)
    {
        if (!PermanentVehicleStatistics[i][IsPermCar]) continue;
        if (GetVehicleModel(i) < 400) continue;
        SavePermanentVehicle(i);
    }
    return 1;
}

stock SavePermanentVehicle(vehicleid)
{
    new query[768];
    if (!PermanentVehicleStatistics[vehicleid][IsPermCar]) return 0;
    else
    {
        format(query, sizeof(query), "UPDATE `PermCars` SET `PermCarModel` = '%d', `PermCarFaction` = '%d', `PermCarX` = '%f', `PermCarY` = '%f', `PermCarZ` = '%f', `PermCarRot` = '%f', `PermCarColor1` = '%d', `PermCarColor2` = '%d', `PermCarFamily` = '%d', `PermCarVIP` = '%d', `PermCarInt` = '%d', `PermCarVW` = '%d' WHERE `PermCarID` = '%d'",
        PermanentVehicleStatistics[vehicleid][PermCarModel],
        PermanentVehicleStatistics[vehicleid][PermCarFaction],
        PermanentVehicleStatistics[vehicleid][PermCarX],
        PermanentVehicleStatistics[vehicleid][PermCarY],
        PermanentVehicleStatistics[vehicleid][PermCarZ],
        PermanentVehicleStatistics[vehicleid][PermCarRot],
        PermanentVehicleStatistics[vehicleid][PermCarColors][1],
        PermanentVehicleStatistics[vehicleid][PermCarColors][2],
        PermanentVehicleStatistics[vehicleid][PermCarFamily],
        PermanentVehicleStatistics[vehicleid][PermCarVIP],
        PermanentVehicleStatistics[vehicleid][PermCarInt],
        PermanentVehicleStatistics[vehicleid][PermCarVW],
        PermanentVehicleStatistics[vehicleid][PermCarSQL]);
        db_query(ServerDB, query);
        print("Vehicle data successfully saved!");
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)