Forum Jump :

Author Message


Posts: 25
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 33
In-game name:

 
#185039 Posted at 2016-01-04 22:54        
     
I've been trying to create units in a for loop... please help. I cannot figure out what is wrong.
It says something about, created scalar unit. in my simple debug hint.

private ["_group","_side","_cnt","_min_range","_max_range","_positions","_westUnits","_eastUnits","_cntPos","_center","_i","_unit"];
_side = _this select 0;
_cnt = _this select 1;
_min_range = _this select 2;
_max_range = _this select 3;
_positions = _this select 4;

_westUnits = ["USMC_Soldier","USMC_Soldier2","USMC_SoldierM_Marksman","USMC_SoldierS","USMC_SoldierS_Engineer","USMC_SoldierS_Sniper","USMC_SoldierS_SniperH","USMC_SoldierS_Spotter","USMC_Soldier_AA","USMC_Soldier_AR","USMC_Soldier_AT","USMC_Soldier_Crew"];
_eastUnits = ["RU_Soldier","RU_Soldier2","RU_Soldier_Crew","RU_Soldier_GL","RU_Soldier_AR","RU_Soldier_HAT","RU_Soldier_LAT","RU_Soldier_MG","RU_Soldier_Marksmen"];

_cntPos = count _positions;
_center = _positions select floor(random(_cntPos));

switch (_side) do
{
	case EAST:
	{
		if ({side _x == EAST} count allUnits == 0) then
		{
			_eastHQ = createCenter EAST;
		};
	};
	case WEST:
	{
		if ({side _x == WEST} count allUnits == 0) then
		{
			_westHQ = createGroup WEST;
		};
	};
};

hint format ["Created Center: %1",_side];
sleep 1;

_group = createGroup _side;

for [{_i=0}, {_i<_cnt}, {_i=_i+1}] do
{
	if (_side == WEST) then
	{
		_unit = _westUnits select floor(random(count _westUnits)) createUnit [[(_center select 0+_min_range+_max_range),(_center select 1+_min_range+_max_range)], _group, "", random(6)/10, "corporal"];
		[_unit] join _group;
	};
	if (_side == EAST) then
	{
		_unit = _eastUnits select floor(random(count _eastUnits)) createUnit [[(_center select 0+_min_range+_max_range),(_center select 1+_min_range+_max_range)], _group, "", random(6)/10, "corporal"];
		[_unit] join _group;
	};
	hintSilent format ["Created %1 unit", {alive _x} count _unit];
	sleep 1;
	hint "";
};

_group;

Nevermind I figured out what the problem was it was, something
to do with the min range and max range... the code below works fine
but without min and max ranges.

private ["_group","_side","_cnt","_radius","_min_range","_max_range","_positions","_westUnits","_eastUnits","_cntPos","_center","_i","_unit"];
_side = _this select 0;
_cnt = _this select 1;
_min_range = _this select 2;
_max_range = _this select 3;
_positions = _this select 4;

_radius = 360;
_westUnits = ["USMC_Soldier","USMC_Soldier2","USMC_SoldierM_Marksman","USMC_SoldierS","USMC_SoldierS_Engineer","USMC_SoldierS_Sniper","USMC_SoldierS_SniperH","USMC_SoldierS_Spotter","USMC_Soldier_AA","USMC_Soldier_AR","USMC_Soldier_AT","USMC_Soldier_Crew"];
_eastUnits = ["RU_Soldier","RU_Soldier2","RU_Soldier_Crew","RU_Soldier_GL","RU_Soldier_AR","RU_Soldier_HAT","RU_Soldier_LAT","RU_Soldier_MG","RU_Soldier_Marksman"];

_cntPos = count _positions;
_center = _positions select floor(random(_cntPos));

switch (_side) do
{
	case EAST:
	{
		if ({side _x == EAST} count allUnits == 0) then
		{
			_eastHQ = createCenter EAST;
		};
	};
	case WEST:
	{
		if ({side _x == WEST} count allUnits == 0) then
		{
			_westHQ = createCenter WEST;
		};
	};
};

_group = createGroup _side;

for [{_i=0}, {_i<_cnt}, {_i=_i+1}] do
{
	if (_side == WEST) then
	{
		_unit = _westUnits select floor(random count _westUnits) createUnit [[(_center select 0)+sin(random(_radius))*(_min_range+_max_range-_min_range+1),(_center select 1)+cos(random(_radius))*(_min_range+_max_range-_min_range+1)], _group, "", random 6/10, "corporal"];
	};
	if (_side == EAST) then
	{
		_unit = _eastUnits select floor(random count _eastUnits) createUnit [[(_center select 0)+sin(random(_radius))*(_min_range+_max_range-_min_range+1),(_center select 1)+cos(random(_radius))*(_min_range+_max_range-_min_range+1)], _group, "", random 6/10, "corporal"];
	};
	[_unit] join _group;
	sleep 0.3;
};

_group;

Just in case someone else wants a custom random unit spawning script.
That doesn't use BIS_fnc_spawnGroup. Because if you script for ArmA 1 that don't have
BIS functions. But this has only units for ARMA 2 in it right now. So you'd have
to change the units for other ARMA versions.

_westUnits and _eastUnits variables..

This post was edited by theplague1988 (2016-01-05 21:46, ago)

Philip "5n4k3" Simonson