command that get the nearest vehicle position
#1

i need a command that get the nearst vehicle position not distance between player to the vehicle
Reply
#2

Search. I found one in the first few links .
Reply
#3

Try these:

pawn Код:
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;
}
Reply
#4

how to work with this command ? xD
GetNearestEmptyVehicle
Reply
#5

? how to use this
i need to know if there is a car within 5 meters from me if yes DO XXXXX else XXXXX
understand ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)