Player next to 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)
+--- Thread: Player next to vehicle (
/showthread.php?tid=389120)
Player next to vehicle -
Amine_Mejrhirrou - 31.10.2012
Hi all
If any one has the code of
a function that Detect the
vehicleid next to the
playerid pleas share it
Re: Player next to vehicle -
tyler12 - 31.10.2012
PHP код:
stock GetNearestVehicle(playerid, Float:dis)
{
new Float:L, Float:O, Float:II;
if(GetPlayerPos(playerid, L, O, II))
{
new vehicleid = INVALID_VEHICLE_ID;
for(new v, Float:temp, Float:VL, Float:VO, Float:VII; v != MAX_VEHICLES; v++)
{
if(GetVehiclePos(v, VL, VO, VII) && v != GetPlayerVehicleID(playerid))
{
VL -= L, VO -= O, VII -= II;
temp = VL * VL + VO * VO + VII * VII;
if(temp < dis) dis = temp, vehicleid = v;
}
}
dis = floatpower(dis, 0.5);
return vehicleid;
}
return INVALID_VEHICLE_ID;
}
Re : Player next to vehicle -
Amine_Mejrhirrou - 31.10.2012
gonna test and ++ REP if it works thnsk
Re: Player next to vehicle -
Stu1 - 31.10.2012
If that doesn't work then heres one.
PHP код:
stock GetClosestVehicle(playerid)
{
new Float:x, Float:y, Float:z;
new Float:dist, Float:closedist=50, closeveh, found = 0;
for(new i=1; i < MAX_VEHICLES; i++)
{
if(GetVehiclePos(i, x, y, z) && i != GetPlayerVehicleID(playerid))
{
dist = GetPlayerDistanceFromPoint(playerid, x, y, z);
if(dist < closedist)
{
found = 1;
closedist = dist;
closeveh = i;
}
}
}
if(found == 1) return closeveh;
return 0;
}