Jump to content
kibaBG

[SOLVED] Spawn Garrison Units Error

Recommended Posts

Hi, I try to spawn garrison in three random buildings in two different villages. This is what I have in the trigger 

_rHouse1 = (nearestObjects [getMarkerPos "capture_1", validHouse, 250]) call BIS_fnc_selectRandom;
_grpDef1 = createGroup [east, true]; 
_unit1 = _grpDef1 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse1 buildingPos 3),[],0,"CAN_COLLIDE"];  
_unit1 disableAI "PATH"; _unit1 setUnitPos "UP";
_unit2 = _grpDef1 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse1 buildingPos 5),[],0,"CAN_COLLIDE"];  
_unit2 disableAI "PATH"; _unit2 setUnitPos "UP";
_rHouse2 = (nearestObjects [getMarkerPos "capture_1", validHouse, 250]) call BIS_fnc_selectRandom;
_unit3 = _grpDef1 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse2 buildingPos 4),[],0,"CAN_COLLIDE"];  
_unit3 disableAI "PATH"; _unit3 setUnitPos "UP";
_unit4 = _grpDef1 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse2 buildingPos 6),[],0,"CAN_COLLIDE"];  
_unit4 disableAI "PATH"; _unit4 setUnitPos "UP";
_rHouse3 = (nearestObjects [getMarkerPos "capture_1", validHouse, 250]) call BIS_fnc_selectRandom;
_unit5 = _grpDef1 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse3 buildingPos 3),[],0,"CAN_COLLIDE"];  
_unit5 disableAI "PATH"; _unit5 setUnitPos "UP";
_unit6 = _grpDef1 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse3 buildingPos 4),[],0,"CAN_COLLIDE"];  
_unit6 disableAI "PATH"; _unit6 setUnitPos "UP";
_rHouse4 = (nearestObjects [getMarkerPos "capture_2", validHouse, 250]) call BIS_fnc_selectRandom;
_grpDef2 = createGroup [east, true]; 
_unit7 = _grpDef2 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse4 buildingPos 5)),[],0,"CAN_COLLIDE"];  
_unit7 disableAI "PATH"; _unit7 setUnitPos "UP";
_unit8 = _grpDef2 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse4 buildingPos 6),[],0,"CAN_COLLIDE"];  
_unit8 disableAI "PATH"; _unit8 setUnitPos "UP";
_rHouse5 = (nearestObjects [getMarkerPos "capture_2", validHouse, 250]) call BIS_fnc_selectRandom;
_unit9 = _grpDef2 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse5 buildingPos 4),[],0,"CAN_COLLIDE"];  
_unit9 disableAI "PATH"; _unit9 setUnitPos "UP";
_unit10 = _grpDef2 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse5 buildingPos 5),[],0,"CAN_COLLIDE"];  
_unit10 disableAI "PATH"; _unit10 setUnitPos "UP";
_rHouse6 = (nearestObjects [getMarkerPos "capture_2", validHouse, 250]) call BIS_fnc_selectRandom;
_unit11 = _grpDef2 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse6 buildingPos 2),[],0,"CAN_COLLIDE"];  
_unit11 disableAI "PATH"; _unit11 setUnitPos "UP";
_unit12 = _grpDef2 createUnit ["CUP_B_US_Soldier_OEFCP",(_rHouse6 buildingPos 4),[],0,"CAN_COLLIDE"];  
_unit12 disableAI "PATH"; _unit12 setUnitPos "UP";

It give me "missing ]" typo error. 

This is the array of valid buildings
 

validHouse = ["Land_jbad_House3_dam","Land_jbad_House_c_5",
"Land_jbad_House_1_old","Land_jbad_House_8_old",
"Land_jbad_House_c_11","Land_jbad_opx2_big_e",
"Land_jbad_House_c_2","Land_jbad_House_c_10",
"Land_jbad_dum_istan2","Land_jbad_House_c_3",
"Land_jbad_opx2_complex5","Land_jbad_opx2_big_c",
"Land_jbad_House8","Land_jbad_House_1",
"Land_HBarrierTower_F"];

Any leads?  🙄

Share this post


Link to post
Share on other sites

