16.04.2011, 15:38
Ever thought of using a 3-dimensional array?
Ex: PlayerInfo[playerid][vowner][0] to PlayerInfo[playerid][vowner][14].
Calculating the amount of buyable cars is also not hard. You just need some very basic math skills.
Ex: PlayerInfo[playerid][vowner][0] to PlayerInfo[playerid][vowner][14].
pawn Код:
enum pInfo // or whatever you called it
{
vowner[15],
vowned[15],
}
pawn Код:
new
cars = (GetPlayerScore(playerid) / 100) - 1;
// I do -1 here to find the right index for the array. If it returns -1, then the score is < 100
cars = (cars > 15) ? 15 : cars;
// Adding this so array index won't go out of bounds when score is > 1500
if(cars < 0)
return SendClientMessage(playerid, COLOR_RED, "Your score is not high enough to be able to buy a car.");
// now find amount of cars already owned
new
i, count, freeslot = -1;
for(i = 0, i < 15; i++)
{
if(PlayerInfo[playerid][vowner][i])
{
count++;
}
else
{
freeslot = i; // find free slot to store new car
}
}
if((cars - count) <= 0 || count >= 15 || freeslot == -1)
return SendClientMessage(playerid, COLOR_RED, "You cannot own anymore cars");
PlayerInfo[playerid][vowner][freeslot] = 1;
PlayerInfo[playerid][vowned][freeslot] = GetPlayerVehicleID(playerid);