Jump to content
Sign in to follow this  
Lucky44

Landmines or Land Mines - how to make simple triggers

Recommended Posts

I've searched all over and can't find a good, simple way to do this (and I can't figure it out on my own!). What I really need is a simple way to spread a lot of landmines around a "minefield" area.

I'm thinking I just want to make a simple trigger that I can Copy/Paste all over in a minefield to create landmines (the kind that infantry can set off). So I don't want to have to name the trigger or any markers, if possible. (Because markers must be named individually.)

I don't mind if it has to use a separate script or not. And I don't mind if one trigger can cover the whole area, detecting the location of an entering infantry and exploding there (yes, that's a very deadly minefield!), or if it has to be lots of little separate triggers, each covering a small area (like 3meters).

Any suggestions? Someone must have done this already, I just can't find it.

Share this post


Link to post
Share on other sites

A lot of triggers isn't really resource-friendly. Overuse of them tends to lag the game.

However what one could do is a lot of markers (if you make a marker called "mine", then copy-paste it, your next marker will be called "mine_1", next "mine_2" etc, giving you a lot of regularily named markers.

You could then use a script running in the background, either testing against a fixed range of units (if you know what units you want to make the mines dangerous for), or in a worse case for all units, or through a trigger all units within the trigger area.

If going by the last example you could have a trigger covering the entire minefield of markers, running a script for all units inside of it.

This code is untested, but should at least point in a working direction of action. I might have borked up the trigger, since I'm not entirely sure if the trigger will reactivate itself if another person enters the area or how it works. My code assumes that it does.

Trigger:

[b]Type:[/b]
ANY PRESENT, Repeatable

[b]Condition:[/b]
this

[b]On Activation:[/b]
terminate mines; mines = thisList execVM "minefield.sqf";

[b]On Deactivation:[/b]
terminate mines;

init.sqf:

minelist = [];
for "_i" from 1 to [b]X[/b] do {    [b]// X is the number of mine_x markers you have![/b]
   _mineMrk = format ["mine_%1", _i];
   minelist set [count minelist, _mineMrk];
};

minefield.sqf:

if (!isServer) exitWith {};

while {true} do {
   {
       _unit = _x;
       {
           _pos = markerPos _x;
           if (_unit distance _pos < [b]2[/b]) then {   [b]// distance in meters from person to marker for detonation[/b]
           _boom = "someKindOfExplosive" createVehicle _pos;
           minelist = minelist - [_x];
       } forEach minelist;
   } forEach _this;
   sleep 1;
};

I'm not entirely sure how one does nested forEach-tests (and really it is not adviseable to do that at all, but if the units within the minefield won't be many at a time I guess it works), but I hope my solution works.

This script will also remove a mine from the detection-system when it is detonated.

Might take some fiddling for it to work right, but the overall structure should be good enough.

Edited by Inkompetent

Share this post


Link to post
Share on other sites

Thanks for all that effort, Inkompetent. I appreciate the help.

There won't be many units in the minefield at once (at least not BlueFor ones, and in this scenario, they're the only ones who wouldn't know where the mines were, so they're the only ones I need to test for). So the resource issue isn't bad there, in your plan, I think.

I don't quite follow the code (I'm not very familiar with local variables, truth be told).

But rather than get into details at this point, two things:

1) it's not working, as is, for me. I think I have done everything right, but no explosions.

2) I am thinking there is an easier way (see below).

What if you have one trigger covering the whole minefield (as in your idea, sort of). And, to make it simple, every X seconds that a unit enters the field, a script will generate a random number (1-100) and if it's less than, say 20, a mine will go off near the player.

That seems pretty easy except for two parts: how do I a) check where the player in the minefield is (as opposed to any other player), and b) set the explosion to go off at the player?

No markers needed. Minimal triggers...seems doable, but I can't figure out the coding of the two things above. :)

Share this post


Link to post
Share on other sites

If you want to take a quick and dirty approach - then concider defining a location to represent a minefield. then you can test for a unit "in" that minefield and spawn some mines randomly around it. Neat way to represent replacement mines that only activate on detonation of others nearby.

Share this post


Link to post
Share on other sites
If you want to take a quick and dirty approach - then concider defining a location to represent a minefield. then you can test for a unit "in" that minefield and spawn some mines randomly around it. Neat way to represent replacement mines that only activate on detonation of others nearby.

Yeah, that could work. But I'm not sure how to do the "spawn some mines randomly around it". -Actually, I can do the spawning, it's just the how to spawn them at/near it that I can't figure. I'm stuck trying to get the name of the entering unit. (And I can't just use "player" since it won't always be a player.)

The key thing I can't figure is how do something like this (I'll use pseudo-code), in the trigger or in a script it calls:

