Respawning vehicles within a certain range
#2

You are checking if the player is in range, but obviously you want to check for vehicles in range. SA-MP instead offers GetVehicleDistanceFromPoint to check if a vehicle is within range of a point.

pawn Код:
CMD:range(playerid, params[])
{
    if(pInfo[playerid][pAdmin] < 3)
        return 0;
   
    new Float: range;
    if( sscanf(params, "f", range) || range < 0.0)
        return SendUsageError( playerid, "/range [Range Distance]" );
   
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);

    for(new i = 1, j = GetVehiclePoolSize(); i <= j; i ++)
    {
        if(GetVehicleDistanceFromPoint(i, x, y, z) <= range)
        {
            if(!IsValidVehicle(i))
            {
                continue;
            }

            if(spawnedcar[i])
            {
                DestroyVehicle(i);

                spawnedcar[i] = 0;
            }
            else
            {
                SetVehicleToRespawn(i);
            }
        }
    }
}
Likewise, you can still do something like this if you prefer the old method:
pawn Код:
IsVehicleInRangeOfPoint(vehicleid, Float: radius, Float: x, Float: y, Float: z) {
    if(GetVehicleDistanceFromPoint(vehicleid, x, y, z) <= radius)
        return true;

    return false;
}
Reply


Messages In This Thread
Respawning vehicles within a certain range - by FunnyBear - 20.03.2016, 14:12
Re: Respawning vehicles within a certain range - by Abagail - 20.03.2016, 14:41

Forum Jump:


Users browsing this thread: 1 Guest(s)