Car mods saving need help.
#1

So i am trying to make the car mods re apply when the player types /park. Now When i type /park all the mods are gone. I got this at House_ReplaceVehicle
pawn Код:
for (new i; i < 14; i++)
        cComponents[i] = GetVehicleComponentInSlot(vid, i);
Now that should get all components and later in that function this is used:
pawn Код:
vid = House_AddVehicle(HouseID, cModel, Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, _CarID, playerid, cComponents);
Now when it creates the new vehicle it removes all mods even though i got this in the House_AddVehicle:
pawn Код:
for (new s; s != 14; ++s)
        {
            if (cComponents[s]) AddVehicleComponent(vid, cComponents[s]);
        }
The header:
pawn Код:
House_AddVehicle(HouseID, cModel, Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, CarID, playerid, cComponents[])
Any one knows the problem?

Edit:
House_ReplaceVehicle:
pawn Код:
House_ReplaceVehicle(HouseID, CarSlot, playerid)
{
    new vid, cModel, Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, Float:Health, cFuel, _CarID, cComponents[14];
    new panels, doors, lights, tires;

    vid = AHouseData[HouseID][VehicleIDs][CarSlot];
    _CarID = AVehicleData[vid][SaveID];
    cModel = AVehicleData[vid][CarModel];
    cFuel = AVehicleData[vid][FuelData];
    Col1 = AVehicleData[vid][Color1];
    Col2 = AVehicleData[vid][Color2];
    cx = AVehicleData[vid][SpawnX];
    for (new i; i < 14; i++)
        cComponents[i] = GetVehicleComponentInSlot(vid, i);
    printf("%s", cComponents);
    cy = AVehicleData[vid][SpawnY];
    cz = AVehicleData[vid][SpawnZ];
    crot = AVehicleData[vid][SpawnRot];
    GetVehicleHealth(vid, Health);
    GetVehicleDamageStatus(vid, panels, doors, lights, tires);

    // Delete the vehicle and clear the data
    Vehicle_Delete(vid);

    // Create a new vehicle in the same carslot
    vid = House_AddVehicle(HouseID, cModel, Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, _CarID, playerid, cComponents);
    // Update the fuel of the vehicle to the previous setting
    AVehicleData[vid][FuelData] = cFuel;
    // Update the health to what it was before and update the bodywork
    SetVehicleHealth(vid, Health);
    UpdateVehicleDamageStatus(vid, panels, doors, lights, tires);

    return vid;
}
House_AddVehicle:
pawn Код:
House_AddVehicle(HouseID, cModel, Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, CarID, playerid, cComponents[])
{
    new vid, CarSlot, pName[MAX_PLAYER_NAME], string[126], modelid, a[14];//, string2[128];
    GetPlayerName(playerid, pName, sizeof(pName));
    CarSlot = House_GetFreeCarSlot(HouseID);
    printf("House_AddVehicle::CarSlot = %d", CarSlot);
    if (CarSlot != -1)
    {
        vid = Vehicle_Create(cModel, cx, cy, cz, crot, Col2, Col1, 600);
        printf("House_AddVehicle::vid= %d", vid);
        AHouseData[HouseID][VehicleIDs][CarSlot] = vid;
        printf("House_AddVehicle::AHouseData[%d][VehicleIDs][%d]= %d", HouseID, CarSlot, AHouseData[HouseID][VehicleIDs][CarSlot]);
        AVehicleData[vid][CarModel] = cModel;
        AVehicleData[AHouseData[HouseID][VehicleIDs][CarSlot]][SaveID] = CarID;
        // Save the spawn-data of the vehicle
        AVehicleData[vid][SpawnX] = cx;
        AVehicleData[vid][SpawnY] = cy;
        AVehicleData[vid][SpawnZ] = cz;
        AVehicleData[vid][SpawnRot] = crot;
        AVehicleData[vid][Color1] = Col2;
        AVehicleData[vid][Color2] = Col1;
        sscanf(cComponents, "p<,>a<i>[14]", a);
        for (new s; s != 14; ++s)
        {
//          AVehicleData[vid][Components][s] = cComponents[s];
            if (cComponents[s]) AddVehicleComponent(vid, cComponents[s]);
        }
        // Apply the given parameters to the vehicle
        AVehicleData[vid][FuelData] = MaxFuel;
        AVehicleData[vid][Owned] = true;
        ChangeVehicleColor(vid, AVehicleData[vid][Color1], AVehicleData[vid][Color2]);
        format(AVehicleData[vid][Owner], 24, pName);
        AVehicleData[vid][BelongsToHouse] = HouseID;
        modelid = GetVehicleModel(vid);
        format(string, sizeof(string), "%s's %s", pName, VehicleNames2[modelid-400]);
        VehText[vid] = Create3DTextLabel(string,0xFFFFFFFF,0,0,0,100.0,0);
        Attach3DTextLabelToVehicle(VehText[vid], vid, 0,0,0);
        print("Vehicle loaded");
    }
    else
    {
        print ("No free carslot");// No free carslot was found, return 0
        return 0;
    }

    // Exit the function and return the vehicle-id
    return vid;
}
Reply
#2

