Jump to content
Sign in to follow this  
DTM2801

Factions using BIS_fnc_spawnGroup

Recommended Posts

Can you use BIS_fnc_spawnGroup creating units of the faction from unit that calls it?

This is the script I'm using:

_cargoNum = _spawned emptyPositions "cargo";
if (_cargoNum > 0) then {
_fillSlots = round (random _cargoNum);
_pos = getpos _position;
_locGr =  _pos findEmptyPosition [10, 100];
_dir = getdir _spawned;
if (_locGr select 0 > 0)then {
_cargo = [_locGr,(side _spawned), _cargoNum,[],[],[],[],[_fillSlots,.5], _dir] call BIS_fnc_spawnGroup;
{_x moveInCargo _spawned;} forEach units _cargo;
 if (_joingroup) then {{[_x] joinSilent (group _spawned)} forEach units _cargo;};
};
};

It choses the side of the unit, but how would I define lets say side WEST, faction BIS_US?

I'm aware of the "CfgGroups" as described here, but how to incorporate that with the functionality of this script (spawning random side/faction soldiers based on the cargo space of the vehicle).

Tips on how to achieve this would be much appreciated.

Edited by DTM2801

Share this post


Link to post
Share on other sites

faction command is what you want.

And then you can gather all infantery units in arrays and spawn from them.

