Jump to content

Recommended Posts

Hi, I make sandbox (kinda) scenario where the player have to liberate 20 sectors on the map. Every sector has map markers and I use the marker names to get position for enemies/loot to spawn. They are different types and  named like capture_1, capture_2, etc 
I want to make one universal script for all 20 sectors which uses the marker names without the sufix. For example I want to spawn a certain group of enemies on all markers that has "capture" in its name, vehicles on vehicle_1, vehicle_2 markers and so on. 

Here is the code "capture_1" marker: 
 

private _pos1 = [(getMarkerPos "capture_1"), 1, 250, 3, 0, 0, 0] call BIS_fnc_findSafePos; 
private _group1 = createGroup [east, true]; 
_group1 = [(getMarkerPos "capture_1"), east,[     
"LOP_ISTS_OPF_Infantry_TL", 
"LOP_ISTS_OPF_Infantry_AR", 
"LOP_ISTS_OPF_Infantry_AR_Asst", 
"LOP_ISTS_OPF_Infantry_AT", 
"LOP_ISTS_OPF_Infantry_GL", 
"LOP_ISTS_OPF_Infantry_Rifleman_5"     
]] call BIS_fnc_spawnGroup;
_group1 setBehaviourStrong "Aware";         
_group1 setCombatMode "RED";     
_group1 setSpeedMode "FULL";    
_group1 setFormation "LINE";    
_group1 deleteGroupWhenEmpty true;     
 {    
 _x setSkill ["general",1];    
 _x setSkill ["courage",1];     
 _x setSkill ["aimingAccuracy", 0.15];     
 _x setSkill ["aimingShake", 0.50];     
 _x setSkill ["aimingSpeed", 0.50];     
 _x setSkill ["reloadSpeed", 0.50];     
} forEach (units _group1);  
_wp1 = _group1 addWaypoint [(getMarkerPos "capture_1"), 20];
_wp1 setWaypointType "MOVE";
_wp2 = _group1 addWaypoint [(getMarkerPos "static_2"), 20];
_wp2 setWaypointType "MOVE";
_wp3 = _group1 addWaypoint [(getMarkerPos "capture_2"), 20];
_wp3 setWaypointType "MOVE";
_wp4 = _group1 addWaypoint [(getMarkerPos "capture_1"), 20];
_wp4 setWaypointType "CYCLE";

How to make it universal, for all the markers with a name "capture_x" ?     

Share this post


Link to post
Share on other sites
15 hours ago, kibaBG said:

How to make it universal, for all the markers with a name "capture_x" ?     

You can use for-loop:

#define CAPTURE_MARKER_FORMAT "capture_%1"

private ["_captureMarker1", "_captureMarker2"];

for "_n" from 1 to 19 do {
    _captureMarker1 = format [CAPTURE_FORMAT_MARKER, _n];
    _captureMarker2 = format [CAPTURE_FORMAT_MARKER, _n + 1];

    ...
};

 

  • Like 1

Share this post


Link to post
Share on other sites
{
	//all your code here
	//Make sure to change any references to the marker with _x
	//eg getMarkerPos _x
}forEach ( allMapMarkers select{ _x select[ 0, 8 ] == "capture_" } );
                                  //first eight characters ==

 

  • Like 1

Share this post


Link to post
Share on other sites

@Schatten To try to implement your suggestion I have to force my poor brain to understand this https://community.bistudio.com/wiki/PreProcessor_Commands I will try my best 😂.
 

@Larrow suggestion is working and very easy to implement but ... I have lots of other marker names within different than "capture_x" like markers for the waypoints, maybe it has to be done manually after all. 😕

Share this post


Link to post
Share on other sites
5 minutes ago, kibaBG said:

I have to force my poor brain to understand this https://community.bistudio.com/wiki/PreProcessor_Commands I will try my best 😂 .

Good luck!

By the way, you don't have to use preprocessor commands:

private ["_captureMarker1", "_captureMarker2"];

for "_n" from 1 to 19 do {
    _captureMarker1 = format ["capture_%1", _n];
    _captureMarker2 = format ["capture_%1", _n + 1];

    ...
};

 

  • Like 1

Share this post


Link to post
Share on other sites
14 hours ago, kibaBG said:

I have lots of other marker names within different than "capture_x" like markers for the waypoints

Without seeing the rest of your code for the other groups' markers, I have no idea if there is a pattern to their names.

So the only other suggestion I have would be something like this...

Spoiler

private[ "_pos", "_group", "_wp" ];
{
	_x params[ "_start", "_moves" ];

	_pos = [ getMarkerPos _start, 1, 250, 3, 0, 0, 0 ] call BIS_fnc_findSafePos;

	_group = [ _pos, east, [
		"LOP_ISTS_OPF_Infantry_TL",
		"LOP_ISTS_OPF_Infantry_AR",
		"LOP_ISTS_OPF_Infantry_AR_Asst",
		"LOP_ISTS_OPF_Infantry_AT",
		"LOP_ISTS_OPF_Infantry_GL",
		"LOP_ISTS_OPF_Infantry_Rifleman_5"
	]] call BIS_fnc_spawnGroup;
	_group setBehaviourStrong "Aware";
	_group setCombatMode "RED";
	_group setSpeedMode "FULL";
	_group setFormation "LINE";
	_group deleteGroupWhenEmpty true;

	{
		_x setSkill[ "general", 1 ];
		_x setSkill[ "courage", 1 ];
		_x setSkill[ "aimingAccuracy", 0.15 ];
		_x setSkill[ "aimingShake", 0.50 ];
		_x setSkill[ "aimingSpeed", 0.50 ];
		_x setSkill[ "reloadSpeed", 0.50 ];
	}forEach units _group;

	{
		_wp = _group addWaypoint[ getMarkerPos _x, 20 ];
		_wp setWaypointType "MOVE";
	}forEach _moves;
	_wp = _group addWaypoint[ getMarkerPos _start, 20];
	_wp setWaypointType "CYCLE";
}forEach [
	//[ start/cycle, [ move, move .... ] ]       // ... as many move positions as you like
	[ "capture_1", [ "static_2", "capture_2" ] ], 
	[ "capture_2", [ "static_3", "capture_3" ] ] //example for a second group starting at "capture_2" moving to "static_3" and "capture_3" and then a cycle at "capture_2"
];

 

Then all you need to do is add an array at the bottom for each group you want to spawn, with their marker names for where they start/cycle and their move waypoints.

 

14 hours ago, kibaBG said:

I have to force my poor brain to understand this PreProcessor_Commands

The one Schatten has shown is pretty easy to understand...

On 10/25/2022 at 8:53 AM, Schatten said:

#define CAPTURE_MARKER_FORMAT "capture_%1"

...so when your code is interpreted by the engine, anywhere it finds CAPTURE_MARKER_FORMAT it replaces it with "capture_%1".

  • Like 1

Share this post


Link to post
Share on other sites

@Larrow This is exactly what I needed, thank you man. I will update when I test it.   
 

I will test @Schatten's variant too.  

 

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

×