Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
spitfire007

Random spawn underwater mines around a point

Recommended Posts

I am trying to make a random underwater minefield with the following code.

The idea is to create a random minefield of 10 mines around a marker within a 40 meter radius..

I am not after a circular array of mines .. I would like them placed randomly within 40 meters of the marker position.

From the wiki on createMine

Creates a mine of the given type (type is the name of the subclass of CfgVehicles). If the markers array contains several marker names, the position of a random one is used, otherwise, the given position is used. The mine is placed inside a circle with this position as its center and placement as its radius.
Object = createMine [type, position, markers, placement]

_markerPos = someMarkerOnTheMap


for "_i" from 1 to 10 do
{

_xmpos = ceil(random 40);
   _ympos = ceil(random 40);
   _zmpos = ceil(random 1);

_mine = createMine ["UnderwaterMine", _markerPos, [], 0];
   _mine setPos (getPos _mine vectorAdd [_xmpos, _ympos, 1]);

};

All this code does is put all the mines at the marker.

I thought using vectorAdd would move them but .... no.

I suppose I could use the minefield module in the editor .. but I would like to spawn them..

Share this post


Link to post
Share on other sites

I would use BIS_fnc_relPos.

_mine setPos ([_markerpos, (random 40),(random 360)] call BIS_fnc_relPos);

Or just randomize the createmine radius: 0 -> random 40

Edited by Greenfist

Share this post


Link to post
Share on other sites

Try this:

_depth = ?????; // you must put a positive number in here
_initialPos = ??????; // up to you
for "_count" from 1 to 10 do {
_minePos = [
	(_initialPos select 0) + ((random 80) - 40),
	(_initialPos select 1) + ((random 80) - 40),
	-1 * (random _depth)
];
if (surfaceIsWater _minePos) then {
	_minen = createMine [
		"UnderwaterMine",
		_minePos,
		[],
		0
	];
};
};

Untested of course ;)

You need to fill in the depth and initial position. Make sure you use a positive number for depth. (Don't use -1 or -5.6 etc). It could have another safety check in there to make sure _minePos is deep enough but I'd already typed it out so maybe next time ;)

Edited by Das Attorney

Share this post


Link to post
Share on other sites
Try this:

_depth = ?????; // you must put a positive number in here
_initialPos = ??????; // up to you
for "_count" from 1 to 10 do {
_minePos = [
	(_initialPos select 0) + ((random 80) - 40),
	(_initialPos select 1) + ((random 80) - 40),
	-1 * (random _depth)
];
if (surfaceIsWater _minePos) then {
	_minen = createMine [
		"UnderwaterMine",
		_minePos,
		[],
		0
	];
};
};

Untested of course ;)

You need to fill in the depth and initial position. Make sure you use a positive number for depth. (Don't use -1 or -5.6 etc). It could have another safety check in there to make sure _minePos is deep enough but I'd already typed it out so maybe next time ;)

Worked straight out of the box.

I particularly like the random function, very elegant.

You make it look so obvious ... I am feeling a little.... errr .. inexperienced :)

---------- Post added at 10:16 ---------- Previous post was at 10:15 ----------

I would use BIS_fnc_relPos.

_mine setPos ([_markerpos, (random 40),(random 360)] call BIS_fnc_relPos);

Or just randomize the createmine radius: 0 -> random 40

I just saw the code Das made ... I ran it and it worked ... thanks for the idea though.

---------- Post added at 10:17 ---------- Previous post was at 10:16 ----------

OR you could use the ingame module, Sites > Minefield > Underwater

Or place them individually: units > empty > mines > underwater

Yes .. that was my thinking too.

That somehow you could call that module via a script... but trawling around got me nowhere. But .. there must be a way .. there always is.

Share this post


Link to post
Share on other sites

YAY

I now have mines ....

Bloody mines ... lots of mines .. too many mines ....

I guess I need code to remove them now.

