Please write code for an Arma 3 function called fnc_generateMinefieldData. Parameters:…
- User
Please write code for an Arma 3 function called fnc_generateMinefieldData. Parameters: minefieldArea – Defines a polygon. The polygon can be of any shape. All coordinates for mines should be within that polygon. Do not allow the coordinates outside of the polygon.
mineType – Defines the type for the mines inside the polygon. mineQuantity – Defines the number of mines in the minefield.
The function should generate the coordinates for each mine and return an array that contains 1. An array with the coordinates of each mine. 2. the type of mines in the minefield.
Ensure that the code is compatible with a dedicated server.
- Assistant
Here is an example code for the Arma 3 function "fnc_generateMinefieldData":
fnc_generateMinefieldData = { params ["_minefieldArea", "_mineType", "_mineQuantity"]; private _mineCoordinates = []; // Generate random coordinates within the given minefield area for "_i" from 1 to _mineQuantity do { private ["_x", "_y"]; private _coordinatesFound = false; // Generate random coordinates until it is within the polygon while {!_coordinatesFound} do { _x = (_minefieldArea select 0) + ((random (_minefieldArea select 2)) - 1); _y = (_minefieldArea select 1) + ((random (_minefieldArea select 3)) - 1); if (_x < (_minefieldArea select 2) && _y < (_minefieldArea select 3) && {_x > 0} && {_y > 0}) then { _coordinatesFound = true; }; }; _mineCoordinates pushBack [_x, _y]; }; [_mineCoordinates, _mineType] };