_BAF_faction = ["baf_type_1","baf_type_2,"baf_type_3"];

_USMC_faction = ["USMC_type_1".................. etc....

Share this post


Link to post
Share on other sites
faction command is what you want.

And then you can gather all infantery units in arrays and spawn from them.

_BAF_faction = ["baf_type_1","baf_type_2,"baf_type_3"];

_USMC_faction = ["USMC_type_1".................. etc....

Thanks I'll give that a go, still there must be a more simple way to do this. Without the faction in the equation the spawngroup function is pretty straight forward.

Share this post


Link to post
Share on other sites

http://community.bistudio.com/wiki/BIS_fnc_help

use that and you can open up BIS_fnc_spawnGroup and see how it works to get a better view of what you need to achieve what you want, or to create your own fnc_spawnGroup.

I am not so much skilled in using cfg´s, but i think there is no way to get all items in for example "infantery" in cfgGroups.

Or get all cfgGroups in for example "BIS_US", i tried with hint format, and gettext but no luck.

At least i don know how, and if someone does, please let us know.

Share this post


Link to post
Share on other sites

Update:

here is how to collect all info from cfgGroups, atleast one way.

it can be gathered into arrays and used to spawn faction based units, withouth manually typing them into lists.

Note: last entry in each of the (configFile >> "CfgGroups") lines is one of wich was collected in the previous one, but look at your .rpt file when running one of these and you see whats collected.

// sides.
_null = [] spawn {
_sel = count (configFile >> "CfgGroups");
_all = [];
while {_sel != 0} do {
_sel = _sel - 1;
_obj = (configFile >> "CfgGroups") select _sel;
_all = _all + [(configName _obj)];
diag_log format["%1",( configName _obj)];
};
hint format["%1",_all];
};

// factions.
_null = [] spawn {
_sel = count (configFile >> "CfgGroups" >> "West");
_all = [];
while {_sel != 0} do {
_sel = _sel - 1;
_obj = (configFile >> "CfgGroups" >> "West") select _sel;
if (isClass _obj) then {
	_all = _all + [(configName _obj)];
	diag_log format["%1",( configName _obj)];
};
};
hint format["%1",_all];
};

// type units.
_null = [] spawn {
_sel = count (configFile >> "CfgGroups" >> "West" >> "BIS_BAF_MTP");
_all = [];
while {_sel != 0} do {
_sel = _sel - 1;
_obj = (configFile >> "CfgGroups" >> "West" >> "BIS_BAF_MTP") select _sel;
if (isClass _obj) then {
	_all = _all + [(configName _obj)];
	diag_log format["%1",( configName _obj)];
};
};
hint format["%1",_all];
};

// groups.
_null = [] spawn {
_sel = count (configFile >> "CfgGroups" >> "West" >> "BIS_BAF_MTP" >> "Infantry");
_all = [];
while {_sel != 0} do {
_sel = _sel - 1;
_obj = (configFile >> "CfgGroups" >> "West" >> "BIS_BAF_MTP" >> "Infantry") select _sel;
if (isClass _obj) then {
	_all = _all + [(configName _obj)];
	diag_log format["%1",( configName _obj)];
};
};
hint format["%1",_all];
};

// units in group.
_null = [] spawn {
_sel = count (configFile >> "CfgGroups" >> "West" >> "BIS_BAF_MTP" >> "Infantry" >> "BAF_Fireteam_MTP");
_all = [];
while {_sel != 0} do {
_sel = _sel - 1;
_obj = (configFile >> "CfgGroups" >> "West" >> "BIS_BAF_MTP" >> "Infantry" >> "BAF_Fireteam_MTP") select _sel;
if (isClass _obj) then {
	_all = _all + [(configName _obj)];
	diag_log format["%1",( configName _obj)];
};
};
hint format["%1",_all];
};

// unit class.
_null = [] spawn {
_sel = count (configFile >> "CfgGroups" >> "West" >> "BIS_BAF_MTP" >> "Infantry" >> "BAF_Fireteam_MTP" >> "Unit3");
_all = [];
while {_sel != 0} do {
_sel = _sel - 1;
_obj = (configFile >> "CfgGroups" >> "West" >> "BIS_BAF_MTP" >> "Infantry" >> "BAF_Fireteam_MTP" >> "Unit3") select _sel;
if ((configName _obj) == "vehicle") then {
	_all = _all + [(getText _obj)];
	diag_log format["%1",( getText _obj)];
};
};
hint format["%1",_all];
};

Note, only tested with vanilla cfgGroups, but should work for all addons as long as they are setup same way.

Edited by Demonized

Share this post


Link to post
Share on other sites

This script below, collects unit config info and and collects all different units from all cfgGroups and spawns a new set of group based on that.

Issues, any unit not present in any cfgGroups will create error, BAF rifleman, US rifleman and a few more, this is WIP project.

Also, i tried looking into cfgVehicles but failed to collect full info needed for BIS_fnc_spawnGroup with it.

Any input welcome.

// execute with:
// _null = [unitname,min_amount_soldiers,chance_of_rest] execVM "scriptname.sqf";
// _null = [unit1,5,0.5] execVM "scriptname.sqf";

_baseUnit = _this select 0;
_minUnits = _this select 1;
_chancerest = _this select 2;

_type = typeOf _baseUnit;
_sides = side _baseUnit;
hint format["%1",_type]; sleep 2;
_side = "";
_faction = "";
_groups = "";
_infType = "";
_testCnt = 0;
if (_sides == resistance) then {_side = "Guerrila"} else {_side = format["%1",_sides]};
_cfgSelected = [];
_notfound = true;

// collect all types classnames and compare with _unit.

// factions.
_sel = count (configFile >> "CfgGroups" >> _side);
_factions = [];
while {_sel != 0} do {
_sel = _sel - 1;
_obj = (configFile >> "CfgGroups" >> _side) select _sel;
if (isClass _obj) then {
	_factions = _factions + [(configName _obj)];
};
};

{
_infType = _x;
diag_log format["factions %1",_factions];
diag_log "--------------------------------------------------------------";
{
	_faction = _x;
	// groups.
	_sel = count (configFile >> "CfgGroups" >> _side >> _faction >> _infType);
	_groups = [];
	while {_sel != 0} do {
		_sel = _sel - 1;
		_obj = (configFile >> "CfgGroups" >> _side >> _faction >> _infType) select _sel;
		if (isClass _obj) then {
			_groups = _groups + [(configName _obj)];
		};
	};

	if ((count _groups) != 0) then {
		diag_log format["groups %1",_groups];
		diag_log "--------------------------------------------------------------";
		{
			_group = _x;
			// units in group.
			_sel = count (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group);
			_unitCl = [];
			while {_sel != 0} do {
				_sel = _sel - 1;
				_obj = (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group) select _sel;
				if (isClass _obj) then {
					_unitCl = _unitCl + [(configName _obj)];
				};
			};
			diag_log format["unitCl %1",_unitCl];
			diag_log "--------------------------------------------------------------";
			{
				_unit = _x;
				// unit class.
				_sel = count (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group >> _unit);
				_all = [];
				while {_sel != 0} do {
					_sel = _sel - 1;
					_obj = (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group >> _unit) select _sel;
					if ((configName _obj) == "vehicle") then {
						_all = _all + [(getText _obj)];
						_testCnt = _testCnt + 1;
						//hint format["%2 found it %1",(getText _obj),_type]; sleep 2;
						if (_type == (getText _obj) AND _notfound) then {
							hint "adding it";
							_cfgSelected = [_side,_faction,_groups,_infType];
							_notfound = false;
							hint format["%1",_cfgSelected]; sleep 2;
						};
					};
				};
				diag_log format["_all %1",_all];
				diag_log "--------------------------------------------------------------";
			} foreach _unitCl;
		} foreach _groups;
	};
} foreach _factions;
} foreach ["Infantry","Infantry_W","Infantry_DDPM"];

diag_log format["_cfgSelected %1",_cfgSelected];
diag_log "--------------------------------------------------------------";
diag_log "phase 1 completed";
diag_log "--------------------------------------------------------------";

// add all units of selected faction to one array so we can use it to spawn from.
_side = _cfgSelected select 0;
_faction = _cfgSelected select 1;
_groups = _cfgSelected select 2;
_infType = _cfgSelected select 3;
_unitArray = [];

{
_group = _x;
// units in group.
_sel = count (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group);
_unitCl = [];
while {_sel != 0} do {
	_sel = _sel - 1;
	_obj = (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group) select _sel;
	if (isClass _obj) then {
		_unitCl = _unitCl + [(configName _obj)];
	};
};

{
	_unit = _x;
	// unit class.
	_sel = count (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group >> _unit);
	_all = [];
	while {_sel != 0} do {
		_sel = _sel - 1;
		_obj = (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group >> _unit) select _sel;
		if ((configName _obj) == "vehicle") then {
			_all = _all + [(getText _obj)];
			if (!((getText _obj) in _unitArray)) then {
				_unitArray = _unitArray + [(getText _obj)];
			};
		};
	};
} foreach _unitCl;
} foreach _groups;

hint format["%1",_unitArray];
diag_log format["%1",_unitArray];
if (_minUnits > (count _unitArray)) then {_minUnits = (count _unitArray)};

waituntil {!isnil "bis_fnc_init"};
_grp = [getMarkerPos "spawn", _sides, _unitArray,[],[],[],[],[_minUnits,_chancerest],180] call BIS_fnc_spawnGroup

Share this post


Link to post
Share on other sites

Wow, you are going all out :cool:, gonna take your script for a spin.

If this works, it shouldnt be a big leap using it to spawn units of the same vehicles side,faction taking available vehicle cargo space in account.

(Having that said, didnt we talk about more simple? hehe)

TEST Result:

Looking good, like you said spawning WEST side US soldiers returns empty array. EAST and RESISTANCE work fine.

If the _minUnits could be converted to _maxUnits based on cargo space its working exactly as wanted. Gonna dive in to it tomorrow after work:).

Awesome job Demonized!

This script below, collects unit config info and and collects all different units from all cfgGroups and spawns a new set of group based on that.

Issues, any unit not present in any cfgGroups will create error, BAF rifleman, US rifleman and a few more, this is WIP project.

Also, i tried looking into cfgVehicles but failed to collect full info needed for BIS_fnc_spawnGroup with it.

Any input welcome.

// execute with:
// _null = [unitname,min_amount_soldiers,chance_of_rest] execVM "scriptname.sqf";
// _null = [unit1,5,0.5] execVM "scriptname.sqf";

_baseUnit = _this select 0;
_minUnits = _this select 1;
_chancerest = _this select 2;

_type = typeOf _baseUnit;
_sides = side _baseUnit;
hint format["%1",_type]; sleep 2;
_side = "";
_faction = "";
_groups = "";
_infType = "";
_testCnt = 0;
if (_sides == resistance) then {_side = "Guerrila"} else {_side = format["%1",_sides]};
_cfgSelected = [];
_notfound = true;

// collect all types classnames and compare with _unit.

// factions.
_sel = count (configFile >> "CfgGroups" >> _side);
_factions = [];
while {_sel != 0} do {
   _sel = _sel - 1;
   _obj = (configFile >> "CfgGroups" >> _side) select _sel;
   if (isClass _obj) then {
       _factions = _factions + [(configName _obj)];
   };
};

{
   _infType = _x;
   diag_log format["factions %1",_factions];
   diag_log "--------------------------------------------------------------";
   {
       _faction = _x;
       // groups.
       _sel = count (configFile >> "CfgGroups" >> _side >> _faction >> _infType);
       _groups = [];
       while {_sel != 0} do {
           _sel = _sel - 1;
           _obj = (configFile >> "CfgGroups" >> _side >> _faction >> _infType) select _sel;
           if (isClass _obj) then {
               _groups = _groups + [(configName _obj)];
           };
       };

       if ((count _groups) != 0) then {
           diag_log format["groups %1",_groups];
           diag_log "--------------------------------------------------------------";
           {
               _group = _x;
               // units in group.
               _sel = count (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group);
               _unitCl = [];
               while {_sel != 0} do {
                   _sel = _sel - 1;
                   _obj = (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group) select _sel;
                   if (isClass _obj) then {
                       _unitCl = _unitCl + [(configName _obj)];
                   };
               };
               diag_log format["unitCl %1",_unitCl];
               diag_log "--------------------------------------------------------------";
               {
                   _unit = _x;
                   // unit class.
                   _sel = count (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group >> _unit);
                   _all = [];
                   while {_sel != 0} do {
                       _sel = _sel - 1;
                       _obj = (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group >> _unit) select _sel;
                       if ((configName _obj) == "vehicle") then {
                           _all = _all + [(getText _obj)];
                           _testCnt = _testCnt + 1;
                           //hint format["%2 found it %1",(getText _obj),_type]; sleep 2;
                           if (_type == (getText _obj) AND _notfound) then {
                               hint "adding it";
                               _cfgSelected = [_side,_faction,_groups,_infType];
                               _notfound = false;
                               hint format["%1",_cfgSelected]; sleep 2;
                           };
                       };
                   };
                   diag_log format["_all %1",_all];
                   diag_log "--------------------------------------------------------------";
               } foreach _unitCl;
           } foreach _groups;
       };
   } foreach _factions;
} foreach ["Infantry","Infantry_W","Infantry_DDPM"];

diag_log format["_cfgSelected %1",_cfgSelected];
diag_log "--------------------------------------------------------------";
diag_log "phase 1 completed";
diag_log "--------------------------------------------------------------";

// add all units of selected faction to one array so we can use it to spawn from.
_side = _cfgSelected select 0;
_faction = _cfgSelected select 1;
_groups = _cfgSelected select 2;
_infType = _cfgSelected select 3;
_unitArray = [];

{
   _group = _x;
   // units in group.
   _sel = count (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group);
   _unitCl = [];
   while {_sel != 0} do {
       _sel = _sel - 1;
       _obj = (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group) select _sel;
       if (isClass _obj) then {
           _unitCl = _unitCl + [(configName _obj)];
       };
   };

   {
       _unit = _x;
       // unit class.
       _sel = count (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group >> _unit);
       _all = [];
       while {_sel != 0} do {
           _sel = _sel - 1;
           _obj = (configFile >> "CfgGroups" >> _side >> _faction >> _infType >> _group >> _unit) select _sel;
           if ((configName _obj) == "vehicle") then {
               _all = _all + [(getText _obj)];
               if (!((getText _obj) in _unitArray)) then {
                   _unitArray = _unitArray + [(getText _obj)];
               };
           };
       };
   } foreach _unitCl;
} foreach _groups;

hint format["%1",_unitArray];
diag_log format["%1",_unitArray];
if (_minUnits > (count _unitArray)) then {_minUnits = (count _unitArray)};

waituntil {!isnil "bis_fnc_init"};
_grp = [getMarkerPos "spawn", _sides, _unitArray,[],[],[],[],[_minUnits,_chancerest],180] call BIS_fnc_spawnGroup

Edited by DTM2801
test result

Share this post


Link to post
Share on other sites
(Having that said, didnt we talk about more simple? hehe)

Lol yeah, i guess simple was thrown out of the pram. :cool:

There was a simpler way somewhere along the creation of this, but that did not work for the BAF units wich have desert, mtp and woodland camo, also there are other units with different camos, so that did not work. still loooking into this, it is far from effective.

And i guess it would be better to be running that script 1 time at mission start and create a bunch of Global arrays with units and their cfg´s instead of running it every time, as you will notice, it takes a few seconds to go through it all, more time with more addons as well.

Will add the missing riflemen units hardtyped into the script for now into the script, but the issue remains and ofc same for new addons units.

Also, looking at the sheer size of it, its maybe shorter to just manually type in all the classnames and use them instead... hehe.. but we wanted dynamic so screw that. :D

Edit: saw you added Test post, yes, but the empty array only happens with the specific "rifleman" unit in US, for rest of the US units it will work.

For cargo spaces:

see chance_of_rest, set that to 0 in the execution of the script.

see min_amount_soldiers, set that to (vehiclename emptyPositions "cargo")

Edited by Demonized

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
Sign in to follow this  

×