Jump to content
Dramacius

Can someone help me with my random spawn script please?

Recommended Posts

Hi, I am trying to spawn a bunch of enemies in a custom shoothouse, I have used Game Logic to set the possible random positions in the building I need the units to stay in position and one of the units is to carry a key.

The problem I am having is they all seem to spawn on the same spawn marker. I haven't tested anything else yet as I just want to get them to spawn in the right places first.

I have 2 other areas attached to the shoothouse, one with an Officer in parade uniform who I want to surrender when the players enter the building for them to capture and another with a few (maybe just 2) civilian hostages who are tied up and on the floor for the players to rescue.

I am using several mods including ACE3 and CBA. This is to go onto a dedicated server once completed.

Thanks for any help you can provide.

My Codes:
 

Spoiler

Main Shoothouse Maze:
 


_Mposition = [
	ShMzSoldierPos_1, ShMzSoldierPos_2, ShMzSoldierPos_3, ShMzSoldierPos_4, ShMzSoldierPos_5, ShMzSoldierPos_6, ShMzSoldierPos_7, ShMzSoldierPos_8, ShMzSoldierPos_9, ShMzSoldierPos_10, ShMzSoldierPos_11, ShMzSoldierPos_12, ShMzSoldierPos_13, ShMzSoldierPos_14, ShMzSoldierPos_15, ShMzSoldierPos_16, ShMzSoldierPos_17, ShMzSoldierPos_18, ShMzSoldierPos_19, ShMzSoldierPos_20, ShMzSoldierPos_21, ShMzSoldierPos_22, ShMzSoldierPos_23, ShMzSoldierPos_24, ShMzSoldierPos_25, ShMzSoldierPos_26, ShMzSoldierPos_27, ShMzSoldierPos_28, ShMzSoldierPos_29, ShMzSoldierPos_30, ShMzSoldierPos_31, ShMzSoldierPos_32, ShMzSoldierPos_33, ShMzSoldierPos_34, ShMzSoldierPos_35, ShMzSoldierPos_36, ShMzSoldierPos_37, ShMzSoldierPos_38, ShMzSoldierPos_39, ShMzSoldierPos_40
	];

_usedMPosition = [];

_newMTargetPos = selectRandom (_Mposition - [_usedMPosition]);

_group = createGroup east;
_type = "";
_here = getPosATL _newMTargetPos;
_markers = [];
_placement = 0;
_special = "None";

_squadlead = _group createUnit ["O_Soldier_F", _here, _markers, _placement, _special];
_squadlead disableAI "PATH";
_squadlead addItem "Keys";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

_soldier = _group createUnit ["O_Soldier_Lite_F", _here, _markers, _placement, _special];
_soldier disableAI "PATH";

_usedMPosition = _usedMPosition + [_newMTargetPos];

 

 

Spoiler

Officer who I want to surrender when the players arrive:


_Oposition = [
	ShOfficerPos_1, ShOfficerPos_2, ShOfficerPos_3, ShOfficerPos_4, ShOfficerPos_5, ShOfficerPos_6
	];

_usedOPosition = [];

_newOTargetPos = selectRandom (_Oposition - [_usedOPosition]);

_typeArray = ["O_Officer_Parade_F"];

_group = createGroup east;
_type = selectRandom _typeArray;
_here = getPosATL _newOTargetPos;
_markers = [];
_placement = 0;
_special = "None";

_general = _group createUnit [_type, _here, _markers, _placement, _special];
_general disableAI "PATH";

_usedOPosition = _usedOPosition + [_newOTargetPos];

 

 

Spoiler

The above Officers personal guards


_OGPosition = [
	ShSmSoldierPos_1,ShSmSoldierPos_2,ShSmSoldierPos_3,ShSmSoldierPos_4,ShSmSoldierPos_5,ShSmSoldierPos_6,ShSmSoldierPos_7,ShSmSoldierPos_8,ShSmSoldierPos_9,ShSmSoldierPos_10,ShSmSoldierPos_11,ShSmSoldierPos_12,ShSmSoldierPos_13,ShSmSoldierPos_14,ShSmSoldierPos_15,ShSmSoldierPos_16,ShSmSoldierPos_17,ShSmSoldierPos_18,ShSmSoldierPos_19,ShSmSoldierPos_20,ShSmSoldierPos_21,ShSmSoldierPos_22,ShSmSoldierPos_23,ShSmSoldierPos_24
];

_usedOGPosition = [];

_newOGTargetPos = selectRandom (_OGposition - [_usedOGPosition]);

_typeArray = ["O_Soldier_F"];

_group = createGroup east;
_type = selectRandom _typeArray;
_here = getPosATL _newOGTargetPos;
_markers = [];
_placement = 0;
_special = "None";

_OfficerGuard = _group createUnit [_type, _here, _markers, _placement, _special];
_OfficerGuard disableAI "PATH";

_usedOGPosition = _usedOGPosition + [_newOGTargetPos];

_OfficerGuard = _group createUnit [_type, _here, _markers, _placement, _special];
_OfficerGuard disableAI "PATH";

_usedOGPosition = _usedOGPosition + [_newOGTargetPos];

_OfficerGuard = _group createUnit [_type, _here, _markers, _placement, _special];
_OfficerGuard disableAI "PATH";

_usedOGPosition = _usedOGPosition + [_newOGTargetPos];

_OfficerGuard = _group createUnit [_type, _here, _markers, _placement, _special];
_OfficerGuard disableAI "PATH";