Would I be right in thinking I should add them all to an array when I place them ?... then delete them the same way ?

edit: .. had some sleep .. more time to dream in code.

I think deleteobjects is coming to the rescue here :)

Edited by spitfire007

Share this post


Link to post
Share on other sites

Delete you buggers .. delete.

Using this code (which I thought would be perfect) ... produces a syntax error in the RPT file.

{
if (_x isKindOf "UnderwaterMine") then {_x deleteVehicle};
} forEach nearestObjects [_markerpos,[],40];

Syntax is correct though .. isn't it ?

Edited by spitfire007

Share this post


Link to post
Share on other sites

It's:

deleteVehicle _x

Just go it backwards :p.

Share this post


Link to post
Share on other sites

Thanks for the replies guys.

I have tried to delete them using the syntax above .. but I am obviously not doing something correctly.

Complete code.

_MYmarkerPos = markerPos "_MYmarkerPos";

_depth = 5; // you must put a positive number in here

for "_count" from 1 to 20 do {

_minePos = [ (_MYmarkerPos select 0) + ((random 80) - 40),(_MYmarkerPos select 1) + ((random 80) - 40), -1 * (random _depth) ];

if (surfaceIsWater _minePos) then { 

_mine = createMine [ "UnderwaterMine", _minePos,[], 0 ];  

							   };
}; 

sleep 15;

{
if (_x isKindOf "UnderwaterMine") then {deleteVehicle _x}
} forEach nearestObjects [_MYmarkerPos,[],500];

Hint "Mines Deleted";

I also tried this. (extra ; on the end of ............deletevehicle _x};

_MYmarkerPos = markerPos "_MYmarkerPos";

_depth = 5; // you must put a positive number in here

for "_count" from 1 to 20 do {

_minePos = [ (_MYmarkerPos select 0) + ((random 80) - 40),(_MYmarkerPos select 1) + ((random 80) - 40), -1 * (random _depth) ];

if (surfaceIsWater _minePos) then { 

_mine = createMine [ "UnderwaterMine", _minePos,[], 0 ];  

							   };
}; 

sleep 15;

{
if (_x isKindOf "UnderwaterMine") then {deleteVehicle _x};
} forEach nearestObjects [_MYmarkerPos,[],500];

Hint "Mines Deleted";

It's something obvious .. but not to me unfortunately.

edit: Wondering now .. it it's the isKindOf statement causing me headaches, in other words .. is UnderwaterMine what I should be checking for on the class tree hierarchy ?

more editing and thinking out loud.

UnderwaterMine is part of "configfile" >> "configvehicles" >> underwatermine

Parents of [minebase, minegeneric, all]

---------- Post added at 08:54 ---------- Previous post was at 08:37 ----------

Nope ..

{
if (_x isKindOf "MineBase") then {deleteVehicle _x};
} forEach nearestObjects [_MYmarkerPos,[],500];

Fails also.

---------- Post added at 08:56 ---------- Previous post was at 08:54 ----------

It must be deleteVehicle then ? ... humm.. is it a vehicle ?

Edited by spitfire007

Share this post


Link to post
Share on other sites

I use "TimeBombCore" to detect apers mines ,try it. Or mebe

_nearestMines = _missionPos nearObjects ["TimeBombCore",40];

{deleteVehicle _x;} forEach _nearestMines;

Edited by Jigsor

Share this post


Link to post
Share on other sites

Well done ... who knew ! code as above with TimeBombCore .. which is a errrr mine ?

Thanks Jigsor :yay:

Share this post


Link to post
Share on other sites

May or may not be relevant to the discussion, but some time ago when I did something very similar in one of my edited Domination side missions, we found that the ability of players to disable the mines seemed to break after 4 or 5 mines. Even though the mines still visibly have their horns which mean they are still armed, players didn't get the disarm action.

Share this post


Link to post
Share on other sites

Thanks for the heads up .. I just want to be able to spawn and delete minfields at this point.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×