Getting closest issue - 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: Getting closest issue (
/showthread.php?tid=597537)
Getting closest issue -
TwinkiDaBoss - 01.01.2016
Alright so the problem is simple, the code works but if you are not in range of that vehicle you will get unknown command display
PHP код:
GetClosestVehicleForPlayer(playerid)
{
new vehicleid = INVALID_VEHICLE_ID;
new Float:distance = 5.0;
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(!IsValidVehicle(i)) continue;
new Float: tmp = GetVehicleDistanceFromPoint(i, X, Y, Z);
if(tmp > distance) continue;
vehicleid = i;
distance = tmp;
}
return vehicleid;
}
Re: Getting closest issue -
jlalt - 01.01.2016
PHP код:
GetClosestVehicleForPlayer(playerid)
{
new vehicleid = INVALID_VEHICLE_ID;
new Float:distance = 5.0;
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(!IsValidVehicle(i)) continue;
new Float: tmp = GetVehicleDistanceFromPoint(i, X, Y, Z);
if(tmp > distance) continue;
vehicleid = i;
distance = tmp;
}
if(vehicleid != INVALID_VEHICLE_ID) return vehicleid;
else return SendClientMessage(playerid,-1,"There are no vehicle near to you!");
}
probably its because you giving player invalid vehicle id o.o try this code it would work
Re: Getting closest issue -
TwinkiDaBoss - 01.01.2016
Thanks mate