"EnteringUnit = getName this" or "EnteringUnit = getName (nearestObject BluFor)"

Any ideas?

Edited by Lucky44

Share this post


Link to post
Share on other sites

If I don't want to bother with real mines I can use this.

//////////////////////////////////////////////////////////////////
// In a game logic,units init or init.sqf file put   mineflag=true; 
//
// place a tiriger on the map where you want your mines
// set it up how you want the trigger to detect the units
// 
// Trigger settings are
// repeating
// Timers 0,2,3  
// COND this and mineflag
// ON ACT nul=[thislist]execVM "mines.sqf";mineflag=false
// ON DEA  mineflag=true
/////////////////////////////////////////////////////////////////////


_unit  = _this select 0;

//_ammo = "R_57mm_HE";
//_ammo = "B_25mm_HE";
//_ammo = "B_25mm_HEI";
_ammo = "B_30mm_HE";
_height = 0;

{_x;
if (speed _x  >=4) then { 

_rnum = round (random 7);

if (_rnum >=5) then {
_bomb = _ammo createVehicle [(getPosASL _x select 0),( getPosASL _x  select 1),_height-3];
_bomb = "GrenadeBase" createVehicle [(getPosASL _x select 0),( getPosASL _x  select 1),-40];

_xx = getdammage _x;

_x setdamage (_xx+0.4);
_x setHit ["legs",random 1.2];// 1 is full damage
_x setHit ["hands",random 1.2];
sleep random 0.6;
};
};
} foreach _unit;

All the info is in the script, it's more or less set up an anti personal mine script.

If your running or walking the mines will go off mostly damaging the legs, if you're still able to walk and it goes off again chances are your dead.

I have it set up so that crawling won,t set the mines off.

[code]

[/code]

---------- Post added at 04:42 PM ---------- Previous post was at 04:19 PM ----------

If you want to use real mines with the above script just ignore the trigger completely and use this script to call the other.

It will spawn mines around a game logic.

//////////////////////////////////////////////////////////////////
// place a game logic on the map at the center of the mine field
// place this code into the logics init line.
// null=[this,30,120] execvm "createmines.sqf" and save this script as createmines.sqf
// this = minefield center // _spread/30 is the diameter of the mine field // _mines/120 is the number of mines planted
// Adjust the values as you wish.

_pos    = _this select 0;
_spread = _this select 1;
_mines  = _this select 2;

_height = -0.08;// sink mine depth // zero is on the surface.

for [{_p = 0},{_p < _mines},{_p = _p + 1}] do
{
mine = "mineE" createVehicle [(getpos _pos select 0)+(random _spread)-_spread/2, (getpos _pos select 1)+(random _spread)-_spread/2,_height];
mine = createTrigger["emptyDetector",getPos mine];
mine setTriggerArea [1,1,0,false]; 
mine setTriggerActivation ["any","present",false]; 
mine setTriggerStatements["this","[thislist] execVM""mines.sqf""",""];
};

Edited by F2k Sel

Share this post


Link to post
Share on other sites
Yeah, that could work. But I'm not sure how to do the "spawn some mines randomly around it". -Actually, I can do the spawning, it's just the how to spawn them at/near it that I can't figure. I'm stuck trying to get the name of the entering unit. (And I can't just use "player" since it won't always be a player.)

The key thing I can't figure is how do something like this (I'll use pseudo-code), in the trigger or in a script it calls:

"EnteringUnit = getName this" or "EnteringUnit = getName (nearestObject BluFor)"

Any ideas?

Spawning nearby is easy with BIS functions and CBA. You generate a location in polar coordinates ( direction/range ) using two calls to random. Then use BIS functions to add those to current location of the target unit. Spawn your mine or explosion at the resulting location.

Share this post


Link to post
Share on other sites
Spawning nearby is easy with BIS functions and CBA. You generate a location in polar coordinates ( direction/range ) using two calls to random. Then use BIS functions to add those to current location of the target unit. Spawn your mine or explosion at the resulting location.

A) which BIS functions did you have in mind?

B) what's CBA?

Share this post


Link to post
Share on other sites

F2K Sel: thanks for that! It looks great. It's more/different than I want in this situation, but I will copy it for the future.

Share this post


Link to post
Share on other sites
A) which BIS functions did you have in mind?

B) what's CBA?

CBA is a mod that contains a number of helper functions for mission and module makers. Very handy and highly recommended.

An example of what I was talking about....

_dir = random 360;
_range = random 20;
_p1 = getPosATL _target;
_p2 = [_range, _dir, 0] call CBA_fnc_polar2vect;
_mine_location = [_p1, _p2] call BIS_fnc_vectorAdd;

Edited by Evil_Echo

Share this post


Link to post
Share on other sites

thanx alot, i'm caming creazy around this for a day:

