Jump to content
Sign in to follow this  
sproyd

Trying to spawn mines only once a Trigger is activated. Need help.

Recommended Posts

So I am creating a mission whereby a squad of enemies race around the map dropping mines. To simulate this I have created Triggers to detect once the enemies have passed a set location and once these Triggers are activated I'd like for mines to appear.

I tried a hideObject true script in my init.sqf for the mines to then be reversed with a hideObject false script to be executed in the Trigger Activation box. However, the mines won't hide upon mission launch.

The Trigger is just a basic Once Present Trigger with a TimeOut (so the enemy don't set off the mines) but regardless the mines don't seem to invisible themselves upon load.

Can someone tell me what I'm doing wrong?

{_x hideObject true;} forEach [mine5, mine6, mine7, mine8, apmine5, apmine6, apmine7, apmine8] ;//script to hide mines for spawning later

Any other ideas about how to spawn these mines in set locations would be appreciated.

Edited by sproyd

Share this post


Link to post
Share on other sites

What is the trigger condition?

Edit: nvm you tried it in init.sqf as well

Seems like hideObject does not work on mines.

You could just move them down a bit

{_x setposATL [getPosATL _x select 0,getPosATL _x select 1,(getPosATL _x select 2)-1]} forEach [mine5, mine6, mine7, mine8, apmine5, apmine6, apmine7, apmine8] ;//script to hide mines for spawning later

When you want to "spawn" them, just move them up one meter.

Edited by cuel

Share this post


Link to post
Share on other sites

Could you not just use the mines module (modules->Sites->Minefield) Set the module up with who laid the mines, area to cover, type and number of mines then in the condition of the module ('condition', not 'condition of presence') place

triggerActivated myTrigger

. Place your trigger down and name it myTrigger. Once the trigger is activated the module will place the mines down for you.

EDIT: Ok the next post i opened was one with you replying about how to check if mines have been deactivated.

So just to cover all bases in case its these mines you need to check for. The mines module does not keep a list anywhere of the mines it creates.

If you setup a global variable in your init.sqf

mines = [];

then names your mines module e.g mineArea1 then in the trigger in the OnAct write

_handle = [] spawn {
sleep 1;
_objects = minearea1 nearobjects ["minebase", 5];
mines = mines + _objects;
};

no matter how many of these modules you have each minearea# trigger will add the mines created to the mines array.

Then when you want to check the mines something like

{mineActive _x} count mines == 0

will tell you they are all deativated.

Edited by Larrow

Share this post


Link to post
Share on other sites

Hi Larrow

Your minefield module idea is excellent and works well. The module activates once my trigger is activated (Enemy Vehicle present with 3 second countdown to ensure they have cleared the area), however I can't get the mines array to work with the code you gave. What does "minebase", 5 mean exactly?

---------- Post added at 22:45 ---------- Previous post was at 22:44 ----------

Could there be a problem that the mines array is 0 upon mission launch and doesn't gain values until later in the mission at which point the Task Complete Trigger has already activated (but prior to Task Creation so doesn't get ticked in the Task Browser?)

Share this post


Link to post
Share on other sites
What does "minebase", 5 mean exactly?

MineBase is the parent class of mines, 5 is meters, so _objects = minearea1 nearobjects ["minebase", 5]; _objects equals all objects of type minebase within 5 meters of minearea1.

Could there be a problem that the mines array is 0 upon mission launch and doesn't gain values until later in the mission at which point the Task Complete Trigger has already activated (but prior to Task Creation so doesn't get ticked in the Task Browser?)

Sounds highly possible. Maybe you could put an extra condition in the Task Completion Trigger, something along the lines of
(["MinesTaskID"] call BIS_fnc_taskExists && {mineActive _x} count mines == 0)

and maybe also that some mines actually exist

(((["MinesTaskID"] call BIS_fnc_taskExists) && (count mines > 0)) && {mineActive _x} count mines == 0)

So the trigger is not going to fire until the task actually exists. Its all dependant on how you got things setup really, when are the mines spawning, when is the task being created etc.

Edited by Larrow

Share this post


Link to post
Share on other sites

I finally got it working. The trick was all about timing and the order of execution of scripts and trigger activation. The trick was to create another erroneous variable i.e. mines1go, that would be set to true only once the mines1 array had been filled.

So in summary I created a trigger to activate once the enemy had passed through, and on a 3 second timeout. The trigger was named minefieldtrigger1

The minefield module then has a Condition of

triggerActivated minefieldtrigger1

Which creates the minefield and is also sync'd to the Create Task Module so creates the task to clean up the minefield.

Then the already activated minefield1trigger Trigger, subsequently executes the following script

_handle = [] spawn {
sleep 4;
mines1 = position mineArea1 nearobjects ["minebase" , 20];
sleep 1;
mines1go = true;
};

In order to fill the mines1 array with all of the mines created in a 20m radius and subsequently creates another variable called mines1go. The condition of task succeed is therefore

 ({mineActive _x} count mines1 == 0) 
&& 
mines1go

Otherwise the task would succeed before the minefield1trigger has a chance to fill the mines1 array.

Anyway, as usual there are a million ways to do things in the editor but I was happy to get this to work :)

---------- Post added at 18:44 ---------- Previous post was at 16:51 ----------

Oh and I don't think m6 SLAM mines are covered under minebase for some reason?

Edited by sproyd

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  

×