06.04.2010, 12:24
i need a command that get the nearst vehicle position not distance between player to the vehicle
stock GetVehicleDriver(vehicleid)
{
for(new i; i<GetMaxPlayers(); i++) if(IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER) return i;
return INVALID_PLAYER_ID;
}
stock Float:GetDistanceBetweenPoints(Float:X, Float:Y, Float:Z, Float:PointX, Float:PointY, Float:PointZ) return floatsqroot(floatadd(floatadd(floatpower(floatsub(X, PointX), 2.0), floatpower(floatsub(Y, PointY), 2.0)), floatpower(floatsub(Z, PointZ), 2.0)));
stock GetNearestVehicle(playerid, Float:Distance = 1000.0)
{
if(!Distance) Distance = 1000.0;
new Float:X[2], Float:Y[2], Float:Z[2], Float:NearestPos = floatabs(Distance), NearestVehicle = INVALID_VEHICLE_ID;
GetPlayerPos(playerid, X[0], Y[0], Z[0]);
for(new i; i<MAX_VEHICLES; i++)
{
if(!IsVehicleStreamedIn(i, playerid) || IsPlayerInVehicle(playerid, i)) continue;
GetVehiclePos(i, X[1], Y[1], Z[1]);
if(NearestPos > GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1])) NearestPos = GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1]), NearestVehicle = i;
}
return NearestVehicle;
}
stock GetNearestEmptyVehicle(playerid, bool:Mode, Float:Distance = 1000.0)
{
if(!Distance) Distance = 1000.0;
new Float:X[2], Float:Y[2], Float:Z[2], Float:NearestPos = floatabs(Distance), NearestVehicle = INVALID_VEHICLE_ID;
GetPlayerPos(playerid, X[0], Y[0], Z[0]);
for(new i; i<MAX_VEHICLES; i++)
{
if(!IsVehicleStreamedIn(i, playerid) || IsPlayerInVehicle(playerid, i)) continue;
if(Mode && GetVehicleDriver(i) != INVALID_PLAYER_ID) continue;
else if(!Mode && IsAnyPlayerInVehicle(i)) continue;
GetVehiclePos(i, X[1], Y[1], Z[1]);
if(NearestPos > GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1])) NearestPos = GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1]), NearestVehicle = i;
}
return NearestVehicle;
}