_usedOGPosition = _usedOGPosition + [_newOGTargetPos];

 

 

Spoiler

Hostages


_Hposition = [
	ShHostage_01, ShHostage_02, ShHostage_04, ShHostage_05, ShHostage_06, ShHostage_07
	];

_usedHPosition = [];

_newHTargetPos = selectRandom (_Hposition - [_usedHPosition]);

_typeArray = ["Max_woman1", "Max_woman2", "Max_woman3", "Max_woman4"];

_group = createGroup civilian;
_type = selectRandom _typeArray;
_here = getPosATL _newHTargetPos;
_markers = [];
_placement = 0;
_special = "None";

_hostage = _group createUnit [_type, _here, _markers, _placement, _special];
_hostage disableAI "PATH";
[_hostage,true] call ace_captives_fnc_setHandcuffed;

_usedHPosition = _usedHPosition + [_newHTargetPos];

_hostage = _group createUnit [_type, _here, _markers, _placement, _special];
_hostage disableAI "PATH";
[_hostage,true] call ace_captives_fnc_setHandcuffed;

_usedHPosition = _usedHPosition + [_newHTargetPos];

 


 

Spoiler

Hostage Guards

_HGposition = [
    ShBgSoldier_01, ShBgSoldier_02, ShBgSoldier_03, ShBgSoldier_04, ShBgSoldier_05, ShBgSoldier_06, ShBgSoldier_07, ShBgSoldier_08, ShBgSoldier_09, ShBgSoldier_10, ShBgSoldier_11, ShBgSoldier_13, ShBgSoldier_14, ShBgSoldier_15, ShBgSoldier_16, ShBgSoldier_17, ShBgSoldier_18, ShBgSoldier_19, ShBgSoldier_20, ShBgSoldier_21, ShBgSoldier_22, ShBgSoldier_23, ShBgSoldier_24, ShBgSoldier_25
        ];
        
_usedHGPosition = [];
_newHGTargetPos = selectRandom (_HGposition - [_usedHGPosition]);

_typeArray = ["O_Soldier_lite_F"];

_group = createGroup east;
_type = selectRandom _typeArray;
_here = getPosATL _newHGTargetPos;
_markers = [];
_placement = 0;
_special = "None";

 

_hostageguard = _group createUnit [_type, _here, _markers, _placement, _special];
_hostageguard disableAI "PATH";
_usedHGPosition = _usedHGPosition + [_newHGTargetPos];

 

_hostageguard = _group createUnit [_type, _here, _markers, _placement, _special];
_hostageguard disableAI "PATH";

_usedHGPosition = _usedHGPosition + [_newHGTargetPos];

 

_hostageguard = _group createUnit [_type, _here, _markers, _placement, _special];
_hostageguard disableAI "PATH";

_usedHGPosition = _usedHGPosition + [_newHGTargetPos];

 

_hostageguard = _group createUnit [_type, _here, _markers, _placement, _special];
_hostageguard disableAI "PATH";

_usedHGPosition = _usedHGPosition + [_newHGTargetPos];

 

_hostageguard = _group createUnit [_type, _here, _markers, _placement, _special];
_hostageguard disableAI "PATH";

_usedHGPosition = _usedHGPosition + [_newHGTargetPos];

 

_hostageguard = _group createUnit [_type, _here, _markers, _placement, _special];
_hostageguard disableAI "PATH";

_usedHGPosition = _usedHGPosition + [_newHGTargetPos];

 

_hostageguard = _group createUnit [_type, _here, _markers, _placement, _special];
_hostageguard disableAI "PATH";

_usedHGPosition = _usedHGPosition + [_newHGTargetPos];

 

_hostageguard = _group createUnit [_type, _here, _markers, _placement, _special];
_hostageguard disableAI "PATH";

_usedHGPosition = _usedHGPosition + [_newHGTargetPos];

 

Share this post


Link to post
Share on other sites

If units and positions are limited and not so randomized (defined number and type of units), you can easily avoid all these scripts, using the editor and deleting at random all unwanted placed units, once in game.

Share this post


Link to post
Share on other sites
On 9/23/2022 at 4:45 PM, pierremgi said:

If units and positions are limited and not so randomized (defined number and type of units), you can easily avoid all these scripts, using the editor and deleting at random all unwanted placed units, once in game.

Its for a multiplayer 24/7 training server, the players will be starting and resetting a live fire shoothouse manually with addAction commands on a laptop based outside the shoothouse.

first addAction calls the scripts to spawn the enemies
second addAction removes them all

nb. I have managed to get the spawns to work but they spawn each unit into there own groups (alpha, bravo, charlie etc.)

Edited by Dramacius
added new information.

Share this post


Link to post
Share on other sites
24 minutes ago, Dramacius said:

nb. I have managed to get the spawns to work but they spawn each unit into there own groups (alpha, bravo, charlie etc.)

 

Why is it a problem?

Share this post


Link to post
Share on other sites
1 minute ago, pierremgi said:

 

Why is it a problem?



Primarily neatness but also to avoid hitting any potential group limits.

Share this post


Link to post
Share on other sites
Just now, Dramacius said:



Primarily neatness but also to avoid hitting any potential group limits.

Emptied group (dead units) are deleted after few seconds. If you want to be sure you can use  _group deleteGroupWhenEmpty TRUE ;  // in your script, once created. 

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

×