OFPEC Forum

Addons & Mods Depot => OFP - Addons & Mods General => Topic started by: Sniperwolf572 on 15 Dec 2005, 23:42:50

Title: Nearest object that does not include player
Post by: Sniperwolf572 on 15 Dec 2005, 23:42:50
I'm trying to script something but I've ran into a problem, I'm trying to do something in condition field of UserActions in a certain config.cpp of an addon, the line goes like this:

Code: [Select]
condition="this distance (nearestObject [this, ""TEN_TestMarine""]) <2";
The code works fine, but the problem is that script detects me, because I'm the same unit class (TEN_TestMarine) and I have another unit of that class 50m away, condition triggers right away because it detects me as that class, but I want it not to detect me, but the next closest soldier of the same class.

Is there any way to do this?
Title: Re:Nearest object that does not include player
Post by: THobson on 17 Dec 2005, 10:00:18
I can't think of a way of doing this I'm afraid.
Title: Re:Nearest object that does not include player
Post by: 456820 on 17 Dec 2005, 10:10:34
if this is about a config.cpp shouldnt it be placed under Addon editing ?

anyay im not sure about an answer either
Title: Re:Nearest object that does not include player
Post by: macguba on 17 Dec 2005, 12:07:52
Welcome to the forum!

Well I can figure out an answer, but it's not pretty.   And I'm not sure if it will work in an addon, since I don't know about addons.

Create a gamelogic.   Run the nearest object test on the gamelogic:  test the result to see if its the player or another unit.   If its another unit stick it in an array.    Move the gamelogic to its next location and repeat.    At the end you'll have an array of candidate objects:  run distance or other tests on them to discover the one you want.

You'll need to experiment to discover the best pattern for the gamelogic's movements.  For example you might start it 10m north of the player, then 10m east, west and south.   Then 15m NE, SE, SW and NW.    Similarly at 20m out and so on.    Or something.
Title: Re:Nearest object that does not include player
Post by: Sniperwolf572 on 03 Jan 2006, 00:24:12
OK, Issue solved by using:

Code: [Select]
condition="(This!=Player) And ((GetDammage This >0.7) And (GetDammage This <0.95))";
on the units, thanks to UNN for assistance.

EDIT:
@macguba:

Date Registered:     July 08, 2003, 12:22:26 AM

 :P