Came up with this Frankenstein but it doesn't work
 

_rHouse1 = (nearestObjects [(getMarkerPos "capture_1"), "house", 250]) call BIS_fnc_selectRandom;
_rHouse2 = (nearestObjects [(getMarkerPos "capture_1"),"house", 250]) call BIS_fnc_selectRandom;
_rHouse3 = (nearestObjects [(getMarkerPos "capture_1"),"house", 250]) call BIS_fnc_selectRandom;
_rHouse4 = (nearestObjects [(getMarkerPos "capture_2"),"house", 250]) call BIS_fnc_selectRandom;
_rHouse5 = (nearestObjects [(getMarkerPos "capture_2"),"house", 250]) call BIS_fnc_selectRandom;
_rHouse6 = (nearestObjects [(getMarkerPos "capture_2"),"house", 250]) call BIS_fnc_selectRandom;
_group3 =[
			{_x setPosATL selectRandom(_rHouse1 buildingPos -1);
			 _x disableAI "PATH"; _x setUnitPos "UP"; 
			} forEach units _group3), east, configfile >> "CfgGroups" >> "East" >> "LOP_ISTS_OPF" >> "Infantry" >> "PO_ISTS_OPF_inf_MG_ft"
		 ] call BIS_fnc_spawnGroup;
_group3 deleteGroupWhenEmpty true;

"capture_1" and "capture_2" are two different town markers. _rHouse1,_rHouse2, ... are random houses (not sure if its working). Where is the error? 

Share this post


Link to post
Share on other sites

 

Picking at random houses can lead to picking the same house,... then the same position... You can stack units at same places.
Working script:

_validHouse = nearestObjects [getpos player, ["house"], 250];
{ 
  _posArray = _x buildingPos -1; 
  if (count _posArray>3) then { // houses with more than 3 positions only
    for "_i" from 0 to (count _posArray -1) do {
      _idx = count _posArray -1;
      if (random 1 <0.2) then {  // limit probability (groups have an ARMA limitation: up to 288 per side)
        _grp = createGroup [EAST, true];
        _pos = (_posArray deleteAt _idx);  // usually last positions are more elevated than first ones
        _unit = _grp createUnit ["CUP_B_US_Soldier_OEFCP",_pos,[],0,"CAN_COLLIDE"];
        [_unit] joinSilent _grp;  // avoid _unit stays civilian (example 6 of BIKI for createUnit)
        _unit setdir (getdir player -180); // test. For a reason I don't know, all units spawned at building position resume north oriented (any map)
        _unit disableAI "PATH"; 
        _unit setUnitPos "UP"
      }; 
    };
  }; 
} forEach _validHouse;

 

  • Thanks 1

Share this post


Link to post
Share on other sites

I tried it but it returns "Error invalid number in expression", line 7. 😥 

Share this post


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

I tried it but it returns "Error invalid number in expression", line 7. 😥 

I don't have any problem. Check if you removed comments if you run it  in trigger or debug console. Change also getpos player by getMarkerPos "capture_1" if you wish.

  • Like 1

Share this post


Link to post
Share on other sites

I repeated all steps again and now it works like a charm from a trigger. Thank you so much this will have huge positive impact on my scenario.   

  • Like 1

Share this post


Link to post
Share on other sites

@kibaBG I don't know what you are using the setup for but I use JEBUS to spawn in any AI groups you want . I like to hand place my units for more efficient placement and cover in the buildings. I use the dostop and disableAI path commands. to hold the units in place. The AI units do not have to be in the same building you can have a group spread out an entire city if you wanted to. The dostop only holds the units in place before combat once contact the dostop will be deactivated on its own. The disabledAI path I have a few triggers setup if certain AI units in the group are killed the disableAI path command will be deactivated. As well as a using different waypoints hold sentry guard will give you a nice assortment of behaviors of each group.  JEBUS spawning script has a lot of functionality and parameters to mess with including being able to use it with GAIA zones and Vcom. Avibird 

  • Like 1

Share this post


Link to post
Share on other sites
Quote

 I like to hand place my units for more efficient placement and cover in the buildings. 

 

