Callback to check the nearest vehicle - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Callback to check the nearest vehicle (
/showthread.php?tid=174936)
Callback to check the nearest vehicle -
dirkblok - 07.09.2010
Hey,
I got a question, does anyone know if there's a callback to check the nearest vehicle from playerid?
Thank you
Re: Callback to check the nearest vehicle -
mick88 - 07.09.2010
There's no callback and no function for that. But it's easy to find a nearby vehicle if that's what you are looking for.
Re: Callback to check the nearest vehicle -
dirkblok - 08.09.2010
Tell me please...
Thanks
Re: Callback to check the nearest vehicle -
Voldemort - 08.09.2010
pawn Код:
forward Float:GetDisBetweenPlayerAndCar(p1ayerid,carid);
forward GetClosestVehicle(carid);
pawn Код:
public GetClosestVehicleToPlayer(playerid)
{
new x,Float:dis,Float:dis2,car;
car = 0;
dis = 99999.99;
for ( x = 0; x < MAX_VEHICLES; x++ )
{
dis2 = GetDisBetweenPlayerAndCar(playerid,x);
if(dis2 < dis && dis2 < 8.0)
{
dis = dis2;
car = x;
}
}
return car;
}
pawn Код:
public Float:GetDisBetweenPlayerAndCar(p1ayerid,carid)
{
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if(!IsPlayerConnected(p1ayerid))
{
return -1.00;
}
GetPlayerPos(p1ayerid,x1,y1,z1);
GetVehiclePos(carid,x2,y2,z2);
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
Re: Callback to check the nearest vehicle -
LarzI - 08.09.2010
What if the distance to the closest vehicle is i.e. 15.0 units?
I see you're doing "&& dis < 8.0"
Re: Callback to check the nearest vehicle -
Voldemort - 08.09.2010
Than you dont have any vehicle close to you, because you wouldn't that its return a vehicle what is in SF while your self is in LS
Re: Callback to check the nearest vehicle -
LarzI - 08.09.2010
15.0 is still close imo :P