Getting the range of player's closest vehicle
#1

Im trying to do some commands, but only make them work if the player is in range of a vehicle, I got a lot on my mind with whatever, and cant seem to think straight. Can someone please help me??(Will +rep anyone who comments anything helpful ofc)

This is what I got
pawn Код:
stock GetPlayerClosestVehicle(playerid)
{
    new vehicleid;
    Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    foreach (new i : vehicleid)
        {
        GetVehicleDistanceFromPoint(vehicleid, X, Y, Z);
        return 1;
        }
}
stock IsPlayerInRangeOfClosestVehicle(playerid)
{
    new veh = GetPlayerClosestVehicle(playerid);
    new Float:X, Float:Y, Float:Z;
    GetVehiclePos(veh, X, Y, Z);
    if(IsPlayerInRangeOfPoint(playerid, 2.0, X, Y, Z);
Reply
#2

I just had an idea...would this work?
pawn Код:
stock IsPlayerInRangeOfClosestVehicle(playerid, distance)
{
    new veh = GetPlayerClosestVehicle(playerid);
    new Float:X, Float:Y, Float:Z;
    GetVehiclePos(veh, X, Y, Z);
    if(GetPlayerDistanceFromPoint(playerid, X, Y, Z) <=distance);
        {
        return 1;
        }
}
Reply
#3

Well, with this you do nothing, but really nothing, you should check in GetPLayerClosestVehicle IsPlayerInRangeOfPoint, with Vehicleis position coords in foreach.
Reply
#4

I could, but stocks are neater imo
Reply
#5

pawn Код:
GetPlayerClosestVehicle(playerid)
{
    new
        Float:X,
        Float:Y,
        Float:Z,
        Float:Distance,
        Float:DefaultDistance = 999999999.9,
        vID = INVALID_VEHICLE_ID;

    for(new carid = 1; carid != MAX_VEHICLES; carid++)
        if(IsValidVehicle(carid))
        {
            GetVehiclePos(carid,X,Y,Z);
            Distance = GetPlayerDistanceFromPoint(playerid, X, Y, Z);
            if(Distance < DefaultDistance)
            {
                DefaultDistance = Distance;
                vID = carid;
            }
        }

    return vID;
}

bool:IsPlayerInRangeOfClosestVehicle(playerid, Float:Range = 10.0)
{
    new veh = GetPlayerClosestVehicle(playerid);
    if(veh == INVALID_VEHICLE_ID) return false;
    new Float:X, Float:Y, Float:Z;
    GetVehiclePos(veh, X, Y, Z);
    return !!IsPlayerInRangeOfPoint(playerid, Range, X, Y, Z);
}
or

pawn Код:
Float:IsPlayerInRangeOfClosestVehicle(playerid, Float:Range = 10.0)
{
    new veh = GetPlayerClosestVehicle(playerid);

    if(veh == INVALID_VEHICLE_ID) return -1.0;

    new Float:X, Float:Y, Float:Z, Float:Distance;
    GetVehiclePos(veh, X, Y, Z);

    Distance = GetPlayerDistanceFromPoint(playerid, X, Y, Z);

    if(IsPlayerInRangeOfPoint(playerid, Range, X, Y, Z))
        return Distance;

    return Distance;
}
pawn Код:
if(-1.0 < IsPlayerInRangeOfClosestVehicle(playerid) < Your_Range)
{
// do something
}
Reply
#6

THanks, but I just had another idea, havent tested or nothing, but what about this??

stock LockVehicle(vehicleid)
{
new veh = GetPlayerClosestVehicle(playerid);
if(IsPlayerInRangeOfPoint(playerid, 2.0, veh)
{
new engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, lights, alarm, 0, bonnet, boot, objective);
}
}
Reply
#7

Top of GM

pawn Код:
#include <Brain>
Reply
#8

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Top of GM

pawn Код:
#include <Brain>
hahaha, very funny...


Fucking Troll.
Reply
#9

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Top of GM

pawn Код:
#include <Brain>
You think just because ur a high roller you can o off topic some people dont know uow to scipt like you, so please stop its anoyying to everyone im suprised you have not been warned yet i see yiu going off topic always
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)