Inrange - 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: Inrange (
/showthread.php?tid=284906)
Inrange -
iGetty - 21.09.2011
How can I get if a player is in range of a vehicle? Like I have this command:
pawn Код:
command(fish, playerid, params[])
{
return 1;
}
I also have the fishing reefer added.
pawn Код:
reefer = CreateVehicle(blablabla);
How can I get if they are in range of the vehicle? So they can fish off it.
Thanks
-iGetty
Re: Inrange -
Stigg - 21.09.2011
You could try:
pawn Код:
stock GetClosestVehicle(playerid, Float:dis)
{
new Float:X, Float:Y, Float:Z;
if(GetPlayerPos(playerid, X, Y, Z))
{
new vehicleid = INVALID_VEHICLE_ID;
for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++)
{
if(GetVehiclePos(v, VX, VY, VZ))
{
VX -= X, VY -= Y, VZ -= Z;
temp = VX * VX + VY * VY + VZ * VZ;
if(temp < dis) dis = temp, vehicleid = v;
}
}
dis = floatpower(dis, 0.5);
return vehicleid;
}
return INVALID_VEHICLE_ID;
}
Modify to suit your needs.
Re: Inrange -
iGetty - 21.09.2011
THANK YOU! That's what I've been looking for! Thank you Stigg! <3 +1 repppppppp.
Re: Inrange -
aRoach - 21.09.2011
Simple:
pawn Код:
new Float:P[ 3 ];
GetVehiclePos( reefer, P[ 0 ], P[ 1 ], P[ 2 ] );
if( IsPlayerInRangeOfPoint( playerid, 5.0, P[ 0 ], P[ 1 ], P[ 2 ] ) )
{
// Code .. Code..
}