Jump to content
Sign in to follow this  
carlostex

Spawning a group of a specific size with a specific soldier class?

Recommended Posts

Allright, i know that i can use BIS_fnc_SpawnGroup to do what i am asking.

Let's say i wanted to spawn 2 Takistani Bonesetter insurgents:

[getPos aPos, EAST, ["TK_INS_Bonesetter_EP1", "TK_INS_Bonesetter_EP1"],[],[],[],[],[],180] call BIS_fnc_spawnGroup

But the problem is, the number of soldiers i need to be spawned is going to be defined by a variable that may have it's value constantly changed.

I can use the variable if i call BIS_fnc_spawnGroup this way:

[getPos aPos, EAST, _numberOfSoldiers] call BIS_fnc_spawnGroup

But now other problem comes, although this allows me to use the variable there to define the number of spawned soldiers, it does not allow me to spawn the class of soldier i want!

I'm looking for a scipt or code that will do it for me, or a modified BIS_fnc_SpawnGroup.

Any help would be appreciated

Share this post


Link to post
Share on other sites

You need to feed the information in the form of a variable that describes an array:

_Soldiers = ["TK_INS_Bonesetter_EP1", "TK_INS_Bonesetter_EP1"];
[getPos aPos, EAST, _Soldiers,[],[],[],[],[],180] call BIS_fnc_spawnGroup;

To make that array change you will have to learn how to add, subtract and change arrays:

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

It's tricky but a very useful skill.

Edited by PELHAM

Share this post


Link to post
Share on other sites
You need to feed the information in the form of a variable that describes an array:

_Soldiers = ["TK_INS_Bonesetter_EP1", "TK_INS_Bonesetter_EP1"];
[getPos aPos, EAST, _Soldiers,[],[],[],[],[],180] call BIS_fnc_spawnGroup;

To make that array change you will have to learn how to add, subtract and change arrays:

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

It's tricky but a very useful skill.

I don't think that will be possible. The only way to do it would be if we had possibility to multiply the element inside the array. Like this:


_soldierstoSpawn = 5;
_soldiersArray= ["TK_INS_Bonesetter_EP1"] * _soldierstospawn;

[getPos aPos, EAST, _soldiersArray,[],[],[],[],[],180] call BIS_fnc_spawnGroup;

Multiplying the classname string by 5 would give the _soldiersArray the value:

["TK_INS_Bonesetter_EP1","TK_INS_Bonesetter_EP1","TK_INS_Bonesetter_EP1","TK_INS_Bonesetter_EP1","TK_INS_Bonesetter_EP1"]

---------- Post added at 05:10 PM ---------- Previous post was at 04:47 PM ----------

Can some one test the following code for me?

_soldiersArray = ["TK_INS_Bonesetter_EP1"];
_soldiersToSpawn = 5;
_soldiersArray = _soldiersArray resize _soldiersToSpawn;

nul=[getPos player, EAST, _soldiersArray,[],[],[],[],[],180] call BIS_fnc_spawnGroup;

The BIKI does not provide enough info about what resize command does. If someone can test it would be deeply appreciated.

Share this post


Link to post
Share on other sites

You need the set command for that:

_soldiers =[];
{_soldiers set [_x, "TK_INS_Bonesetter_EP1"]} forEach [0,1,2,3,4];

player sidechat format ["%1",_soldiers];//debug

or to add:

waituntil {!isnil "bis_fnc_init"};
_soldiers =["TK_INS_Bonesetter_EP1","TK_INS_Bonesetter_EP1"];
{_soldiers set [_x, "TK_INS_Bonesetter_EP1"]} forEach [2,3,4];
[getPos player, EAST, _soldiers,[],[],[],[],[],180] call BIS_fnc_spawnGroup;

player sidechat format ["%1",_soldiers];//debug

_soldiersArray resize 5 gives:

["TK_INS_Bonesetter_EP1","TK_INS_Bonesetter_EP1",<NULL>,<NULL>,<NULL>]

Edited by PELHAM

Share this post


Link to post
Share on other sites

Using the set command like that is not gonna solve my problem. Because the value of the variable might change. It's not always 5!!!

---------- Post added at 06:07 PM ---------- Previous post was at 05:47 PM ----------

Why doesn't BIS gives us a way to multiply the elements of an array?