private ["_placecounter", "_pos", "_trg"];

_placecounter = _this select 0;

//made trigger to count objects type sign_danger on marker placecounter position

_pos = [(getmarkerpos _placecounter select 0), (getmarkerpos _placecounter select 1), 0];

_trg = createTrigger ["EmptyDetector",_pos];

_trg setTriggerArea[5000,5000,0,false];

_trg setTriggerActivation["ANY","PRESENT",true];

_trg setTriggerStatements["this", "", ""];

_tlist = list _trg ;

// select the sign danger list ,make indistructible the signals,create an invisible heli landing place

// and attach the signals to avoid movement if mine explode,create the mines

if (typeof _x == "sign_danger") then

{

_x allowdamage false;

vhe = createVehicle ["helihempty", getpos _x, [], 0, "none"];

_x attachto [vhe,[-3,-3,0]];

} foreach list _tlist ;

createvehicle ["mine", getpos vhe, [], 0, "none"];

only to put mines under danger signals (is a training map for tank crew)

if i put this:

{if (typeof _x == "sign_danger") then {_x allowdamage false; vhe = createVehicle ["helih", getpos _x, [], 0, "none"]; _x attachto [vhe,[-3,-3,1.9]];}} foreach thislist ; createvehicle ["mine", getpos vhe,[-3,-3,1.9] "none"];

in a trigger it works, but i was looking around using cript to create a loop in order to respawn mines for the incaming tank, after one explode...i think i'll use your script tx, and apologize me for my "strange language :))

Share this post


Link to post
Share on other sites

heres what i use in my Battlefield missions

it may give you some ideas

you can set one side not to set them off , if you anyone to trigger them just set it to anyone

in the trigger

MineField.sqf



// Script by Zonekiller  -- http://zonekiller.ath.cx --    -- zonekiller@live.com.au --

if !(isServer) exitwith {};

private ["_base","_signpos","_s1","_side","_marker","_markercolor","_pos","_acc","_initCode","_hgt","_mine","_minefield","_minepos","_bombpos","_m"];

_base = _this select 0;
_sidebase = _this select 1;
_marker = _this select 2;
_side = "";



if (_sidebase == west) then {_side = "((resistance countside thislist > 0) or (east countside thislist > 0))"};
if (_sidebase == east) then {_side = "((resistance countside thislist > 0) or (west countside thislist > 0))"};
if (_sidebase == resistance) then {_side = "((east countside thislist > 0) or (west countside thislist > 0))"};


_markercolor = getMarkerColor _marker; 

_pos = position _base;

_minenum = 25; // bigger number more mines
_hgt = -0.01; // this is set about right for this ammo, big bang and some time you only get hurt , not die
_acc = 35; // bigger number bigger circle of spread





_initCode = "";
_mine = 0;
_minefield = [];

_signpos = [(_pos select 0) + 35, (_pos select 1),0];
_s1 = "Sign_Danger" createVehicle _signpos;
_minefield = _minefield + [_s1];
_s1 setdir 90;

_signpos = [(_pos select 0) - 35, (_pos select 1),0];
_s1 = "Sign_Danger" createVehicle _signpos;
_minefield = _minefield + [_s1];
_s1 setdir 270;

_signpos = [(_pos select 0) , (_pos select 1) + 35,0];
_s1 = "Sign_Danger" createVehicle _signpos;
_minefield = _minefield + [_s1];
_s1 setdir 0;

_signpos = [(_pos select 0) , (_pos select 1) - 35,0];
_s1 = "Sign_Danger" createVehicle _signpos;
_minefield = _minefield + [_s1];
_s1 setdir 180;

while {_mine < _minenum} do
{

_minepos = [(_pos select 0) + (random (_acc*2)) - _acc, (_pos select 1) + (random (_acc*2)) -_acc, _hgt];
_bombpos = [(_minepos select 0), (_minepos select 1), _hgt];
_initCode = "'Sh_125_SABOT' createVehicle ";
_initCode = _initCode + format["%1",_bombpos];

_m = createTrigger["EmptyDetector", _minepos];
_m setTriggerArea[1.5,1.5,0,true];
_m setTriggerActivation["ANY","PRESENT",false];
_m setTriggerTimeout[0,0,0, true ];
_m setTriggerStatements[_side, _initCode ,""];
_minefield = _minefield + [_m];
_mine = _mine + 1;

};

[_marker,_markercolor,_minefield] execVM "extras\minefield1.sqf";



and to clean them off when the base changes

MineField1.sqf



if !(isServer) exitwith {};

_marker = _this select 0;
_markercolor = _this select 1;
_minefield = _this select 2;


waituntil {(getMarkerColor _marker != _markercolor)};

{deletevehicle _x} foreach _minefield;



Edited by Zonekiller

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  

×