GetFreeVehicleSlot
#1

I tried to make a GetFreeVehicleSlot thingy, but it works when the server restarts etc, but not while its running.
I made this:

pawn Код:
stock GetFreeVehicleSlot()
{
    new VSlot;
    for(new v = 0; v < MAX_VEHICLES; v ++)
    {
        VSlot = v;
        if(VSlot != Vehicles[v][CarFileID])
        {
            return VSlot;
        }
    }
    return VSlot;
}
and the next vehicle in the Database should be 32, but IG it keeps showing 31.

Vehicle Save Callback
pawn Код:
public SaveVehicleCallback(vehicleid, playerid)
{
    new
        rows,
        fields;

    cache_get_data(rows, fields);
    if(rows == 1)
    {
        //SendClientMessage(SavingVehiclePlayerID, WARNRED, "This Vehicle already exists");
        SendClientMessage(playerid, WARNRED, "This Vehicle already exists");
    }
    else if(rows == 0)
    {
        new query[2000];

        format(query, sizeof(query), "INSERT INTO `Vehicles` (`CarFileID`, `ModelID`, `VehicleID`,`VOwner`, `VPlate`, `VehicleWorld`, `VehicleInteriorID`) VALUES ");
        format(query, sizeof(query), "%s(%d, %d, %d, '%s', '%s', %d, %d)",
        query,
        GetFreeVehicleSlot(),
        Vehicles[vehicleid][ModelID],
        vehicleid,
        Vehicles[vehicleid][VOwner],
        Vehicles[vehicleid][VPlate],
        Vehicles[vehicleid][VehicleWorld],
        Vehicles[vehicleid][VehicleInteriorID]);
        mysql_function_query(g_connectionHandle, query, false, "DefaultCallback", "");
       
        format(query, sizeof(query), "UPDATE `Vehicles` SET `Color1`= %d, `Color2` = %d, `VPosX` = '%f', `VPosY` = '%f', `VPosZ` = '%f', `VPosAngle` = '%f', `FactionCar` = %d WHERE VehicleID = %d",
        Vehicles[vehicleid][Color1],
        Vehicles[vehicleid][Color2],
        Vehicles[vehicleid][VPosX],
        Vehicles[vehicleid][VPosY],
        Vehicles[vehicleid][VPosZ],
        Vehicles[vehicleid][VPosAngle],
        Vehicles[vehicleid][FactionCar],
        vehicleid);
        mysql_function_query(g_connectionHandle, query, false, "DefaultCallback", "");
       
        DestroyVehicle(vehicleid);
        SpawnedVehicles--;

        new query2[400];
        format(query2, sizeof(query2), "SELECT * FROM `Vehicles` WHERE `VehicleID` = %d", vehicleid); // Selects all the information from the table
        mysql_function_query(g_connectionHandle, query2, true, "LoadVehiclesCallback", "d", vehicleid);
       
        SendClientMessage(playerid, GREEN, "Vehicle Saved!");
        //SendClientMessage(SavingVehiclePlayerID, GREEN, "Vehicle Saved!");
        //SavingVehiclePlayerID = -1;
    }
    else
    {
        //SendClientMessage(SavingVehiclePlayerID, COLOR_WHITE, "There was a "#COL_EMB_RED"fatal error "#COL_EMB_WHITE"during registration! Please contact a developer.");
        SendClientMessage(playerid, COLOR_WHITE, "There was a "#COL_EMB_RED"fatal error "#COL_EMB_WHITE"during registration! Please contact a developer.");
    }
    return 1;
}
Vehicle Load Callback:
pawn Код:
public LoadVehiclesCallback(vehicleid)
{
    new
        rows,
        fields;

    cache_get_data(rows, fields);
    if(rows == 1)
    {
        new temp[50];
        cache_get_row(0, 0, temp); // #0 = #1 in the DB
        Vehicles[vehicleid][CarFileID] = strval(temp);
        cache_get_row(0, 2, temp);
        Vehicles[vehicleid][ModelID] = strval(temp);
        cache_get_row(0, 3, temp);
        Vehicles[vehicleid][Color1] = strval(temp);
        cache_get_row(0, 4, temp);
        Vehicles[vehicleid][Color2] = strval(temp);
        cache_get_row(0, 5, temp);
        Vehicles[vehicleid][VPosX] = floatstr(temp);
        cache_get_row(0, 6, temp);
        Vehicles[vehicleid][VPosY] = floatstr(temp);
        cache_get_row(0, 7, temp);
        Vehicles[vehicleid][VPosZ] = floatstr(temp);
        cache_get_row(0, 8, temp);
        Vehicles[vehicleid][VPosAngle] = floatstr(temp);
        cache_get_row(0, 9, temp);
        Vehicles[vehicleid][LockStatus] = strval(temp);
        cache_get_row(0, 10, temp);
        Vehicles[vehicleid][FactionCar] = strval(temp);
        cache_get_row(0, 11, Vehicles[vehicleid][VOwner]);
        cache_get_row(0, 12, Vehicles[vehicleid][VPlate]);
        cache_get_row(0, 13, temp);
        Vehicles[vehicleid][VehicleWorld] = strval(temp);
        cache_get_row(0, 14, temp);
        Vehicles[vehicleid][VehicleInteriorID] = strval(temp);
        cache_get_row(0, 15, temp);
        Vehicles[vehicleid][SpeedoColor] = strval(temp);
        cache_get_row(0, 16, temp);
        Vehicles[vehicleid][Impounded] = strval(temp);
        cache_get_row(0, 17, temp);
        Vehicles[vehicleid][FlashAble] = strval(temp);

        if(Vehicles[vehicleid][Impounded] == 1)
        {
            if(VehicleJustImpounded[vehicleid] == 1)
            {
                ImpoundCount++;
                if(ImpoundCount >= 48)
                {
                    ImpoundCount = 0;
                }
                //new rand = random(sizeof(RandomImpoundSpawn));
                //Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], RandomImpoundSpawn[rand][0], RandomImpoundSpawn[rand][1], RandomImpoundSpawn[rand][2], RandomImpoundSpawn[rand][3], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
                Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], RandomImpoundSpawn[ImpoundCount][0], RandomImpoundSpawn[ImpoundCount][1], RandomImpoundSpawn[ImpoundCount][2], RandomImpoundSpawn[ImpoundCount][3], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
                SetVehicleVirtualWorld(Vehicles[vehicleid][VehicleID], 0);//set vw
                LinkVehicleToInterior(Vehicles[vehicleid][VehicleID], 0);//set int
                SetVehicleNumberPlate(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VPlate]);
                Vehicles[vehicleid][Fuel] = 100;
                Vehicles[vehicleid][Battery] = 100;
                VehicleJustImpounded[vehicleid] = 0;
            }
            else
            {
                new rand = random(sizeof(RandomImpoundSpawn));
                Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], RandomImpoundSpawn[rand][0], RandomImpoundSpawn[rand][1], RandomImpoundSpawn[rand][2], RandomImpoundSpawn[rand][3], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
                SetVehicleVirtualWorld(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VehicleID]+1);//set vw
                LinkVehicleToInterior(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VehicleInteriorID]);//set int
                SetVehicleNumberPlate(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VPlate]);
                Vehicles[vehicleid][Fuel] = 100;
                Vehicles[vehicleid][Battery] = 100;
            }
        }
        else
        {
            Vehicles[vehicleid][VehicleID] = AddStaticVehicleEx(Vehicles[vehicleid][ModelID], Vehicles[vehicleid][VPosX], Vehicles[vehicleid][VPosY], Vehicles[vehicleid][VPosZ], Vehicles[vehicleid][VPosAngle], Vehicles[vehicleid][Color1], Vehicles[vehicleid][Color2], -1);
            SetVehicleVirtualWorld(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VehicleWorld]);//set vw
            LinkVehicleToInterior(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VehicleInteriorID]);//set int
            SetVehicleNumberPlate(Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][VPlate]);
            Vehicles[vehicleid][Fuel] = 100;
            Vehicles[vehicleid][Battery] = 100;
        }
        Vehicles[Vehicles[vehicleid][VehicleID]][SavedCar] = 1;
        new query[500];
        format(query, sizeof(query), "UPDATE `Vehicles` SET `VehicleID` = %d WHERE `CarFileID` = %d", Vehicles[vehicleid][VehicleID], Vehicles[vehicleid][CarFileID]);
        mysql_function_query(g_connectionHandle, query, false, "DefaultCallback", "");
       
        printf("[System] Vehicle %d has been succesfully spawned!", vehicleid);
        SpawnedVehicles++;
    }
    return 1;
}
Reply


Messages In This Thread
GetFreeVehicleSlot - by Stefand - 04.06.2013, 15:39
Re: GetFreeVehicleSlot - by nmader - 04.06.2013, 16:52
Re: GetFreeVehicleSlot - by Stefand - 04.06.2013, 16:57
Re: GetFreeVehicleSlot - by Pooh7 - 04.06.2013, 17:08
Re: GetFreeVehicleSlot - by Stefand - 04.06.2013, 17:09
Re: GetFreeVehicleSlot - by Stefand - 04.06.2013, 17:16
Re: GetFreeVehicleSlot - by nmader - 04.06.2013, 17:27
Re: GetFreeVehicleSlot - by Stefand - 04.06.2013, 17:44
Re: GetFreeVehicleSlot - by Stefand - 04.06.2013, 18:23
Re: GetFreeVehicleSlot - by Stefand - 04.06.2013, 18:34

Forum Jump:


Users browsing this thread: 1 Guest(s)