Jump to content
Bnae

Spawn unit with custom gear.

Recommended Posts

Hello again!

 

I have this very easy problem at the moment.

Using exec to spawn EAST units. Let's say group of 4 enemies.

_enemygroup_01 = [getmarkerpos "spawn_01", EAST, ["O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F"],[],[],[],[],[],180] call BIS_fnc_spawnGroup;

What is the easiest way to add custom gear to these soldiers i just spawned? To make it easier, they all have the same custom gear.

 

 

Share this post


Link to post
Share on other sites
{
    // the VR export replacing "this" with "_x"
    removeAllWeapons _x;
    removeAllItems _x;
    removeAllAssignedItems _x;
    removeUniform _x;
    removeVest _x;
    removeBackpack _x;
    removeHeadgear _x;
    removeGoggles _x;


    _x forceAddUniform "U_I_CombatUniform";
    for "_i" from 1 to 4 do {_x addItemToUniform "30Rnd_556x45_Stanag";};
    _x addItemToUniform "16Rnd_9x21_Mag";
    _x addVest "V_PlateCarrierIA2_dgtl";
    for "_i" from 1 to 4 do {_x addItemToVest "FirstAidKit";};
    for "_i" from 1 to 6 do {_x addItemToVest "HandGrenade";};
    for "_i" from 1 to 3 do {_x addItemToVest "16Rnd_9x21_Mag";};
    _x addBackpack "B_TacticalPack_oli";
    for "_i" from 1 to 2 do {_x addItemToBackpack "SatchelCharge_Remote_Mag";};
    for "_i" from 1 to 4 do {_x addItemToBackpack "DemoCharge_Remote_Mag";};
    _x addHeadgear "H_Cap_headphones";
    _x addGoggles "G_Bandanna_oli";


    _x addWeapon "arifle_Mk20C_F";
    _x addPrimaryWeaponItem "muzzle_snds_M";
    _x addPrimaryWeaponItem "acc_flashlight";
    _x addPrimaryWeaponItem "optic_MRCO";
    _x addWeapon "hgun_P07_F";


    _x linkItem "ItemMap";
    _x linkItem "ItemCompass";
    _x linkItem "ItemWatch";
    _x linkItem "ItemRadio";
    _x linkItem "ItemGPS";
} foreach units _enemygroup_01;

Now every unit will have the some stuff.

 

if u want so use different loudouts for the units then u can select a unit out of the group.

_first_unit = (units _enemygroup_01) select 0;
removeAllWeapons _first_unit;
removeAllItems _first_unit;
removeAllAssignedItems _first_unit;
.
.
.

some goes with the second and so on.

_third_unit = (units _enemygroup_01) select 2;
removeAllWeapons _third_unit;
removeAllItems _third_unit;
removeAllAssignedItems _third_unit;
.
.
.

"units _enemygroup_01" gives you an array of the units in the group "_enemygroup_01". So this "units _enemygroup_01" is ~the same as "[my_awsome_unit_1, my_awsome_unit_2, my_awsome_unit_3, my_awsome_unit_1,]". with "select" you simply select the entry in the array starting at 0 for the first element. The second element is "select 1" etc.

Share this post


Link to post
Share on other sites

You are going to create a group with identical units (O_Soldier_F). Is there a reason for that??

Share this post


