Jump to content
orb1975

RANDOM TRIGGERS

Recommended Posts

Hello guys. I have a problem with the atmosphere I want to create in Altis. I have the idea, but I can't materialize it. The idea is like this:

1) Create random Triggers (20) all over the map.
2) These Triggers must have a diameter of 2km.
3) These Triggers must not overlap. They must have a distance of 2.5km from each other.

 

This is my code:

_Map_Center = [15000,15000,51.37]; // Altis Map

_SafePos = [_Map_Center, 2000, 15000, 3, 0, 20, 0] call BIS_fnc_findSafePos;

_Trigger_mas_Cercano = nearestObject [_SafePos, "Trigger"];

_Distancia = _SafePos distance _Trigger_mas_Cercano;



If _Distancia > 2000 then do {

    _Counter = 0;

    for "_i" from 1 to 15 do {

        _Counter = _Counter + 1;

        _SafePos = [_Map_Center, 2000, 15000, 3, 0, 20, 0] call BIS_fnc_findSafePos;

        

        _trg_trigger = createTrigger ["EmptyDetector", _SafePos];

        _trg_trigger setTriggerArea [1000, 1000, 0, false, 0];

        _trg_trigger setTriggerText "Trigger_" + str(_Counter);

        _trg_trigger setTriggerActivation ["WEST", "PRESENT", true];

        _trg_trigger setTriggerStatements ["this", "null = [] execVM 'scripts\bla_bla_bla.sqf'", ""];

    };

};

This is where I am stuck and extremely frustrated ... I can't get the triggers to overlap. I want that before creating the trigger on the map, the system checks if there is already another trigger nearby, and if it is less than 2000 meters away, then to find another place on the map using the "call BIS_fnc_findSafePos". Please help!!!!

Edited by orb1975
more explanation!

Share this post


Link to post
Share on other sites

What I'd do is create an array of positions you know to be good.  Start of by putting 1 position in there, which will always be good as there are no other triggers yet.  Then in a while loop that checks for the number of items in your array you get a new position and check it against all the other positions in your array.  So pseudo code:

private _array = [];
private _minDistance = 2000;

private _firstPos = [...] call bis_fnc_getSafePos;
_array pushback _firstPos;

while {count _arracy < 15} do {
	private _pos = [...] call bis_fnc_getSafePos;//Grab a new, random position
	
  	private _i = _array findIf {_firstPos distance2D _pos < _minDistance}; //check if other positions are too close
  	
  	if (_i == -1) then {
    	_array pushback _pos; //If not too close, add it to the array
    } else {
    	systemChat "Too close to other pos";
    };
};

You can already create your triggers in this loop if you want and it's probably best to add a counter to check that you don't run through this loop a million times looking for a pos.  This code will obviously not run as it's got syntax errors but you should get the idea.

  • Like 1

Share this post


Link to post
Share on other sites
13 hours ago, stanhope said:

Lo que haría es crear una serie de posiciones que sepa que son buenas. Comience poniendo 1 posición allí, lo que siempre será bueno ya que todavía no hay otros factores desencadenantes. Luego, en un ciclo while que verifica la cantidad de elementos en su matriz, obtiene una nueva posición y la compara con todas las demás posiciones en su matriz. Entonces pseudo código:


 
 

 

    
	 
	
  	 
  	
  	   
      
    

Ya puede crear sus disparadores en este ciclo si lo desea y probablemente sea mejor agregar un contador para verificar que no se ejecuta a través de este ciclo un millón de veces buscando una posición. Obviamente, este código no se ejecutará ya que tiene errores de sintaxis, pero debería hacerse una idea.

Ok. I will try it.  Thanks dude!

Share this post


Link to post
Share on other sites

No dude...i have try it but nothing... isnt working... thanks anyway for your help... 

Share this post


Link to post
Share on other sites
2 hours ago, orb1975 said:

isnt working.

 

Uh...

 

On 8/25/2020 at 4:27 AM, stanhope said:

This code will obviously not run as it's got syntax errors but you should get the idea.

  • Like 1
  • Thanks 1
  • Haha 1

Share this post


Link to post
Share on other sites

Hi, I tried but the code still doesn't work. I'm stuck on this and ask you please help. The code that the colleague has recommended to me, I put it, adding my code to it; but it does not work. Here is the final code, which does not work, as I indicate that I do not want the triggers to be less than 2000 meters, and still puts them together.

 

_Map_Center = [15000,15000,51.37]; // Altis Map
_lst_Soldados_Disponibles = ["I_G_Soldier_exp_F", "I_G_Soldier_F", "I_G_Soldier_LAT2_F", "I_G_Soldier_LAT_F", "I_G_Soldier_lite_F", "I_G_Soldier_AR_F", "I_G_Soldier_GL_F", "I_G_engineer_F", "I_G_Soldier_TL_F", "I_G_Soldier_SL_F", "I_G_medic_F", "I_G_officer_F", "I_G_Soldier_A_F", "I_G_Soldier_M_F", "I_G_Sharpshooter_F"];
_Soldados_Seleccionados = [];

