31.01.2014, 16:35
Hello i am experiencing a problem with my car buying system. When i buy a vehicle when i have two houses i automaticly get 2 vehicles. Instead it should search for a free spot in the first house. If theres none search in second house if theres none then cancel. This is my code:
How would i go around doing that?
pawn Код:
stock BuyVehicle(ModelID, Float:PosX, Float:PosY, Float:PosZ, Float:PosRot, OwnerName[], CarName[], playerid, Price)
{
new string[255], HouseID, i = GetFreeCarIDSpot(), vid, pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
for (new HouseSlot; HouseSlot < MAX_HOUSESPERPLAYER; HouseSlot++)
{
HouseID = APlayerData[playerid][Houses][HouseSlot];
printf("OnPlayerBuyVehicle::HouseID = %d", HouseID);
if (HouseID != 0)
{
for (new CarSlot; CarSlot < House_GetMaxCarSlots(HouseID); CarSlot++)
{
if (AHouseData[HouseID][VehicleIDs][CarSlot] == 0)
{
GivePlayerCash(playerid, -Price);
format(string, sizeof(string), "INSERT INTO Vehicles (HouseID, ID, Owner, Model, X, Y, Z, Rot, Color1, Color2) VALUES ('%d', '%d', '%s', '%d', '%f', '%f', '%f', '%f', '1', '1')", HouseID, i, OwnerName, ModelID, PosX, PosY, PosZ, PosRot);
mysql_function_query(Handle, string, false, "", "");
format(string, sizeof(string), "You have succesfully bought a %s!", CarName);
SendClientMessage(playerid, 0x00FF00FF, string);
vid = Vehicle_Create(ModelID, PosX, PosY, PosZ, PosRot, 1, 1, 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] = ModelID;
AVehicleData[AHouseData[HouseID][VehicleIDs][CarSlot]][SaveID] = i;
// Save the spawn-data of the vehicle
AVehicleData[vid][SpawnX] = PosX;
AVehicleData[vid][SpawnY] = PosY;
AVehicleData[vid][SpawnZ] = PosZ;
AVehicleData[vid][SpawnRot] = PosRot;
// Also set the fuel to maximum
AVehicleData[vid][FuelData] = MaxFuel;
// Also set the owner
AVehicleData[vid][Owned] = true;
format(AVehicleData[vid][Owner], 24, pName);
// Save the HouseID for the vehicle
AVehicleData[vid][BelongsToHouse] = HouseID;
VehicleLoad[i] = true;
SavePlayer(playerid);
break;
}
}
}
}
return 1;
}