Jump to content
CoA|Saint

create a pre-defined amount of markers in triggerarea

Recommended Posts

Hi lads, 

I would like to create a pre-defined amount of makers in a triggerarea. The created markers should be saved in an array in order to be able to access them. The array should look something like this: 

_myArrayOfCreatedMarkers = ["marker_0","marker_1","marker_2","marker_3",....] call bis_fnc_selectrandom;

I have no idea how I can clearly name the created markers and store them in an array. My attemps in pseudo code are like this:

if (!isServer) exitWith {};

private ["_triggerArea","_ammount", "_i", "_triggPos", "_clearPos", "_list", "_name1", "_marker"];

_triggerArea = _this select 0;
_ammount = 10;
for "_i" from 1 to 10000 do 
    {
    
    _triggPos = [_triggerArea] call BIS_fnc_randomPosTrigger;
    _clearPos = (_triggPos) findEmptyPosition [0, 0, "vehicleType"];
    
		if (count _clearPos > 0) then
        {
        _name1 = format ["marker%1", count _ammount];
        _marker = createMarker [_name1, _clearPos];
        _marker setMarkerType "Empty";
		hint str _marker;
        }
    else
        {
        _i = _i - 1;
        };
    };

I dont get any further with my lack of scripting knowledge. Any suggestions please? 

 

kind regards

Saint

Share this post


Link to post
Share on other sites

You don't need to modify "_i" as the for "_i" structure automatically iterates through the specified range.

_myArrayOfCreatedMarkers = [];

for "_i" from 1 to 10000 do 
{
    _triggPos = [_triggerArea] call BIS_fnc_randomPosTrigger;
    _clearPos = (_triggPos) findEmptyPosition [0, 0, "vehicleType"];
    
    if (count _clearPos > 0) then
    {
        _name = "marker_" + str(_i);
        _marker = createMarker [_name,_clearPos];
        _marker setMarkerType "Empty";
        _myArrayOfCreatedMarkers pushback _name;
    }
};

You might also want to add in a check for whether the position is actually within the trigger area, as sometimes with this sort of thing they can end up just outside of it. Something like:

if ((count _clearPos > 0) && (_triggerPos inArea _triggerArea)) then

 

  • Like 2

Share this post


Link to post
Share on other sites

Thank you very much, @Harzach. Your Code works like a charm for me!

the working code is: 

if (!isServer) exitWith {};

private ["_triggerArea","_myArrayOfCreatedMarkers", "_i", "_triggPos", "_clearPos", "_list", "_name", "_marker"];
_myArrayOfCreatedMarkers = [];
_triggerArea = _this select 0; // execute in init.sgf :     _triggerHandler = [triggerName] execVM "markersInTrigger.sqf";

for "_i" from 1 to 11 do 
{
    _triggPos = [_triggerArea] call BIS_fnc_randomPosTrigger;
    _clearPos = (_triggPos) findEmptyPosition [10, 10 /* ,"vehicleType"*/];
    
    if ((count _clearPos > 0) && (_triggPos inArea _triggerArea)) then
    {
        _name = "marker_" + str(_i);
        _marker = createMarker [_name,_clearPos];
        _marker setMarkerType "hd_start";
        _myArrayOfCreatedMarkers pushback _name;
		hint str _myArrayOfCreatedMarkers
    }
};

best regards

Saint

  • Like 2

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

×