27.06.2008, 18:55 
	
	
	
		GetVehicleDriver(vehicleid)
Returns the ID of the player driving in the vehicle. Returns '-1' if nobody is driving in the vehicle.
I see that the function I just came up with, was already posted  
 
However, the one I made is a LITTLE bit faster and more server-friendly
This one returns INVALID_PLAYER_ID if the vehicle has no driver, and the player id of a driver if it has.
	
	
	
	
Returns the ID of the player driving in the vehicle. Returns '-1' if nobody is driving in the vehicle.
Код:
stock GetVehicleDriver(vehicleid)
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if (IsPlayerInVehicle(i, vehicleid))
    {
      if(GetPlayerState(i) == 2)
      {
   		return i;
      }
	}
  }
  return -1;
}
 
 However, the one I made is a LITTLE bit faster and more server-friendly

pawn Код:
stock GetDriver(vehicleid)
{
for(new playerid = 0; playerid<MAX_PLAYERS;playerid++)
{
if(IsPlayerConnected(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(IsPlayerInVehicle(playerid,vehicleid)) return playerid;
}
}
}
return INVALID_PLAYER_ID;
}




 
	

 
	
 
	

