Home   Help Search Login Register  

Author Topic: closest unit in array(or something crappy like that)  (Read 706 times)

0 Members and 1 Guest are viewing this topic.

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Hi m8s, how's it going? Seen any dancing bananas latley? No? Then you have to help me with my problem here. Great, I appricate it m8y.

I'm feeling a little sweety. My hands are shaking. A deep breath. Inhale. And exhale. Ahhh... Oh no... I can't make it... It was too long ago. I have forgot how you ask these questions. Lucky I have my banana with me. Puh! A new deep breath. Ahhhh... OK, let's go.

Here they are. Don't get panic. Stay calm. Tell them my problem now, common, say it...


- Uh... Hi... Missed me...?

*crowd is completley silent*

- Uh... No... Uh... *coughs* I *cough* have a small problem here...

*crowd goes wild... uh... not in that way*

- YOU F*CKING IDIOT ARMSTY! GO AND TRY YOURSELF! DO NOT BURDEN US NO MORE! YOU ARE NOW BANNED FROM OFPEC FOREVER!!! AHAHAHAHAHA!!! AHAHAHAHAHA!!! FOREVER!!! AAAAAAAAAAAAAAHAHAHAHAHA!!! *coughs* *coughs* *coughs* *coughs* [size=0.5]Could some1 give me some water please?[/size]

.................................................................................................. .....................

OK, so I have these guys, and I want to see which one is closest to the player, the closest person gets this marker on him. My OFP skills are a little dusty so I hope u understand :)

I've got to writing the guys in an array but then it got locked... I have no idea what to do later on.

I think it must be something like:

Code: [Select]
#loop

~1

_array1 = [person1,person2,person3,etc]

_closest = some crappy code here I dont know wtf to write

"marker" setmarkerpos getpos _closest

goto "loop"

:beat: *Gets (ar)rayed* :beat:

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:closest unit in array(or something crappy like that)
« Reply #1 on: 04 Jan 2004, 06:25:10 »
Hmm... something like this maybe? ;)

Code: [Select]
#loop

~1

_array1 = [person1,person2,person3,etc]

_i = (count _array1) - 1
_closest = _array1 select _i

#closestloop
~0.1
_i = _i - 1
? ((_array1 select _i) distance player) < (_closest distance player): _closest = (_array1 select _i)
? _i > 0: goto "closestloop"

"marker" setmarkerpos getpos _closest

goto "loop"

Try that out... it's untested, and it's been a fair while since I wrote any OFP scripting so go easy on it ;D

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:closest unit in array(or something crappy like that)
« Reply #2 on: 04 Jan 2004, 12:43:21 »
OK, Sui thx m8. I'll check that out soon. :)

:beat: *Gets Suicided* :beat:

deaddog

  • Guest
Re:closest unit in array(or something crappy like that)
« Reply #3 on: 04 Jan 2004, 16:36:50 »
Try this:


Code: [Select]
_array1 = [person1,person2,person3,etc]

_dis=999999
_closest=0

{_d=player distance _x;if (_d<_dis) then {_dis=_d;_closest=_x}} foreach _array1

"marker" setmarkerpos getpos _closest

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:closest unit in array(or something crappy like that)
« Reply #4 on: 04 Jan 2004, 18:22:32 »
too bad the site is still not fully back up, as if i remember
right: there should be a function available, doing exactly
what you want Armsty

Maybe you do a search thru the forum, as the creation
of this function could have made somewhere in the forums
too  ;)

let's say: closest unit array
could be good words to start the search  ;D

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:closest unit in array(or something crappy like that)
« Reply #5 on: 04 Jan 2004, 18:57:10 »
I used deaddog's cause it have lesser typing(and it looks more cool with shit I've never seen :) ). Thx every1!

:beat: *Gets Locked* :beat:

EDIT: Uhm, yea, just a small Q again. How do I found out who's _closest? I tried ? _closest == person1 but that doesn't seem to work. Any ideas?
« Last Edit: 04 Jan 2004, 19:01:28 by The real Armstrong »

deaddog

  • Guest
Re:closest unit in array(or something crappy like that)
« Reply #6 on: 04 Jan 2004, 19:25:29 »
Quote
? _closest == person1
That should work (if person1 is the closest).  What does it do or not do?

Also, did the marker get set to the right location?

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:closest unit in array(or something crappy like that)
« Reply #7 on: 04 Jan 2004, 19:50:02 »
ya, the marker worked. I have put this in a line:

? closestIP == JerSon : _close = "blahblah"
? closestIP == JerPef : _close = "blahblah2"

etc.

Doesn't seem to work(I've changed person1, person2 and _closest in your script)

:beat: *Gets Shot* :beat:

EDIT: I used Sui's script instead and it works now. Must have been me who messed around with something I didn't understood in deaddogs script.

:beat: *Gets Locked* :beat:
« Last Edit: 04 Jan 2004, 21:17:26 by The real Armstrong »