Inrange
#1

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
Reply
#2

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.
Reply
#3

THANK YOU! That's what I've been looking for! Thank you Stigg! <3 +1 repppppppp.
Reply
#4

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..
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)