Getting the nearest airport
#1

So, if I were in Las Venturas Airport and I type /w (work cmd) how would i get a new mission from here:
PHP код:
//LVA to LSA
    
{"Las Venturas Airport Gate 1 to Los Santos Airport Gate 1 with 31 Passengers"false,24356,1580.8203,1533.4772,10.8324,1727.2162,-2412.8289,13.5547},
    {
"Las Venturas Airport Gate 1 to Los Santos Airport Gate 1 with 29 Passengers"false,23089,1580.8203,1533.4772,10.8324,1727.2162,-2412.8289,13.5547},
    {
"Las Venturas Airport Gate 1 to Los Santos Airport Gate 1 with 17 Passengers"false,22783,1580.8203,1533.4772,10.8324,1727.2162,-2412.8289,13.5547},
    
//LSA TO LVA
 
{"Los Santos Airport Gate 1 to Las Venturas Airport Gate 1 with 61 Passengers"false,25349,1727.2162,-2412.8289,13.5547,1580.8203,1533.4772,10.8324},
 {
"Los Santos Airport Gate 1 to Las Venturas Airport Gate 1 with 53 Passengers"false,22000,1727.2162,-2412.8289,13.5547,1580.8203,1533.4772,10.8324},
 {
"Los Santos Airport Gate 1 to Las Venturas Airport Gate 1 with 34 Passengers"false,22984,1727.2162,-2412.8289,13.5547,1580.8203,1533.4772,10.8324}, 
and it picks out the nearest Airport (so if i am flying near in LS, it would get a new mission from Ls airport, and if i were to fly around lv, it would get the mission from Lv airport)

how would i do that? any Examples, or tutorials on how to get the nearest airport / location?
Reply
#2

Use different distances in isplayerinrangeofpoint and loop trough them
Reply
#3

Quote:
Originally Posted by milanosie
Посмотреть сообщение
Use different distances in isplayerinrangeofpoint and loop trough them
Can you cite an example of how would i do that... It's very hard in every part of scripting when i'm still a noob :P
EDIT: I have read through wiki about that function and I will try it... And what do you mean by looping through them?
Reply
#4

pawn Код:
Float:GetDisFromPlayerToPoint(playerid,Float:x,Float:y,Float:z)
{
    new Float:xp,Float:yp,Float:zp;
    GetPlayerPos(playerid,xp,yp,zp);
    return floatsqroot(floatpower(floatabs(floatsub(x,xp)),2)+floatpower(floatabs(floatsub(y,yp)),2)+floatpower(floatabs(floatsub(z,zp)),2));

}
GetClosestAirport(playerid)
{
    new Airport = -1;
    new Float:dis = 999999.0;
    for(new x = 0 ; x < sizeof(Airports); x++)
    {
        if(GetDisFromPlayerToPoint(playerid,Airports[x][0],Airports[x][1],Airports[x][2]) < dis)
        {
            dis = GetDisFromPlayerToPoint(playerid,Airports[x][0],Airports[x][1],Airports[x][2]);
            Airport = x;
        }
    }
    return Airport;
}
Hope will help
Reply
#5

just add break; after Airport = x; cuz there is no need to loop through all airports if you are near first one in array
Reply
#6

Quote:
Originally Posted by ikey07
Посмотреть сообщение
pawn Код:
Float:GetDisFromPlayerToPoint(playerid,Float:x,Float:y,Float:z)
{
    new Float:xp,Float:yp,Float:zp;
    GetPlayerPos(playerid,xp,yp,zp);
    return floatsqroot(floatpower(floatabs(floatsub(x,xp)),2)+floatpower(floatabs(floatsub(y,yp)),2)+floatpower(floatabs(floatsub(z,zp)),2));

}
GetClosestAirport(playerid)
{
    new Airport = -1;
    new Float:dis = 999999.0;
    for(new x = 0 ; x < sizeof(Airports); x++)
    {
        if(GetDisFromPlayerToPoint(playerid,Airports[x][0],Airports[x][1],Airports[x][2]) < dis)
        {
            dis = GetDisFromPlayerToPoint(playerid,Airports[x][0],Airports[x][1],Airports[x][2]);
            Airport = x;
        }
    }
    return Airport;
}
Hope will help
How do I integrate it with the airports?, ( so if a checkpoint is in Lv airport, it will just check if the player is in range then get's a mission from that airport )
Reply
#7

Quote:
Originally Posted by CoaPsyFactor
Посмотреть сообщение
just add break; after Airport = x; cuz there is no need to loop through all airports if you are near first one in array
If you break; it'll always select the first item in the array. You need to loop through them ALL to see which one is the closest. The first equation in the loop will always be lower then 999999.0.
Reply
#8

pawn Код:
new Float:Airports[][3] = {
{X,Y,Z},
{X,Y,Z},
{X,Y,Z},
{X,Y,Z}
};
Put this at top, where X,Y,Z is all points which should be checked to find closest
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)