Me too but placing on hand on proper places for sandbox scenario is a lot of work. I try to reduce the number of triggers, the scenario is huge ... for 30 areas of operation I reduced the number of triggers to 60, two triggers in area.
I would like to spread enemies more evenly in the building itself, now  it's a marksman paradise 🙂 or hell for player if he doesn't have marksman rifle or ammunition for it. 
The best way will be when the player shoots from sniper rifle or high caliber the enemies change their place from upper position to the interior of the building. This will be the most realistic, but no idea how to do it.     
   

Share this post


Link to post
Share on other sites

Here I make all spawned unit in one group, lower the checked zone (performance reasons), add random units array to get more variation
 

_grp = createGroup [independent, true];
_validHouse = nearestObjects [getpos player, ["house"], 50];
{ 
  _posArray = _x buildingPos -1; 
  if (count _posArray>3) then {
    for "_i" from 0 to (count _posArray -1) do {
      _idx = count _posArray -1;
      if (random 1 <0.2) then { 
        _pos = (_posArray deleteAt _idx);
		_runit = selectRandom ["gm_xx_army_squadleader_m16a1_80_grn","gm_xx_army_rifleman_01_akm_alp",
		"gm_xx_army_machinegunner_rpk_80_oli","gm_xx_army_antitank_hk53a2_rpg7_80_oli",
		"gm_xx_army_marksman_svd_80_wdl","gm_xx_army_engineer_hk33a2_80_brn","gm_xx_army_medic_01_mpikms72_m84",
		"gm_xx_army_assault_ak74nk_80_wdl","gm_xx_army_demolition_mp2a1_80_blk"];
        _unit = _grp createUnit [_runit,_pos,[],0,"CAN_COLLIDE"];
        [_unit] joinSilent _grp;  
        _unit setdir (getdir player -180);
        _unit disableAI "PATH"; 
        _unit setUnitPos "UP";
      }; 
    };
  }; 
} forEach _validHouse;

The only thing I want to change is make units spawn ate truly random pos in the building, not only at the last floor? :dozingoff:

 

Share this post


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

The only thing I want to change is make units spawn ate truly random pos in the building, not only at the last floor? :dozingoff:

 

 because you're always taking the last element of the array and they could be sorted by floors.

 

If you want random elements, you can keep your algorithm as-is and just change

 

_posArray = _x buildingPos -1;

To :

 

_posArray = (_x buildingPos -1) call BIS_fnc_arrayShuffle;

Now, the array containing the positions should be randomized and taking the last one would mean taking a random one

 

More informations in documentations : BIS_fnc_arrayShuffle

  • Thanks 1

Share this post


Link to post
Share on other sites

@cidfr Works perfectly, thanks! Very useful function, I am pasting the final code if someone wants to use it to spawn garrison units: 

 

_grp = createGroup [independent, true];
_validHouse = nearestObjects [getpos player, ["house"], 100];
{ 
  _posArray = (_x buildingPos -1) call BIS_fnc_arrayShuffle; 
  if (count _posArray>3) then {
    for "_i" from 0 to (count _posArray -1) do {
      _idx = count _posArray -1;
      if (random 1 <0.2) then { 
        _pos = (_posArray deleteAt _idx);
		_runit = selectRandom ["gm_xx_army_squadleader_m16a1_80_grn","gm_xx_army_rifleman_01_akm_alp",
		"gm_xx_army_machinegunner_rpk_80_oli","gm_xx_army_antitank_hk53a2_rpg7_80_oli",
		"gm_xx_army_marksman_svd_80_wdl","gm_xx_army_engineer_hk33a2_80_brn","gm_xx_army_medic_01_mpikms72_m84",
		"gm_xx_army_assault_ak74nk_80_wdl","gm_xx_army_demolition_mp2a1_80_blk"];
        _unit = _grp createUnit [_runit,_pos,[],0,"CAN_COLLIDE"];
        [_unit] joinSilent _grp;  
        _unit setdir (getdir player -180);
        _unit disableAI "PATH"; 
        _unit setUnitPos "UP";
      }; 
    };
  }; 
} forEach _validHouse;

Edit: 

New issue appeared ... the units don't stay garrisoned on dedicated server, they just go back to squad formation as there is no disableAI command.    

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

×