If i wanted to create an array of 100 "TK_INS_Bonesetter_EP1", a multiply operand would do the trick instead of writing that string 100 times. :mad:

Share this post


Link to post
Share on other sites

well change it to:

_number = ceil(random 10);
_soldiers =[];
_soldiers resize _number;
_elements = count _soldiers;
for "_i" from 0  to _elements do {_soldiers set [_i, "TK_INS_Bonesetter_EP1"]};
player sidechat format ["%1",_soldiers];

That will build you random arrays between 0 and 10 and set each element to "TK_INS_Bonesetter_EP1";

edit - slight change - tested and works, be aware though it's possible (unlikely with ceil) it will return an empty array, 0 at some stage.

Edited by PELHAM

Share this post


Link to post
Share on other sites

Can you test that? Will it resize the array correctly?

Share this post


Link to post
Share on other sites
Can you test that? Will it resize the array correctly?

Changed it slightly, tested - returns different sized arrays - put it in a sqf and call it with a radio trigger - the array values will show in sidechat.

Share this post


Link to post
Share on other sites
well change it to:

_number = ceil(random 10);
_soldiers =[];
_soldiers resize _number;
_elements = count _soldiers;
for "_i" from 0  to _elements do {_soldiers set [_i, "TK_INS_Bonesetter_EP1"]};
player sidechat format ["%1",_soldiers];

That will build you random arrays between 0 and 10 and set each element to "TK_INS_Bonesetter_EP1";

edit - slight change - tested and works, be aware though it's possible (unlikely with ceil) it will return an empty array, 0 at some stage.

Thanks man. And no worries about using random, i'm not gonna use it. The variable will change according to a count. The rest of the code will only run if the variable value is bigger than 0.

Anyway, if it works it's all good. All i needed was code that could effectively give the array the correct number of strings indicated by the variable. All i need now is an Arma capable computer for me to test it properly.

Share this post


Link to post
Share on other sites
All i need now is an Arma capable computer for me to test it properly.

You got me there, can't help you with that lol

Share this post


Link to post
Share on other sites

No worries mate if that code effectively works, all i need is to adapt my script. Pretty sure i can make it work!

Share this post


Link to post
Share on other sites

Mikie just told me off for being over complicated lol - simpler way of doing it suggested by him:

_number = ceil(random 10);
for "_i" from 0 to _number do {
_men = [getPos aPos, EAST, ["TK_INS_Bonesetter_EP1"],[],[],[],[],[],180] call BIS_fnc_spawnGroup;};

Share this post


Link to post
Share on other sites

I'm not sure about that. Will those spawned individual units be in the same group? It is crucial that i'm not creating single groups for every single unit of those, so in the mean time i'll keep the older code.

Share this post


Link to post
Share on other sites
I'm not sure about that. Will those spawned individual units be in the same group? It is crucial that i'm not creating single groups for every single unit of those, so in the mean time i'll keep the older code.

They would all be individuals, you you have to add something to make them join groups. Maybe what we came up with on the previous pages is best for you then?

Share this post


Link to post
Share on other sites

use this -

waituntil {!isnil "bis_fnc_init"};
F35Bgrp1 = createGroup west;

for "_i" from 0 to 2 do {

_distances = [5,6,7] call BIS_fnc_selectRandom;
	_ang = random 360;  	
	_dis = _distances; 
	_dx = sin(_ang)*_dis; 
	_dy = cos(_ang)*_dis; 
	_loc = [((getpos spawnpoint) select 0) + _dx, ((getpos spawnpoint) select 1) + _dy, 0];
	USsupportteamfake = [_loc, West, ["US_Delta_Force_M14_EP1"],[],[],[],[],[],180] call BIS_fnc_spawnGroup;

	{
	[_x] joinSilent (F35Bgrp1);
	}foreach units USsupportteamfake;

};

they are all part of the same team - if you cant get it to work - add a single player using the above method and no for loop and set him a good 30 metres away - and get him to join the group first.

they will all run to him.

works just tested - you can even test it without the group part and get them to simply join the player (if not MP testing).

Share this post


Link to post
Share on other sites

Thanks Mikie and Pelham, i'm still using the older code with resizing and set the array. I really like it and is very useful indeed.

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  

×