Checking if a player is near ANY vehicle.
#1

So far I have this:

pawn Code:
command(vinteract, playerid, params[])
{
    if(loggedin[playerid] == 0) return SendClientMessage(playerid, 0x66666666, "You must be logged in perform commands");
    if(GetPlayerVehicleID(playerid) > 0)
    {
        if(GetPlayerVehicleSeat(playerid) == 0 || GetPlayerVehicleSeat(playerid) == 1)
        {
            ShowPlayerDialog(playerid, VEHINTERACTIONIN, DIALOG_STYLE_LIST, "Vehicle Interaction - Front Seat.", "> Engine (On/off)\n> Lights (On/Off)\n> Glovebox(Open/Close)\n> Bonnet(Open/Close)\n> Trunk(Open/Close)\n> Windows (Up/Down)", "Close", "");
        }
        else
        {
            ShowPlayerDialog(playerid, VEHINTERACTIONBACK, DIALOG_STYLE_LIST, "Vehicle Interaction - Back Seat.", "> Windows (Up/Down)", "Close", "");
        }
    }
    else
    {
        /*if(IsPlayerInRangeOfAVehicle(playerid))
        {
            //ShowPlayerDialog(playerid, VEHINTERACTIONOUT, DIALOG_STYLE_LIST, "", dialog, "Close", "");
        }
        else
        {
            SendClientMessage(playerid, 0x66666666, "You must be near a vehicle");
        }
        */

    }
    return 1;
}
I need to know how I can check if a player is within range of ANY vehicle in the server, and pick the closest one to him, any ideas how I can do this?
Reply
#2

GetVehiclePos
IsPlayerInRangeOfPoint
Reply
#3

Good point, I guess I could use a for loop, but what would be the best way to hold the floats and still gather the closest vehicle?
Reply
#4

pawn Code:
forward GetClosestVehicle(carid);
public GetClosestVehicle(carid)
{
    new x,Float:dis,Float:dis2,car;
    car = 0;
    dis = 99999.99;
    for ( x = 0; x < MAX_VEHICLES; x++ )
    {
        if(x != carid)
        {
            dis2 = GetDistanceBetweenVehicles(x,carid);
            if(dis2 < dis && dis2 < 8.0)
            {
                dis = dis2;
                car = x;
            }
        }
    }
    return car;
}
i dont under your english becoz i am not good at english but i think you want that function...
Reply
#5

Quote:
Originally Posted by Danyal
View Post
pawn Code:
forward GetClosestVehicle(carid);
public GetClosestVehicle(carid)
{
    new x,Float:dis,Float:dis2,car;
    car = 0;
    dis = 99999.99;
    for ( x = 0; x < MAX_VEHICLES; x++ )
    {
        if(x != carid)
        {
            dis2 = GetDistanceBetweenVehicles(x,carid);
            if(dis2 < dis && dis2 < 8.0)
            {
                dis = dis2;
                car = x;
            }
        }
    }
    return car;
}
i dont under your english becoz i am not good at english but i think you want that function...
Close, but it's from a standing player to a vehicle.
Reply
#6

Untested, modify it to your liking to return 0 if dis > 10


pawn Code:
public GetClosestVehicleFromPlayer(playerid)
{
    new Float:dis = 99999999.0;
    new veh = -1;
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
        new Float:distance = GetVehicleDistanceFromPoint(i, x, y, z);
        if(distance < dis)
        {
            dis = distance;
            veh = i;
        }
    }
    return veh;
}
Reply
#7

Quote:
Originally Posted by milanosie
View Post
Untested, modify it to your liking to return 0 if dis > 10


pawn Code:
public GetClosestVehicleFromPlayer(playerid)
{
    new Float:dis = 99999999.0;
    new veh = -1;
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
        new Float:distance = GetVehicleDistanceFromPoint(i, x, y, z);
        if(distance < dis)
        {
            dis = distance;
            veh = i;
        }
    }
    return veh;
}
Thank you, I'll edit it now :3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)