Link to post
Share on other sites
{
    // the VR export replacing "this" with "_x"
    removeAllWeapons _x;
    removeAllItems _x;
    removeAllAssignedItems _x;
    removeUniform _x;
    removeVest _x;
    removeBackpack _x;
    removeHeadgear _x;
    removeGoggles _x;


    _x forceAddUniform "U_I_CombatUniform";
    for "_i" from 1 to 4 do {_x addItemToUniform "30Rnd_556x45_Stanag";};
    _x addItemToUniform "16Rnd_9x21_Mag";
    _x addVest "V_PlateCarrierIA2_dgtl";
    for "_i" from 1 to 4 do {_x addItemToVest "FirstAidKit";};
    for "_i" from 1 to 6 do {_x addItemToVest "HandGrenade";};
    for "_i" from 1 to 3 do {_x addItemToVest "16Rnd_9x21_Mag";};
    _x addBackpack "B_TacticalPack_oli";
    for "_i" from 1 to 2 do {_x addItemToBackpack "SatchelCharge_Remote_Mag";};
    for "_i" from 1 to 4 do {_x addItemToBackpack "DemoCharge_Remote_Mag";};
    _x addHeadgear "H_Cap_headphones";
    _x addGoggles "G_Bandanna_oli";


    _x addWeapon "arifle_Mk20C_F";
    _x addPrimaryWeaponItem "muzzle_snds_M";
    _x addPrimaryWeaponItem "acc_flashlight";
    _x addPrimaryWeaponItem "optic_MRCO";
    _x addWeapon "hgun_P07_F";


    _x linkItem "ItemMap";
    _x linkItem "ItemCompass";
    _x linkItem "ItemWatch";
    _x linkItem "ItemRadio";
    _x linkItem "ItemGPS";
} foreach units _enemygroup_01;

Now every unit will have the some stuff.

 

if u want so use different loudouts for the units then u can select a unit out of the group.

_first_unit = (units _enemygroup_01) select 0;
removeAllWeapons _first_unit;
removeAllItems _first_unit;
removeAllAssignedItems _first_unit;
.
.
.

some goes with the second and so on.

_third_unit = (units _enemygroup_01) select 2;
removeAllWeapons _third_unit;
removeAllItems _third_unit;
removeAllAssignedItems _third_unit;
.
.
.

"units _enemygroup_01" gives you an array of the units in the group "_enemygroup_01". So this "units _enemygroup_01" is ~the same as "[my_awsome_unit_1, my_awsome_unit_2, my_awsome_unit_3, my_awsome_unit_1,]". with "select" you simply select the entry in the array starting at 0 for the first element. The second element is "select 1" etc.

 

 

Did you test this?

I also thought that it would be this easy, but some reason they always spawn with the "O_Soldier_F" gear.

Share this post


Link to post
Share on other sites

You are going to create a group with identical units (O_Soldier_F). Is there a reason for that??

 

Excellent question.

 

I tried to make it with different way and i failed.

_enemygroup_01 = createGroup EAST;

"O_Soldier_F" createUnit [ getMarkerPos "spawn_01", _enemygroup_01,"removeAllweapons this", 0.5, "corporal"];

This one way, but this is clearly not the easy way.

Share this post


Link to post
Share on other sites

works fine for me :

_enemygroup_01 = [position player, EAST, ["O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F"],[],[],[],[],[],180] call BIS_fnc_spawnGroup;
{
    removeAllWeapons _x;
    removeAllItems _x;
    removeAllAssignedItems _x;
    removeUniform _x;
    removeVest _x;
    removeBackpack _x;
    removeHeadgear _x;
    removeGoggles _x;


    _x forceAddUniform "U_I_CombatUniform";
    for "_i" from 1 to 4 do {_x addItemToUniform "30Rnd_556x45_Stanag";};
    _x addItemToUniform "16Rnd_9x21_Mag";
    _x addVest "V_PlateCarrierIA2_dgtl";
    for "_i" from 1 to 4 do {_x addItemToVest "FirstAidKit";};
    for "_i" from 1 to 6 do {_x addItemToVest "HandGrenade";};
    for "_i" from 1 to 3 do {_x addItemToVest "16Rnd_9x21_Mag";};
    _x addBackpack "B_TacticalPack_oli";
    for "_i" from 1 to 2 do {_x addItemToBackpack "SatchelCharge_Remote_Mag";};
    for "_i" from 1 to 4 do {_x addItemToBackpack "DemoCharge_Remote_Mag";};
    _x addHeadgear "H_Cap_headphones";
    _x addGoggles "G_Bandanna_oli";


    _x addWeapon "arifle_Mk20C_F";
    _x addPrimaryWeaponItem "muzzle_snds_M";
    _x addPrimaryWeaponItem "acc_flashlight";
    _x addPrimaryWeaponItem "optic_MRCO";
    _x addWeapon "hgun_P07_F";


    _x linkItem "ItemMap";
    _x linkItem "ItemCompass";
    _x linkItem "ItemWatch";
    _x linkItem "ItemRadio";
    _x linkItem "ItemGPS";
} foreach units _enemygroup_01;

