SA-MP Forums Archive
Get vehicle free seat ID - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Get vehicle free seat ID (/showthread.php?tid=662276)



Get vehicle free seat ID - 3417512908 - 28.12.2018

Help with this...If the vehicle seat is not full,return seat ID or return -1


Re: Get vehicle free seat ID - ranme15 - 28.12.2018

You could use a loop to check whoever in the vehicle, then using GetPlayerVehicleSeat function to check whether seats are full or not.


Re: Get vehicle free seat ID - Dennis12 - 28.12.2018

Mhm, I think this could help you:

Код:
stock getSeatStatus(const vID, const seatID)
{
	for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
	{
		if(GetPlayerVehicleID(i) == vID && GetPlayerVehicleSeat(i) == seatID)
			return true; 
	}
	return false; 
}



Re: Get vehicle free seat ID - 3417512908 - 28.12.2018

Quote:
Originally Posted by ranme15
Посмотреть сообщение
You could use a loop to check whoever in the vehicle, then using GetPlayerVehicleSeat function to check whether seats are full or not.
Quote:
Originally Posted by Dennis12
Посмотреть сообщение
Mhm, I think this could help you:

Код:
stock getSeatStatus(const vID, const seatID)
{
	for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
	{
		if(GetPlayerVehicleID(i) == vID && GetPlayerVehicleSeat(i) == seatID)
			return true; 
	}
	return false; 
}
Thank a lot bro


Re: Get vehicle free seat ID - beckzy - 28.12.2018

I'm not sure if GetPlayerVehicleSeat always works. It didn't used to work at times for some reason.


Re: Get vehicle free seat ID - Threshold - 29.12.2018

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:

PHP код:
new const MaxVehicleSeats[212] =
{
    
4222441224222422424244222,
    
1444219122029424122241,
    
21202111222442212124422421,
    
12212242143111442424122244,
    
22222222421121122422112222,
    
22224111222222142222244224,
    
42122222244221244100112,
    
1224244241042222002211,
    
4442222242000400
};
GetFreeSeat(vehicleid)
{
    new 
vehiclemodel GetVehicleModel(vehicleid);
    if(
vehiclemodel)
    {
        new
            
bool:seattaken[10],
            
playerseat = -1
        
;
        foreach(new 
Player)
        {
            if(!
IsPlayerInVehicle(ivehicleid)) continue;
            
playerseat GetPlayerVehicleSeat(i);
            if(
<= playerseat 128)
                
seattaken[playerseat] = true;
        }
        for(new 
0MaxVehicleSeats[vehiclemodel 400]; v++)
        {
            if(
seattaken[v]) continue;
            return 
v;
        }
    }
    return -
1;

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.