[HELP]Get nearest to farthest
#1

I got myself this script, out of another script but see this:
pawn Код:
getNearestPizzeria(Float:X1,Float:Y1,Float:Z1)
  {
    new index;
    new Float:distOld=9999.0;
    new Float:distNew=0.0;
    for (new i=0;i<cantidadPizzerias;i++)
      {
      distNew=floatsqroot(floatpower(floatabs(floatsub(Pizzerias[i][X],X1)),2)+floatpower(floatabs(floatsub(Pizzerias[i][Y],Y1)),2)+floatpower(floatabs(floatsub(Pizzerias[i][Z],Z1)),2));
      if    (distNew<distOld)
        {
        distOld=distNew;
        index=i;
        }
      }
    return index;
  }
Pizzeria = airport

But that doesn't matter.
What matters is there are 3 airports and if you enter a checkpoint at these you get money, now your first checkpoint is the nearest airport, so if you go stand on the runway in the checkpoint and keep starting/stopping the job, you get tons of money without doing anything, thats why i want you to ask me if you could give me a way te get the Farthest one and not the Nearest.

Could you help me please?
Thanks in advance!!
Reply
#2

pawn Код:
getNearestPizzeria(Float:X1,Float:Y1,Float:Z1)
{
    new index;
    new Float:distOld;
    new Float:distNew;
    for(new i; i<cantidadPizzerias; i++)
    {
        distNew=floatsqroot(floatpower(floatabs(floatsub(Pizzerias[i][X],X1)),2)+floatpower(floatabs(floatsub(Pizzerias[i][Y],Y1)),2)+floatpower(floatabs(floatsub(Pizzerias[i][Z],Z1)),2));
        if(distNew > distOld)
        {
            distOld=distNew;
            index=i;
        }
    }
    return index;
}
Reply
#3

Quote:
Originally Posted by Jefff
pawn Код:
getNearestPizzeria(Float:X1,Float:Y1,Float:Z1)
{
    new index;
    new Float:distOld;
    new Float:distNew;
    for(new i; i<cantidadPizzerias; i++)
    {
        distNew=floatsqroot(floatpower(floatabs(floatsub(Pizzerias[i][X],X1)),2)+floatpower(floatabs(floatsub(Pizzerias[i][Y],Y1)),2)+floatpower(floatabs(floatsub(Pizzerias[i][Z],Z1)),2));
        if(distNew > distOld)
        {
            distOld=distNew;
            index=i;
        }
    }
    return index;
}
Thanks man! Didn't see that :P, just looked over it
You're the best!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)