01.10.2012, 23:12
The function is used to get the closest vehicle to a player, however, it doesn't work as expected. It doesn't check the vehicles as expected.
Here is the code:
Here is the exact issue. I tried the function before a vehicle was spawned and it worked correctly, however. Once a vehicle is spawn it is as if the for loop doesn't check the ID's properly. Here is a screenshot.
Any ideas?
Edit: For Player ID 0, the Returning ID is -1, for Player ID 1, the the ID returns 0.
Here is the code:
pawn Код:
forward GetClosestVehicleFromPlayer(playerid);
public GetClosestVehicleFromPlayer(playerid)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(GetVehicleModel(playerid) != 0)
{
new Float:distance = GetVehicleDistanceFromPoint(i, x, y, z);
if(distance < 3)
{
return i;
}
}
}
return -1;
}
Any ideas?
Edit: For Player ID 0, the Returning ID is -1, for Player ID 1, the the ID returns 0.