Jump to content
eviljack109

How to make an objective to clear a minefield?

Recommended Posts

I have a Minefield use'ing the A3 mine Module, but I have now idea to make a trigger fire when all the mines are deactivated.

 

I know it needs to be something like this...

if allMines are Active then don't activate...

 

or something like that. My scripting is still very rough so I am just lost on where to start to get that to where I want it.

Share this post


Link to post
Share on other sites

Not sure exactly how you would write it without playing around with the editor myself, but could you perhaps count the number of active mines, and once that count reaches zero, the trigger would fire?

 

 

 

Share this post


Link to post
Share on other sites

Somehing along the lines of... Not tested.

waitUntil { {!mineActive _x} forEach allMines };

Note that allMines means all on map. I believe this applies to user placed so might be better to do distance check or just use nearestObjects or some other command.

 

EDIT:

Quote

In Arma 3, nearestObjects is partially broken and is unable to return nearby placed explosive charges or mines when searching by classnames. Use nearObjects, nearestObject or allMines instead.

 

Share this post


Link to post
Share on other sites

@HazJ Will give that a try now will let you know. I'm hoing to try an put it in the activation field of the trigger

Share this post


Link to post
Share on other sites

@HazJ I got the following error, when putting where I said I did...

 

'call{waitUntil { {!mineActive _x} forEach allMines };}'
Error Generic error in expression.

 

Share this post


Link to post
Share on other sites

In trigger condition:

{!mineActive _x} forEach allMines

 

Share this post


Link to post
Share on other sites
11 minutes ago, HazJ said:

In trigger condition:


{!mineActive _x} forEach allMines

 

Not getting any sort of error. But not matter what I set the activation type to (i.e. "game logic" or "anybody") The trigger just won't fire.

Share this post


Link to post
Share on other sites

All mines must be deactivated. Mines must be active to start with. ALL mines (every single one is checked for !mineActive or at least should). For now, create one mine and name it testMine then change cond to:

!mineActive testMine

If that works... Try with multiple placed mines.

{!mineActive _x} forEach [testMine1, testMine2];

Then lastly, try the one with allMines above I sent you.

  • Like 1

Share this post


Link to post
Share on other sites

@HazJ Test Results:

!mineActive testMine

Placed one mine down like you said and disarmed it. Trigger fired.

{!mineActive _x} forEach [testMine1, testMine2];

Placed another mine down, and like last time. The trigger went off.

{!mineActive _x} forEach allMines

Did not make any changes to the mines that I placed down. The trigger did NOT fire with this condition

Share this post


Link to post
Share on other sites

Try:

{!mineActive _x} count allMines < 1

  • Like 1

Share this post


Link to post
Share on other sites
2 minutes ago, HazJ said:

Try:

{!mineActive _x} count allMines < 1

Sorry no, that just fired the trigger on the spot.

 

Share this post


Link to post
Share on other sites

Change back to:

{!mineActive _x} forEach allMines

In debug console put:

hintSilent format [":: %1", allMines];

What does it show? As said previously, this will check for every mine. This is to make sure there are no others.

 

EDIT: You can use apply command to check if mine is X distance in in list X or whatever. allMines returns array so.

https://community.bistudio.com/wiki/apply

I'll post example tomorrow. Sleep now... ZzZzZz

Share this post


Link to post
Share on other sites

And these were placed and both deactivated?

Share this post


Link to post
Share on other sites

oh sorry, That was what I got before I deactivated the mines. This is what I got when I difused them... 

::[]

 

Share this post


Link to post
Share on other sites

Sorry for the necro, but this was my problem today and the thread does not contain an optimal solution, so I'll post my solution for others:

 

{mineActive _x && _x distance minefield_1 < 30} count allMines == 0

 

'minefield_1' is the name I assigned to the minefield module, but it can be any kind of object, gamelogic etc.

Share this post


Link to post
Share on other sites

allmines count only active mines anyway...

The only weird deactivated mines count by allmines are:  deactivated mines of dispenser (LAW DLC).

Once deactivated, these mines (from dispenser) become empty objects (p3d) but stay kind of "APERSMineDispenser_Mine_Ammo",  invisible (and inactive). :hehe:

 

Share this post


Link to post
Share on other sites

In the minefield modules init place...

Spoiler

nul = this spawn {
	params[ "_minefieldModule" ];
	
	if !( isServer ) exitWith {};
	
	waitUntil{ time > 0 };
	
	_mineType = _minefieldModule getVariable "minestype";
	_areaX = parseNumber ( _minefieldModule getVariable "axisa" );
	_areaY = parseNumber ( _minefieldModule getVariable "axisb" );
	_isRectangle = _minefieldModule getVariable "shape" == "rectangle";
	_dir = getDir _minefieldModule;	
	
	_mineAmmo = getText( configFile >> "CfgVehicles" >> _mineType >> "ammo" );	
	
	_largestAxis = ( _areaX max _areaY ) * ( [ 1, 1.4142 ] select _isRectangle );
	_mines = _minefieldModule nearObjects [ _mineAmmo, _largestAxis ] select{ _x inArea[ getPosATL _minefieldModule, _areaX, _areaY, _dir, _isRectangle ] };
	
	waitUntil{ { mineActive _x }count _mines == 0 };
		
	hint "All mines cleared";
};

 

Created a FB ticket to get the mines created by the module to be referenced on the module( so you can get them by getVariable ).

  • Like 3

Share this post


Link to post
Share on other sites

Larrow's solution seems quite generic (I personally consider this to be something good) and, most probably, works for most (if not all) situations. One possible tweak (one I always struggle for) is to change count to findIf, which will terminate as soon as the condition returns true, so you won't have to go through the whole array every time. This could look like (showing only the waitUntil part)

waitUntil {
	_mines findIf {mineActive _x;} == -1;
};

Now, especially if you don't have many mines in this minefield of yours, the benefit from this change could be negligible (haven't performed any tests and I don't have any idea as to how CPU intense mineActive command is). Nevertheless, I do believe it's a good habit to try and optimise the code if you can, especially if the syntax is not affected (a lot).

 

One more thing to add would be a sleep command in order to save some CPU cycles. Checking (almost) every frame doesn't provide much of a functionality improvement while using CPU for no good reason (in my opinion of course). This could look like

waitUntil {
	sleep 5; // Tweak value to meet your requirements
	_mines findIf {mineActive _x;} == -1;
};

Apart from those two, I believe that Larrow's response should be fine. Well, I think it's already fine, but I do believe you could benefit a wee bit from those two small changes, especially from the second one (sleep command).

 

Hope this helped at least a wee bit.

 

Have fun and ArmA a lot.

  • Like 1

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

×