Saving an ID from the database and assign it to a vehicleid help +REP!
#1

Hello i want to make a car system and i have come a far way with it with the help from _Zeus but now he is making his own GM so i need help from someone else now So this is my car loading system:
pawn Код:
forward OnPlayerHousesVehiclesLoad(playerid, houseid_);
public OnPlayerHousesVehiclesLoad(playerid, houseid_)
{
    printf( "OnPlayerHousesVehiclesLoad::houseid_ = %d", houseid_ );
    new rows, fields;
    cache_get_data( rows, fields, Handle );

    if( rows )
    {
        print("There are rows - Vehicles");
        new
        idx = 0,
        cmodel2, Float: cx2, Float: cy2, Float: cz2, Float: crot2, ccol1, ccol2, _carid
        ;
        while( rows > idx )
        {
            _carid = cache_get_row_int(idx, 2);
            cmodel2 = cache_get_row_int( idx, 3 );
            cx2 = cache_get_row_float( idx, 4 );
            cy2 = cache_get_row_float( idx, 5 );
            cz2 = cache_get_row_float( idx, 6 );
            crot2 = cache_get_row_float( idx, 7 );
            ccol1 = cache_get_row_int( idx, 8 );
            ccol2 = cache_get_row_int( idx, 9 );

            printf("House_AddVehicle(%d,%d,%f,%f,%f,%f,%d,%d);", houseid_, cmodel2, cx2, cy2, cz2, crot2, ccol1, ccol2);
            House_AddVehicle(houseid_, cmodel2, cx2, cy2, cz2, crot2, ccol1, ccol2, _carid);
            print("Car loaded");

            idx++;
        }
    }
    return 1;
}
Now the _carid is the problem. The _carid does NOT represent vehicle id it represents an ID in the database. Wich should be saved for EVERY vehicle.
Now here is House_AddVehicle:
pawn Код:
House_AddVehicle(HouseID, cModel, Float:cx, Float:cy, Float:cz, Float:crot, Col1, Col2, CarID)
{
    // Setup local variables
    new vid, CarSlot;//, string2[128];

    // Get a free carslot from the house
    CarSlot = House_GetFreeCarSlot(HouseID);
    printf("House_AddVehicle::CarSlot = %d", CarSlot);
    // Check if there is a free carslot
    if (CarSlot != -1)
    {
        vid = Vehicle_Create(cModel, cx, cy, cz, crot, Col1, Col2, 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[vid][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;
        // Also set the fuel to maximum
        AVehicleData[vid][FuelData] = MaxFuel;
        // Also set the owner
        AVehicleData[vid][Owned] = true;
        format(AVehicleData[vid][Owner], 24, AHouseData[HouseID][Owner]);
        // Save the HouseID for the vehicle
        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;
}
It should save the id per vehicle but now i have a park command that needs to use the ID to save it. Now here is the CMDark
pawn Код:
CMD:park(playerid, params[])
{
    new Float:x, Float:y, Float:z, Float:rot, vid, HouseID;
    new engine,lights,alarm,doors,bonnet,boot,objective, string[128];

    if (GetPlayerVehicleSeat(playerid) == 0)
    {
        vid = GetPlayerVehicleID(playerid);
        HouseID = AVehicleData[vid][BelongsToHouse];
        if ((AVehicleData[vid][Owned] == true) && (HouseID != 0))
        {
            GetVehiclePos(vid, x, y, z);
            GetVehicleZAngle(vid, rot);
            AVehicleData[vid][SpawnX] = x;
            AVehicleData[vid][SpawnY] = y;
            AVehicleData[vid][SpawnZ] = z;
            AVehicleData[vid][SpawnRot] = rot;
            format(string, sizeof(string), "UPDATE Vehicles SET X = %f, Y = %f, Z = %f, Rot = %f WHERE ID = %d", x, y, z, rot, AVehicleData[vid][SaveID]);
            mysql_function_query( Handle, string, false, "", "" );
            for (new i; i < MAX_HOUSESPERPLAYER; i++)
            {
                HouseID = APlayerData[playerid][Houses][i];
                for (new CarSlot; CarSlot < 20; CarSlot++)
                {
                    if (AHouseData[HouseID][VehicleIDs][CarSlot] == vid)
                    {
                        House_ReplaceVehicle(HouseID, CarSlot);
                        PutPlayerInVehicle(playerid, AHouseData[HouseID][VehicleIDs][CarSlot], 0);
                        GetVehicleParamsEx(AHouseData[HouseID][VehicleIDs][CarSlot], engine, lights, alarm, doors, bonnet, boot, objective);
                        SetVehicleParamsEx(AHouseData[HouseID][VehicleIDs][CarSlot], 1, lights, alarm, doors, bonnet, boot, objective);
                        break;
                    }
                }
            }
            SendClientMessage(playerid, 0x00FF00FF, "You've parked your vehicle");
        }
        else
            SendClientMessage(playerid, 0xFF0000FF, "You cannot park a vehicle that's not owned by you");
    }
    else
        SendClientMessage(playerid, 0xFF0000FF, "You are not in a vehicle!");
    return 1;
}
Now the AVehicleData[vid][SaveID] always gives back 0 why does it do that?
Hope anyone can help me! +REP!
I found out cache_get_row doesnt get it already the query gets 0 back...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)