Often with bugs like this just posting the exact lines that do want you want doesn't help - the bug is something elsewhere preventing your code being called correctly at all. We need WAY more code to debug the problem. As you rightly point out, that code looks fine so the bug probably isn't there. In general, if you don't know what is causing a bug, don't assume that you know where the code causing the bug is.
Reply
#3

I am sorry.

House_ReplaceVehicle:
pawn Код:
House_ReplaceVehicle(HouseID, CarSlot, playerid)
{
    new vid, cModel, Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, Float:Health, cFuel, _CarID, cComponents[14];
    new panels, doors, lights, tires;

    vid = AHouseData[HouseID][VehicleIDs][CarSlot];
    _CarID = AVehicleData[vid][SaveID];
    cModel = AVehicleData[vid][CarModel];
    cFuel = AVehicleData[vid][FuelData];
    Col1 = AVehicleData[vid][Color1];
    Col2 = AVehicleData[vid][Color2];
    cx = AVehicleData[vid][SpawnX];
    for (new i; i < 14; i++)
        cComponents[i] = GetVehicleComponentInSlot(vid, i);
    printf("%s", cComponents);
    cy = AVehicleData[vid][SpawnY];
    cz = AVehicleData[vid][SpawnZ];
    crot = AVehicleData[vid][SpawnRot];
    GetVehicleHealth(vid, Health);
    GetVehicleDamageStatus(vid, panels, doors, lights, tires);

    // Delete the vehicle and clear the data
    Vehicle_Delete(vid);

    // Create a new vehicle in the same carslot
    vid = House_AddVehicle(HouseID, cModel, Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, _CarID, playerid, cComponents);
    // Update the fuel of the vehicle to the previous setting
    AVehicleData[vid][FuelData] = cFuel;
    // Update the health to what it was before and update the bodywork
    SetVehicleHealth(vid, Health);
    UpdateVehicleDamageStatus(vid, panels, doors, lights, tires);

    return vid;
}
House_AddVehicle:
pawn Код:
House_AddVehicle(HouseID, cModel, Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, CarID, playerid, cComponents[])
{
    new vid, CarSlot, pName[MAX_PLAYER_NAME], string[126], modelid, a[14];//, string2[128];
    GetPlayerName(playerid, pName, sizeof(pName));
    CarSlot = House_GetFreeCarSlot(HouseID);
    printf("House_AddVehicle::CarSlot = %d", CarSlot);
    if (CarSlot != -1)
    {
        vid = Vehicle_Create(cModel, cx, cy, cz, crot, Col2, Col1, 600);
        printf("House_AddVehicle::vid= %d", vid);
        AHouseData[HouseID][VehicleIDs][CarSlot] = vid;
        printf("House_AddVehicle::AHouseData[%d][VehicleIDs][%d]= %d", HouseID, CarSlot, AHouseData[HouseID][VehicleIDs][CarSlot]);
        AVehicleData[vid][CarModel] = cModel;
        AVehicleData[AHouseData[HouseID][VehicleIDs][CarSlot]][SaveID] = CarID;
        // Save the spawn-data of the vehicle
        AVehicleData[vid][SpawnX] = cx;
        AVehicleData[vid][SpawnY] = cy;
        AVehicleData[vid][SpawnZ] = cz;
        AVehicleData[vid][SpawnRot] = crot;
        AVehicleData[vid][Color1] = Col2;
        AVehicleData[vid][Color2] = Col1;
        sscanf(cComponents, "p<,>a<i>[14]", a);
        for (new s; s != 14; ++s)
        {
//          AVehicleData[vid][Components][s] = cComponents[s];
            if (cComponents[s]) AddVehicleComponent(vid, cComponents[s]);
        }
        // Apply the given parameters to the vehicle
        AVehicleData[vid][FuelData] = MaxFuel;
        AVehicleData[vid][Owned] = true;
        ChangeVehicleColor(vid, AVehicleData[vid][Color1], AVehicleData[vid][Color2]);
        format(AVehicleData[vid][Owner], 24, pName);
        AVehicleData[vid][BelongsToHouse] = HouseID;
        modelid = GetVehicleModel(vid);
        format(string, sizeof(string), "%s's %s", pName, VehicleNames2[modelid-400]);
        VehText[vid] = Create3DTextLabel(string,0xFFFFFFFF,0,0,0,100.0,0);
        Attach3DTextLabelToVehicle(VehText[vid], vid, 0,0,0);
        print("Vehicle loaded");
    }
    else
    {
        print ("No free carslot");// No free carslot was found, return 0
        return 0;
    }

    // Exit the function and return the vehicle-id
    return vid;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)