Jump to content
Sign in to follow this  
CarlGustaffa

findNearest(unknown)Enemy

Recommended Posts

Situation: East detects West with a detection trigger. thisList select 0 is the detected unit on west.

Now I need to find the closest enemy to west side, even if east units is not knownabout to west.

This is because east AI will fire artillery against west, but only if they have no friendlies in the area.

I'm thinking about two possible solutions, but no idea how to put it to work.

Solution 1:

Generate an array which lists all units along with their distance to given point.

Select the array entry with the smallest distance. But I don't know how to work

with arrays in this (or any for that matter) fashion. Any ideas or guidelines?

Solution 2:

Create a trigger on the detected unit that reveales _thislist select 0 (=closest?)

But if playing with extended map info or AI leaders, would generate inbalance.

Which way is the suggested way to go? And since I'm new at this, how?

Share this post


Link to post
Share on other sites

use condition: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">( (SIDE countSide ((POSITION) nearObjects ["AllVehicles", RADIUS]) ) == 0 ) replace SIDE, POSITION and RADIUS by the wanted side, position and radius

e.g:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">( (east countSide ((getPos this) nearObjects ["AllVehicles", 200]) ) == 0 )Im not sure if you can really use "getPos this", you might just have to name your trigger sth like "TestTrigger", then use "getPos TestTrigger"

You can exchange SIDE with unit, if you change countSide into countFriendly or countEnemy.

You can find the explainations etc. of the used ArmA functions at the BIKI, community.bistudio.com

Below is my first Method (but unnecessary long :P):

Quote[/b] ]You could use a function, test.sqf: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">/*

Function that searches _pos (position), within _range radius, for "AllVehicles" classed or subclassed objects, returns true if object on _side was found. returns false if no object on _side was found.

*/

private ["_pos", "_range", "_side", "_ar"];

_pos = _this select 0;

_range = _this select 1;

_side = _this select 2;

_ar = _pos nearObjects ["AllVehicles", _range];

if ( (_side countSide _ar) > 0) then

{

true

} else {

false

}

(Not tested)

in init.sqf or other initialization method: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">t_Test = compile preProcessFile "test.sqf";

You can use the following in a condition field: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">!([position, range, side] call t_Test)

exchange position, range, side for what you want to test, e.g: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">!([ [4,5,0], 200, east ] call t_Test)

or if it's in the trigger: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">!([ getPos this, 200, east ] call t_Test)

If you do not want to specify the side staticly, but instead, test for unit friendlies or enemies: exchange all _side variables to _unit and change: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> (_side countSide _ar) into <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> (_unit countFriendly _ar) or <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> (_unit countEnemy _ar)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×