Help with open carslot problem.
#1

Okay so i am experiencing some problems with loading of house vehicles. I had this:
pawn Код:
new vid, CarSlot, pName[MAX_PLAYER_NAME];//, string2[128];
    GetPlayerName(playerid, pName, sizeof(pName));
    CarSlot = House_GetFreeCarSlot(HouseID);
    printf("House_AddVehicle::CarSlot = %d", CarSlot);
    if (CarSlot != 0)
    {
        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] = Col1;
        AVehicleData[vid][Color2] = Col2;
        // 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;

        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;
}
But that always says there is no free car slot for some reason. Anyone knows why?
Reply
#2

The problem will be in House_GetFreeCarSlot function then since it will return 0.
Reply
#3

Okay this is the function:
pawn Код:
House_GetFreeCarSlot(HouseID)
{
    new MaxCarSlots = House_GetMaxCarSlots(HouseID);
    printf( "House_GetFreeCarSlot::MaxCarSlots = %d", MaxCarSlots );
    for (new CarSlot; CarSlot < MaxCarSlots; CarSlot++)
    {
        printf( "House_GetFreeCarSlot::if(AHouseData[%d][VehicleIDs][%d] == 0 | Result: %d)", HouseID, CarSlot, AHouseData[HouseID][VehicleIDs][CarSlot] );
        if (AHouseData[HouseID][VehicleIDs][CarSlot] == 0)
        {
            print( "House_GetFreeCarSlot::CarSlot is 0" );
            return CarSlot;
        }
    }
    return -1;
}
And the console gives out this when loading which i find kind of weird:
Код:
[12:21:25] There are rows - Vehicles
[12:21:25] ccol1: 0, ccol2: 1
[12:21:25] 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
[12:21:25] House_AddVehicle(3,480,-1986.920043,270.180999,35.010898,265.811004,0,1, 3);
[12:21:25] House_GetFreeCarSlot::MaxCarSlots = 10
[12:21:25] House_GetFreeCarSlot::if(AHouseData[3][VehicleIDs][0] == 0 | Result: 0)
[12:21:25] House_GetFreeCarSlot::CarSlot is 0
[12:21:25] House_AddVehicle::CarSlot = 0
[12:21:25] No free carslot
[12:21:25] Car loaded
[12:21:25] OnPlayerHousesVehiclesLoad::houseid_ = 4
[12:21:25] There are rows - Vehicles
[12:21:25] ccol1: 0, ccol2: 1
[12:21:25] 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
[12:21:25] House_AddVehicle(4,480,-1986.920043,270.180999,35.010898,265.811004,0,1, 3);
[12:21:25] House_GetFreeCarSlot::MaxCarSlots = 10
[12:21:25] House_GetFreeCarSlot::if(AHouseData[4][VehicleIDs][0] == 0 | Result: 0)
[12:21:25] House_GetFreeCarSlot::CarSlot is 0
[12:21:25] House_AddVehicle::CarSlot = 0
[12:21:25] No free carslot
[12:21:25] Car loaded
Reply
#4

I found the problem. The function is fine and it returns 0 which is a valid free slot. The mistake is in this line:
pawn Код:
if (CarSlot != 0)
and it should be:
pawn Код:
if (CarSlot != -1)
because if it's not -1, then there aren't free slots.
Reply
#5

Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)