29.12.2018, 10:12
I made some function like this quite a while back, and I'm sure many others have been made just like it. This was my version a few years ago:
There is a slight chance that the array might need to be updated. It does include vehicles that can be driven but not entered, and these are issued with a 'seat count' of 0.
PHP код:
new const MaxVehicleSeats[212] =
{
4, 2, 2, 2, 4, 4, 1, 2, 2, 4, 2, 2, 2, 4, 2, 2, 4, 2, 4, 2, 4, 4, 2, 2, 2,
1, 4, 4, 4, 2, 1, 9, 1, 2, 2, 0, 2, 9, 4, 2, 4, 1, 2, 2, 2, 4, 1,
2, 1, 2, 0, 2, 1, 1, 1, 2, 2, 2, 4, 4, 2, 2, 1, 2, 1, 2, 4, 4, 2, 2, 4, 2, 1,
1, 2, 2, 1, 2, 2, 4, 2, 1, 4, 3, 1, 1, 1, 4, 4, 2, 4, 2, 4, 1, 2, 2, 2, 4, 4,
2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 1, 1, 2, 1, 1, 2, 2, 4, 2, 2, 1, 1, 2, 2, 2, 2,
2, 2, 2, 2, 4, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 4, 2, 2, 2, 2, 2, 4, 4, 2, 2, 4,
4, 2, 1, 2, 2, 2, 2, 2, 2, 4, 4, 2, 2, 1, 2, 4, 4, 1, 0, 0, 1, 1, 2,
1, 2, 2, 4, 2, 4, 4, 2, 4, 1, 0, 4, 2, 2, 2, 2, 0, 0, 2, 2, 1, 1,
4, 4, 4, 2, 2, 2, 2, 2, 4, 2, 0, 0, 0, 4, 0, 0
};
GetFreeSeat(vehicleid)
{
new vehiclemodel = GetVehicleModel(vehicleid);
if(vehiclemodel)
{
new
bool:seattaken[10],
playerseat = -1
;
foreach(new i : Player)
{
if(!IsPlayerInVehicle(i, vehicleid)) continue;
playerseat = GetPlayerVehicleSeat(i);
if(0 <= playerseat < 128)
seattaken[playerseat] = true;
}
for(new v = 0; v < MaxVehicleSeats[vehiclemodel - 400]; v++)
{
if(seattaken[v]) continue;
return v;
}
}
return -1;
}