Jump to content
Braf Mueller

Critique My Scripting

Recommended Posts

I'm still somewhat new to scripting in Arma, and I just wanted to get some opinions on how this script looks to you guys. It's a script that gets called from the serverInit.sqf. The goal is to spawn X number of enemies assaulting a position without spawning 100's of AI at once. I would like to think there's a more efficient way to do this, but I'm not sure what is possible within Arma 3.

 

*EDIT: Noticed a couple of issues that I fixed. Such as, subtracting from _totalSpawned instead of adding... oops.

// Defines the count of AI that can be in action & how many can ever spawn
_maxActiveAI  = 75;
_maxAIToSpawn = 300;

// Group lists
// Squads are MUCH larger. Use them sparingly.
// 10 Tickets per spawn
_squads = [
	configfile >> "CfgGroups" >> "East" >> "VN_VC" >> "vn_o_group_men_vc" >> "vn_o_group_men_vc_01",
	configfile >> "CfgGroups" >> "East" >> "VN_VC" >> "vn_o_group_men_vc" >> "vn_o_group_men_vc_02"
];

// 4 Tickets per spawn
_teams = [
	configfile >> "CfgGroups" >> "East" >> "VN_VC" >> "vn_o_group_men_vc" >> "vn_o_group_men_vc_04",
	configfile >> "CfgGroups" >> "East" >> "VN_VC" >> "vn_o_group_men_vc" >> "vn_o_group_men_vc_03"
];

// List of spawn point markers for AI
_spawnMarkers = [
	"ai_spawn_1",
	"ai_spawn_2",
	"ai_spawn_3",
	"ai_spawn_4"
];

// List of attack point markers for AI
_attackPoints = [
	"ai_attack_1",
	"ai_attack_2",
	"ai_attack_3",
	"ai_attack_4"
];

_totalSpawned  = 0;

while {_totalSpawned < _maxAIToSpawn} do
{
	while { count units EAST <= _maxActiveAI - 4 && _totalSpawned < _maxAIToSpawn} do
	{
		_groupToSpawn = objNull;
		if( _maxActiveAI - count units EAST  >= 10 && random 1 > 0.5) then
		{
			_groupToSpawn  = selectRandom _squads;
			_totalSpawned  = _totalSpawned + 10; 
		}
		else
		{
			_groupToSpawn  = selectRandom _teams;
			_totalSpawned  = _totalSpawned + 4; 
		};
		
		_grp = [getMarkerPos selectRandom _spawnMarkers, EAST, (_groupToSpawn)] call BIS_fnc_spawnGroup;
		
		[_grp, getMarkerPos selectRandom _attackPoints] spawn lambs_wp_fnc_taskAssault;

	};
	sleep 60;
};

 

  • Like 1

Share this post


Link to post
Share on other sites

looks fine.

 

im assuming you are declaring those private variables elsewhere so they don't cause errors.

 

you could maybe get creative and insert some logic to determine when to spawn squads vs teams, and which type of teams to spawn, to respond appropriately to resistance. like, if the defenders have tanks, after some time the enemy could deploy more AT teams. Or if they have infantry, maybe more marksmen. also some logic to determine which attack point to attack (nearby players, etc).

 

but as a start its fine 🙂

  • Like 5

Share this post


Link to post
Share on other sites

Give a little sleep (0.5) inside your inner loop because you are spawning groups: the  creation + side meeting is not so immediate. You could have units uncounted or counted as civilian without slot time.

  • Like 4

Share this post


Link to post
Share on other sites
_groupToSpawn = objNull;

Should be:

_groupToSpawn = configNull;

 

Makes no difference when using isNull.

Makes every difference when using typeName.

 

In case you -have- to use typeName at some point,

it's wise to always keep the variable data types consistent.

  • Like 3

Share this post


Link to post
Share on other sites

Thanks for the feedback, everyone! Still getting my feet wet with scripting, but it opens up so many more doors in the editor.

  • Like 2

Share this post


Link to post
Share on other sites

You got some nice comments from the people here. I just have to add a wee bit of a minor detail. In your inner while-loop you check for a condition you have already checked on the outer while-loop, essentially checking it twice for no obvious (to me) reason. You could actually either combine those two while-loops into just the inner one or get rid of the

_totalSpawned < _maxAIToSpawn

from the second loop. It won't make any difference on the performance side but I believe it's good practice to keep your code as clean as possible and communicate your intends as precisely as possible. It will help in debugging and maintenance.

 

Otherwise a very nice script to start with 🙂.

  • 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

×