Jump to content
hcpookie

Passing random variable to createMine?

Recommended Posts

Working on a minefield script that partially randomizes the minefield by randomly selecting underwater mine types from an array - between moored, bottom mines, etc.  When passing the actual mine name to createMine it works fine... e.g. "UnderWaterMine" is OK.

 

My script is trying to use the variable _mineType that stores the mine randomly selected from an array via selectRandomWeighted.  Pretty simple as you would any "select a random vehicle".

 

When I pass a variable to createMine, as you would w/ createVehicle, it fails to create the mine.

 

When I use "createVehicle" instead of "createMine" it works fine.  Of course you cannot simply "createVehicle" a mine because there seems to be some additional setting (activateMine perhaps?) that "turns them on"... so I can create a minefield of dud mines :)

 

QUESTION:  How can one pass _mineType to the createMine command?  Is this a hard-coded limitation?  Is there a better way to do this?  I am trying to avoid a hard-coded "homogenous" minefield in this script.

  • Like 1

Share this post


Link to post
Share on other sites

So it isn't just me after all :)

 

Based on my testing this week it looks like I'm going to be forced to exec a command (via exitWith) for each of the mine types... that will be fun to figure out :(

Share this post


Link to post
Share on other sites
5 hours ago, hcpookie said:

createVehicle, it fails to create the mine.

 

Hello there hcpookie !

 

Here is an example creating a minefield from @Quicksilver

 

@file: fn_AOminefield.sqf

Spoiler

/*
@file: fn_AOminefield.sqf
Author:

	Quiksilver (credit Rarek [ahoyworld] for initial build)
	
Description:

	Spawn a minefield around radio tower sub-objective
	
________________________________________________________________*/

#define MINE_TYPES "APERSBoundingMine","APERSMine","ATMine"
_centralPos = _this select 0;
_unitsArray = [];

for "_x" from 0 to 59 do {
        _mine = createMine [[MINE_TYPES] call BIS_fnc_selectrandom, _centralPos, [], 38];
        _unitsArray = _unitsArray + [_mine];
};

_distance = 40;
_dir = 180;

for "_c" from 0 to 23 do {
    _pos = [_flatPos, _distance, _dir] call BIS_fnc_relPos;
    _sign = "Land_Razorwire_F" createVehicle _pos;
        waitUntil {alive _sign};
        _sign setDir _dir;
		_sign enableSimulation false;
		_sign allowDamage false;
        _dir = _dir + 15;
        
        _unitsArray = _unitsArray + [_sign];
};

_unitsArray

 

 

_unitsArray = [_Position] call QS_fnc_AOminefield;

 

Share this post


Link to post
Share on other sites

Thanks!  I'll look into this.  Not sure why that would work but this does not:

_mine = createMine [_mineTypeRnd,_minePos, [], 0]; 

Only difference I see is that code defines the array where I randomly choose from an array.

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, hcpookie said:

Thanks!  I'll look into this.  Not sure why that would work but this does not:


_mine = createMine [_mineTypeRnd,_minePos, [], 0]; 

Only difference I see is that code defines the array where I randomly choose from an array.

Are you sure that _mineTypeRnd is correct type. You could also double check if _minePos is correct position

  • Like 1

Share this post


Link to post
Share on other sites

Yes I am hinting to see that.  So it looks like I got it working - I think the mines were being created under the surface?  When I switched to getPosASLW and the mines are correctly appearing at the markers.  I've been reading on the position AGL vs. ASLW vs. all the others and I may have screwed that up.  So I think that's what the problem was all along :/

 

I'm still sorting through the placement function so it will put shallow mines on the bottom vs. floating above the surface... using the marker spheres for visual confirmation of the placement actions.

 

the minePos function is WIP; right now this places Helipad Empty markers and intended to measure closest markers to ensure random spacing is evenly distributed in the area... just does some random pos selections from center for now.  I intend to add a check for "shallow" water and add some checks to place only the bottom mines for shallow placement.

 

	while {(_num < 12)} do {

		_minePos = [_pos] call pook_BOATS_fnc_mTC;

		_mineMkr = createVehicle ["Sign_Sphere100cm_F", _minePos, [], 0, "NONE"];
		_mineMkr setPosASLW _minePos;
		_k = getPosASLW _mineMkr;

		_mineTypeRnd = [_typ] call pook_BOATS_fnc_mF; >>> This selects mines from different arrays for some variety!

hint format["Mine Type: %1\nMinePos: %2",_mineTypeRnd,_k];
sleep 3;
		_mine = createMine [_mineTypeRnd,_k, [], 0]; 
		deleteVehicle _mineMkr;
		_num = _num + 1;

	};

 

  • Like 1

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

×