Home   Help Search Login Register  

Author Topic: finding the smallest distance (tough)  (Read 569 times)

0 Members and 1 Guest are viewing this topic.

Offline .pablo.

  • Former Staff
  • ****
  • When in doubt, empty the magazine.
finding the smallest distance (tough)
« on: 23 Jul 2003, 04:02:58 »
say i have 7 cars, and i want a soldier to get in the closest one with the least code

how do i do it?

deaddog

  • Guest
Re:finding the smallest distance (tough)
« Reply #1 on: 23 Jul 2003, 05:31:24 »
Try this:

Create this script:

;closestcar.sqs

cars=[car1,car2,car3, etc] <<< create array of car names

_u=_this select 0

_dis=999999
_closestcar=car1

{_d=_u distance _x;if (_d<_dis) then {_dis=_d;_closestcar=_x}} foreach cars

_u domove getpos _closestcar

exit


call the script like this:  [nameofsoldier] exec "closestcar.sqs"



Offline .pablo.

  • Former Staff
  • ****
  • When in doubt, empty the magazine.
Re:finding the smallest distance (tough)
« Reply #2 on: 23 Jul 2003, 17:54:15 »
i didn't know foreach could be used like that!

thanks!