Share this post


Link to post
Share on other sites

Excellent question.

 

I tried to make it with different way and i failed.

_enemygroup_01 = createGroup EAST;

"O_Soldier_F" createUnit [ getMarkerPos "spawn_01", _enemygroup_01,"removeAllweapons this", 0.5, "corporal"];

This one way, but this is clearly not the easy way.

don't know what you did but this works just fine.

Share this post


Link to post
Share on other sites

 

works fine for me :

_enemygroup_01 = [position player, EAST, ["O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F"],[],[],[],[],[],180] call BIS_fnc_spawnGroup;
{
    removeAllWeapons _x;
    removeAllItems _x;
    removeAllAssignedItems _x;
    removeUniform _x;
    removeVest _x;
    removeBackpack _x;
    removeHeadgear _x;
    removeGoggles _x;


    _x forceAddUniform "U_I_CombatUniform";
    for "_i" from 1 to 4 do {_x addItemToUniform "30Rnd_556x45_Stanag";};
    _x addItemToUniform "16Rnd_9x21_Mag";
    _x addVest "V_PlateCarrierIA2_dgtl";
    for "_i" from 1 to 4 do {_x addItemToVest "FirstAidKit";};
    for "_i" from 1 to 6 do {_x addItemToVest "HandGrenade";};
    for "_i" from 1 to 3 do {_x addItemToVest "16Rnd_9x21_Mag";};
    _x addBackpack "B_TacticalPack_oli";
    for "_i" from 1 to 2 do {_x addItemToBackpack "SatchelCharge_Remote_Mag";};
    for "_i" from 1 to 4 do {_x addItemToBackpack "DemoCharge_Remote_Mag";};
    _x addHeadgear "H_Cap_headphones";
    _x addGoggles "G_Bandanna_oli";


    _x addWeapon "arifle_Mk20C_F";
    _x addPrimaryWeaponItem "muzzle_snds_M";
    _x addPrimaryWeaponItem "acc_flashlight";
    _x addPrimaryWeaponItem "optic_MRCO";
    _x addWeapon "hgun_P07_F";


    _x linkItem "ItemMap";
    _x linkItem "ItemCompass";
    _x linkItem "ItemWatch";
    _x linkItem "ItemRadio";
    _x linkItem "ItemGPS";
} foreach units _enemygroup_01;

 

Oh yeah it works when i LOCAL EXEC it, but when i have it as a .sqf it doesn't.

 

This is the part where my skills are not enough.

Share this post


Link to post
Share on other sites

where do you execute this stuff?

It is working i created that while we were talking, but it's not as easy as your way.

Share this post


Link to post
Share on other sites

Excellent question.

 

I tried to make it with different way and i failed.

 

Use config entry instead

_enemygroup_01 = [getmarkerpos "spawn_01", EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam")] call BIS_fnc_spawnGroup;

Share this post


Link to post
Share on other sites

 

Use config entry instead

_enemygroup_01 = [getmarkerpos "spawn_01", EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam")] call BIS_fnc_spawnGroup;

 

Unfortunately this doesn't make it any easier to spawn custom units. At least i think so?

Share this post


Link to post
Share on other sites

the config entrie is only usefull if you want to create a certain already defined group. If you want to create group consisting of units with different loudouts then the method Bnae used is the easiest. 

Make sure to spawn a unit that is on the right side but has no stuff on it, like the unarmed units. Saves a bit performance.

_enemygroup_01 = createGroup EAST;

"O_Soldier_F" createUnit [ getMarkerPos "spawn_01", _enemygroup_01,"removeAllweapons this", 0.5, "corporal"];

For execution.

 

create a blalbalba.sqf in your mission folder. Preview the mission. Press ESC. Type in the debug console :

execVM "blablabla.sqf"

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

×