Jump to content
R3vo

Returning nearest mine reliably around player

Recommended Posts

I am searching for a way to return all sorts of mines (IEDs, tripwire, AT so on and so forth) reliably around the player. Looping through allMines is not an option.

 

I found out that nearestObject [player, mineBase]; only returns AT mines for some reason. Does anyone know the other base classes?

_mine = nearestObject [player, "mineBase"]; //returns "UnderwaterMineAB_Range_Ammo","ATMine_Range_Ammo","APERSMine_Range_Ammo","UnderwaterMine_Range_Ammo";

I am still missing the tripwire, bounding, slam and ieds.

 

 

 

 

Edit: I fixed the issue by sorting the array returned by allmines by distance.

Revo_fnc_sortMinesDistance =
{
//by jezuro
_unsorted = _this select 0;
_sortedMines = [];
_pos = position player;

{
     _closest = _unsorted select 0;
     {if ((position _x distance _pos) < (position _closest distance _pos)) then {_closest = _x}} forEach _unsorted;
     _sortedMines = _sortedMines + [_closest];
     _unsorted = _unsorted - [_closest]
} forEach _unsorted;

_sortedMines
};

If anyone has got a faster alternative please let me know.

Share this post


Link to post
Share on other sites

The thing I dislike of your code is (position _closest distance _pos).. you know already the distance from the closest to _pos, so store it in a variable, if not, the command is executed on every iteration.

 

Anyway, you should check BIS_fnc_sortBy, which maybe suits your needs.

Share this post


Link to post
Share on other sites

The thing I dislike of your code is (position _closest distance _pos).. you know already the distance from the closest to _pos, so store it in a variable, if not, the command is executed on every iteration.

 

Anyway, you should check BIS_fnc_sortBy, which maybe suits your needs.

 

 

Thanks for your feedback, but position _closest may change on each run until the array is completely sorted. Anyways, I replaced this function with BIS_fnc_sortBy.

 

 

nearestObject [player, "MineGeneric"]

 

 

Thanks, may I know from where you've got that MineGeneric class ?

 

Edit: Tested your code, it unfortunately does also not detect all type of mines.

Share this post


Link to post
Share on other sites

 

 

Edit: Tested your code, it unfortunately does also not detect all type of mines.

What fails?

Share this post


Link to post
Share on other sites

Nothing fails, it simply does not detect tripwire mines and if I remember correctly slam mines.

Share this post


Link to post
Share on other sites

Mine detection is all kinds of FUBAR.. 

 

nearestObject [player,"TimeBombCore"]
 

TimeBombCore will detect most explosives....

 

"APERSBoundingMine_Range_Ammo"

"APERSMine_Range_Ammo"

"APERSTripMine_Wire_Ammo"

"ATMine_Range_Ammo"

"ClaymoreDirectionalMine_Remote_Ammo"

"DemoCharge_Remote_Ammo"

"IEDLandBig_Remote_Ammo"

"IEDLandSmall_Remote_Ammo"

"IEDUrbanBig_Remote_Ammo"

"IEDUrbanSmall_Remote_Ammo"

"SatchelCharge_Remote_Mag"

"SLAMDirectionalMine_Wire_Ammo"

"UnderwaterMineAB_Range_Ammo",

"UnderwaterMine_Range_Ammo",

"UnderwaterMinePDM_Range_Ammo"

 

MineGeneric [ x, found, x, found, x, x, x, x, x, x, x, x, found, found, found ]
MineBase [ x, found, x, found, x, x, x, x, x, x, x, x, found, found, found ]
TimeBombCore [ found, x, found, x, found, found, found, found, found, found, found, found, x, x, x ]
Same order as listed above. Note the classes not detected by TimeBombCore, yet..

"APERSMine_Range_Ammo" isKindOf "TimeBombCore"  //true

"TimeBombCore" in ([(configfile >> "CfgAmmo" >> "APERSMine_Range_Ammo"),true] call BIS_fnc_returnParents) //true

"ATMine_Range_Ammo" isKindOf "TimeBombCore" //true

"TimeBombCore" in ([(configfile >> "CfgAmmo" >> "ATMine_Range_Ammo"),true] call BIS_fnc_returnParents)  //true
"UnderwaterMineAB_Range_Ammo" isKindOf "TimeBombCore" //true

"TimeBombCore" in ([(configfile >> "CfgAmmo" >> "UnderwaterMineAB_Range_Ammo"),true] call BIS_fnc_returnParents) //true
"UnderwaterMine_Range_Ammo" isKindOf "TimeBombCore" //true

"TimeBombCore" in ([(configfile >> "CfgAmmo" >> "UnderwaterMine_Range_Ammo"),true] call BIS_fnc_returnParents) //true
"UnderwaterMinePDM_Range_Ammo" isKindOf "TimeBombCore" //true

"TimeBombCore" in ([(configfile >> "CfgAmmo" >> "UnderwaterMinePDM_Range_Ammo"),true] call BIS_fnc_returnParents) //true
 

You could do something like...

_mines = [ nearestObject [ player, "MineBase" ], nearestObject [ player, "TimeBombCore" ] ];
_nearest = [ +_mines, [], { _x distanceSqr player }, "ASCEND", { !isNull _x } ] call BIS_fnc_sortBy select 0;
If you dont want to iterate allMines
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks for your input Larrow, definitely gonna try that, it should improve performance quite abit. In addition I'll open a Ft ticket since in my opinion all mines should inherit from mineBase or mineGeneric.

 

 

Edit: Your code works like a charm.

 

 

Thanks to everyone for your input !

 

 

http://feedback.arma3.com/view.php?id=26908

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

×