Getting the nearest airport -
Neil. - 11.05.2012
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?
Re: Getting the nearest airport -
milanosie - 11.05.2012
Use different distances in isplayerinrangeofpoint and loop trough them
Re: Getting the nearest airport -
Neil. - 11.05.2012
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?
Re: Getting the nearest airport -
ikey07 - 11.05.2012
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
Re: Getting the nearest airport -
CoaPsyFactor - 11.05.2012
just add break; after Airport = x; cuz there is no need to loop through all airports if you are near first one in array
Re: Getting the nearest airport -
Neil. - 11.05.2012
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 )
Re: Getting the nearest airport -
Haydz - 11.05.2012
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.
Re: Getting the nearest airport -
ikey07 - 11.05.2012
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