private _Array = [];
private _Distance = 2000;
private _FirstPos = [_Map_Center, 2000, 15000, 3, 0, 20, 0] call BIS_fnc_findSafePos;
_Array pushback _FirstPos;

	while {count _Array < 15} do {
		private _NewPos = [_Map_Center, 2000, 15000, 3, 0, 20, 0] call BIS_fnc_findSafePos; // Find a new position in random.
		private _i = _array findIf {_FirstPos distance2D _NewPos < _Distance};

		_Counter = 0;
		if (_i == -1) then {
			_Counter = _Counter + 1;
			_Array pushback _NewPos; //If not too close, add it to the array
			[west, "HQ"] sideChat "Se colocó el marcador_" + str(_Counter);

			_trg_trigger = createTrigger ["EmptyDetector", _NewPos];
			_trg_trigger setTriggerArea [1000, 1000, 0, false, 0];
			_trg_trigger setTriggerText "Trigger_" + str(_Counter);
			_trg_trigger setTriggerActivation ["WEST", "PRESENT", true];
			//_trg_trigger setTriggerStatements ["this", "null = [] execVM 'scripts\bla_bla_bla.sqf'", ""];

			_rNum = random 999999;
			_Icon = ["Nucleo_" + str(_rNum), _trg_trigger] call BIS_fnc_markerToTrigger;
			_Icon setMarkerShape "ICON";
			_Icon setMarkerType "KIA";
			_Icon setMarkerColor "ColorBlack";
			_Icon setMarkerSize [1,1];
			_Icon setMarkerAlpha 0.75;

			_rNum = random 999999;
			_mrk_name = "Centro_" + str(_rNum);
			_mrk_marker = [str(_mrk_name), _trg_trigger] call BIS_fnc_markerToTrigger;
			_mrk_marker setMarkersize [2000, 2000];
			_mrk_marker setMarkerColor "ColorBlack";
			_mrk_marker setMarkerBrush "SolidBorder";
			_mrk_marker setMarkerAlpha 0.25;

        } else {
			systemChat "Too close from other position";
		};
	};

 

Share this post


Link to post
Share on other sites
Spoiler

private _Map_Center = [worldSize / 2, worldSize / 2];
private _Array = [];
private _Distance = 2000;

private _FirstPos = [_Map_Center, 2000, 15000, 3, 0, 20, 0] call BIS_fnc_findSafePos;
_Array pushBack _FirstPos;

while {count _Array < 15} do {
    private _NewPos = [_Map_Center, 2000, (worldSize / 2), 3, 0, 20, 0, [], [0,0]] call BIS_fnc_findSafePos; // Find a new position in random.
    
    private _i = _array findIf {
        systemChat str _NewPos;
        systemChat str _x;
        systemChat str (_NewPos distance2D _x);
        _NewPos distance2D _x < _Distance
    };

    if (_i == -1) then {
        _Array pushBack _NewPos; //If not too close, add it to the array
        [west, "HQ"] sideChat "Se colocó el marcador_" + str(count _Array);

        _trg_trigger = createTrigger ["EmptyDetector", _NewPos];
        _trg_trigger setTriggerArea [1000, 1000, 0, false, 0];
        _trg_trigger setTriggerText "Trigger_" + str(count _Array);
        _trg_trigger setTriggerActivation ["WEST", "PRESENT", true];

        _rNum = random(9999);
        _Icon = ["Nucleo_" + str(_rNum), _trg_trigger] call BIS_fnc_markerToTrigger;
        _Icon setMarkerShape "ICON";
        _Icon setMarkerType "KIA";
        _Icon setMarkerColor "ColorBlack";
        _Icon setMarkerSize [1,1];
        _Icon setMarkerAlpha 0.75;

        _rNum = random(9999);
        _mrk_name = "Centro_" + str(_rNum);
        _mrk_marker = [str(_mrk_name), _trg_trigger] call BIS_fnc_markerToTrigger;
        _mrk_marker setMarkerSize [2000, 2000];
        _mrk_marker setMarkerColor "ColorBlack";
        _mrk_marker setMarkerBrush "SolidBorder";
        _mrk_marker setMarkerAlpha 0.25;

    } else {
        systemChat "Too close from other position";
    };
};

 

Fixed, you'll still need to take my debug messages out and at that one trigger statement back in.  If you want a trigger with a radius of 2000 meters the centres of these triggers don't have to be 2000 but 4000 meters apart

  • Like 1

Share this post


Link to post
Share on other sites
43 minutes ago, stanhope said:
  Revelar contenidos ocultos


private _Map_Center = [worldSize / 2, worldSize / 2];
private _Array = [];
private _Distance = 2000;

private _FirstPos = [_Map_Center, 2000, 15000, 3, 0, 20, 0] call BIS_fnc_findSafePos;
_Array pushBack _FirstPos;

