Jump to content
Ombra_ita

[Ombra] Random Minefield Script/function

Recommended Posts

What does this script do?

This script creates a minefield with a random number of mines and IED, positioning them in a random way inside the given area.

Does not include APERSTripMine (mines with cable)

 

Does it work in multiplayer?

Yes, it works in MultiPlayer and SinglePlayer

 

Parameters

_area → Marker → Set a marker area with the size you like in editor

_minMinesCount → int → Minimum number of mines you want in the area

_maxMinesCount → int → Maximum number of mines you want in the area

 

How do I call the script?

Just get into your init.sqf and place it like this, has to be server only.

If you have multiple minefields you have to add multiple lines with each marker and number of mines.

if (isServer) { ["MarkerName", 10, 30] execVM "randomMinefield.sqf"; };

 

Next improvements

- Will use marker position and specified range manually instead of marker size which is not very handy.

 

randomMinefield.sqf (thanks to Hypoxic125 for the error feedback)

//Uncomment following if used as function
//params["_area", "_minMinesCount", "_maxMinesCount"];
//Uncomment following if used as script
_area = _this select 0;
_minMinesCount = _this select 1; 
_maxMinesCount = _this select 2;

_minesArray = ["ATMine","APERSBoundingMine","APERSMine","IEDLandBig_F","IEDUrbanBig_F","IEDUrbanSmall_F","IEDLandSmall_F"];
_minesCountInArea = random[_minMinesCount, _maxMinesCount/2, _maxMinesCount];
_areaDimensions = getMarkerSize _markerArea;
_minesPositionRange = _areaDimensions select 0;

//Creating random position and spawning mines
for "_i" from 0 to _minesCountInArea - 1 do {
  _randomPos = [[_markerArea], []] call BIS_fnc_randomPos;
  _randomPos set [2, 0];
  createMine[selectRandom _minesArray, _randomPos, [], 0];
}

 

Share this post


Link to post
Share on other sites

Your script will mess up when it comes to z values returned by BIS_fnc_randomPos. You need to make sure that Z value is 0 so that mines stay with the terrain rather than in the air, or severely underground.

 

Consider:

 

params [
  ["_area", "", [""]],
  ["_minMinesCount", 0, [-1]],
  ["_maxMinesCount", 0, [-1]]
];

private _debug = true;

private _minesArray = [
  "ATMine",
  "APERSBoundingMine",
  "APERSMine",
  "IEDLandBig_F",
  "IEDUrbanBig_F",
  "IEDUrbanSmall_F",
  "IEDLandSmall_F"
];

private _minesCountInArea = random [_minMinesCount, _maxMinesCount / 2, _maxMinesCount];

for "_i" from 0 to _minesCountInArea - 1 do {
  private _pos = [[_area], []] call BIS_fnc_randomPos;
  _pos set [2, 0]; //this is the key line
  private _mine = createMine [selectRandom _minesArray, _pos, [], 0];

  if (_debug) then {
    private _markerName = format ["%1_marker", _mine];
    private _marker = createMarker [_markerName, _pos];
    _marker setMarkerColor "ColorRED";
    _marker setMarkerType "mil_dot";
    _marker setMarkerShape "ICON";

    private _pos = getPosATL _mine;
    private _arrow = createVehicle ["Sign_Arrow_F", _pos, [], 0, "CAN_COLLIDE"];
  };
};

 

Share this post


Link to post
Share on other sites
On 2/9/2023 at 6:38 AM, Hypoxic125 said:

Your script will mess up when it comes to z values returned by BIS_fnc_randomPos. You need to make sure that Z value is 0 so that mines stay with the terrain rather than in the air, or severely underground.

 

Consider:

 


params [
  ["_area", "", [""]],
  ["_minMinesCount", 0, [-1]],
  ["_maxMinesCount", 0, [-1]]
];

private _debug = true;

private _minesArray = [
  "ATMine",
  "APERSBoundingMine",
  "APERSMine",
  "IEDLandBig_F",
  "IEDUrbanBig_F",
  "IEDUrbanSmall_F",
  "IEDLandSmall_F"
];

private _minesCountInArea = random [_minMinesCount, _maxMinesCount / 2, _maxMinesCount];

for "_i" from 0 to _minesCountInArea - 1 do {
  private _pos = [[_area], []] call BIS_fnc_randomPos;
  _pos set [2, 0]; //this is the key line
  private _mine = createMine [selectRandom _minesArray, _pos, [], 0];

  if (_debug) then {
    private _markerName = format ["%1_marker", _mine];
    private _marker = createMarker [_markerName, _pos];
    _marker setMarkerColor "ColorRED";
    _marker setMarkerType "mil_dot";
    _marker setMarkerShape "ICON";

    private _pos = getPosATL _mine;
    private _arrow = createVehicle ["Sign_Arrow_F", _pos, [], 0, "CAN_COLLIDE"];
  };
};

 

Thank you for your feedback. I will edit the main code!

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

×