Detecting if playerid is in range of vehicleid - 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: Detecting if playerid is in range of vehicleid (
/showthread.php?tid=407889)
Detecting if playerid is in range of vehicleid -
jakejohnsonusa - 15.01.2013
How do I detect if a playerid is in range (55.0) of vehicleid?
Thanks in advance!
Re: Detecting if playerid is in range of vehicleid -
Infinity90 - 15.01.2013
pawn Code:
RespawnNearbyVehicles(playerid, Float:radi)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
for(new i=1; i<MAX_VEHICLES; i++)
{
if(GetVehicleModel(i))
{
new Float:posx, Float:posy, Float:posz;
new Float:tempposx, Float:tempposy, Float:tempposz;
GetVehiclePos(i, posx, posy, posz);
tempposx = (posx - x);
tempposy = (posy - y);
tempposz = (posz - z);
if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
{
SetVehicleToRespawn(i);
}
}
}
}
Usage
pawn Code:
RespawnNearbyVehicles(playerid, radius);
Re: Detecting if playerid is in range of vehicleid -
jakejohnsonusa - 15.01.2013
That doesn't look right.... That respawns the cars. I want it to check if a player is in range (55.0) of a certain vehicle (I will be using with GetNearestVehicle).
Anyone know?
Re: Detecting if playerid is in range of vehicleid -
Dolby - 15.01.2013
pawn Code:
new Float:X,Float:Y,Float:Z;
GetVehiclePos(vehicleid, X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, 55.0, X, Y, Z))
{
...
}
Re: Detecting if playerid is in range of vehicleid -
jakejohnsonusa - 15.01.2013
Thanks!