while {count _Array < 15} do {
    private _NewPos = [_Map_Center, 2000, (worldSize / 2), 3, 0, 20, 0, [], [0,0]] call BIS_fnc_findSafePos; // Find a new position in random.
    
    private _i = _array findIf {
        systemChat str _NewPos;
        systemChat str _x;
        systemChat str (_NewPos distance2D _x);
        _NewPos distance2D _x < _Distance
    };

    if (_i == -1) then {
        _Array pushBack _NewPos; //If not too close, add it to the array
        [west, "HQ"] sideChat "Se colocó el marcador_" + str(count _Array);

        _trg_trigger = createTrigger ["EmptyDetector", _NewPos];
        _trg_trigger setTriggerArea [1000, 1000, 0, false, 0];
        _trg_trigger setTriggerText "Trigger_" + str(count _Array);
        _trg_trigger setTriggerActivation ["WEST", "PRESENT", true];

        _rNum = random(9999);
        _Icon = ["Nucleo_" + str(_rNum), _trg_trigger] call BIS_fnc_markerToTrigger;
        _Icon setMarkerShape "ICON";
        _Icon setMarkerType "KIA";
        _Icon setMarkerColor "ColorBlack";
        _Icon setMarkerSize [1,1];
        _Icon setMarkerAlpha 0.75;

        _rNum = random(9999);
        _mrk_name = "Centro_" + str(_rNum);
        _mrk_marker = [str(_mrk_name), _trg_trigger] call BIS_fnc_markerToTrigger;
        _mrk_marker setMarkerSize [2000, 2000];
        _mrk_marker setMarkerColor "ColorBlack";
        _mrk_marker setMarkerBrush "SolidBorder";
        _mrk_marker setMarkerAlpha 0.25;

    } else {
        systemChat "Too close from other position";
    };
};

 

Solucionado, todavía necesitará quitar mis mensajes de depuración y volver a ingresar en esa declaración de activación. Si desea un activador con un radio de 2000 metros, los centros de estos activadores no tienen que estar separados por 2000, sino 4000 metros.

I try 4000, 5000, 6000  but dont....isnt work...the code put triggers with any distance between triggers....

Share this post


Link to post
Share on other sites

I tweaked a few more things, just test the code, it works.

Share this post


Link to post
Share on other sites
6 hours ago, stanhope said:

I tweaked a few more things, just test the code, it works.

Try it dude... isnt work. this is the code.  the maps is empty... you can try it in your empty altis.... here is the code...

_Map_Center = [15000,15000,51.37]; // Altis Map
_lst_Soldados_Disponibles = ["I_G_Soldier_exp_F", "I_G_Soldier_F", "I_G_Soldier_LAT2_F", "I_G_Soldier_LAT_F", "I_G_Soldier_lite_F", "I_G_Soldier_AR_F", "I_G_Soldier_GL_F", "I_G_engineer_F", "I_G_Soldier_TL_F", "I_G_Soldier_SL_F", "I_G_medic_F", "I_G_officer_F", "I_G_Soldier_A_F", "I_G_Soldier_M_F", "I_G_Sharpshooter_F"];
_Soldados_Seleccionados = [];

private _Array = [];
private _Distance = 2000;
private _FirstPos = [_Map_Center, 2000, 15000, 3, 0, 20, 0] call BIS_fnc_findSafePos;
_Array pushback _FirstPos;

	while {count _Array < 15} do {
		private _NewPos = [_Map_Center, 2000, 15000, 3, 0, 20, 0] call BIS_fnc_findSafePos; // Find a new position in random.
		private _i = _array findIf {_FirstPos distance2D _NewPos < _Distance};

		_Counter = 0;
		if (_i == -1) then {
			_Counter = _Counter + 1;
			_Array pushback _NewPos; //If not too close, add it to the array
			[west, "HQ"] sideChat "Se colocó el marcador_" + str(_Counter);

			_trg_trigger = createTrigger ["EmptyDetector", _NewPos];
			_trg_trigger setTriggerArea [1000, 1000, 0, false, 0];
			_trg_trigger setTriggerText "Trigger_" + str(_Counter);
			_trg_trigger setTriggerActivation ["WEST", "PRESENT", true];
			//_trg_trigger setTriggerStatements ["this", "null = [] execVM 'scripts\bla_bla_bla.sqf'", ""];

			_rNum = random 999999;
			_Icon = ["Nucleo_" + str(_rNum), _trg_trigger] call BIS_fnc_markerToTrigger;
			_Icon setMarkerShape "ICON";
			_Icon setMarkerType "KIA";
			_Icon setMarkerColor "ColorBlack";
			_Icon setMarkerSize [1,1];
			_Icon setMarkerAlpha 0.75;

			_rNum = random 999999;
			_mrk_name = "Centro_" + str(_rNum);
			_mrk_marker = [str(_mrk_name), _trg_trigger] call BIS_fnc_markerToTrigger;
			_mrk_marker setMarkersize [2000, 2000];
			_mrk_marker setMarkerColor "ColorBlack";
			_mrk_marker setMarkerBrush "SolidBorder";
			_mrk_marker setMarkerAlpha 0.25;

        } else {
			systemChat "Too close from other position";
		};
	};

 

Share this post


Link to post
Share on other sites
Spoiler

eniL0Mg.png

All you have to do to the code I linked above is replace the 2000 with 4000

  • 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

×