Jump to content
Sign in to follow this  
R4IDER

Spawning AI and adding to group

Recommended Posts

Hi,

From my understanding there is a limit of 144 groups that can be active at anyone time in ARMA3 which has never really been a problem for me before until now. Using the following code I can spawn units in locations of my choice, the downside to this is that it creates a new group every-time the function runs. What I would like to do is have all of the AI spawn and join the same group. For the last few hours I have been trying to work out how to achieve this. I have been working on the idea that if I create a normal unit with the following in its INIT line "grp_badguys = group this;". I could then use join to make that unit leave the newly create group and join the new one. At the bottom of the function I added "[_soldier] join grp_badguys;" This gives me a undefined variable error so I tried entering "[this] join grp_badguys;" into the INIT line of the spawned unit but to my amazement this causes the game to crash.

I have now run out of ideas to fix this so if anyone could point me in the right direction it would be appreciated, thanks.

Fnc_SpawnUnit = {

private ["_group","_marker","_soldier"];

_group = _this select 0;

_marker = _this select 1;

_spawn = (GetMarkerPos _marker);

_direction = _this select 2;

_position = _this select 3;

_stance = _this select 4;

_group = CreateGroup east;

_soldier = "O_mas_afr_Rebel8a_F" createUnit [_spawn,_group,"this setDir _direction;this setposATL _position;this setUnitPos _stance;this disableAI 'MOVE';",0.5];

};

Here is an example of how I am calling the function.

["ZoneGroup_X", "zone2", 193.56, [14356.5,12658.1,5.87066], "UP"] call Fnc_SpawnUnit;

Share this post


Link to post
Share on other sites

hi R4IDER,

in the editor place a GameLogic with init:

CenterEast = createCenter east;
grp_badguys = createGroup east;

new function:

Fnc_SpawnUnit = {
private ["_group","_marker","_spawn","_direction","_position","_stance","_soldier"];
_group = _this select 0;
_marker = _this select 1;
_spawn = (GetMarkerPos _marker);
_direction = _this select 2;
_position = _this select 3;
_stance = _this select 4;
_soldier = _group createUnit ["O_mas_afr_Rebel8a_F", _spawn, [], 0, "FORM"];
_soldier setDir _direction;
_soldier setposATL _position;
_soldier setUnitPos _stance;
_soldier disableAI "MOVE";
};

to call:

[grp_badguys, "zone2", 193.56, [14356.5,12658.1,5.87066], "UP"] call Fnc_SpawnUnit;

main change is to use createUnit_array.

greetings Na_Palm

Share this post


Link to post
Share on other sites

Hi,

Thanks for your help Na_Palm. I have tried the above but the result is that no unit is spawned along with no error.

Share this post


Link to post
Share on other sites

the error must be in "O_mas_afr_Rebel8a_F", thats no standard unit. With "B_G_Soldier_F" it works with no problem.

Share this post


Link to post
Share on other sites

Hi,

Would you mind sending me a copy of your mission where you have it working? maybe I could use it to work out what I am doing wrong.

Share this post


Link to post
Share on other sites

forentest.Altis.zip

extract in "\%user%\your documents\arma3\missions" then you can open it in editor directly. The code for Fnc_SpawnUnit and their call is in "init.sqf".

Hope it helps :)

Share this post


Link to post
Share on other sites

Hi,

Thank you that was helpful.

The problem was no group was created there for the units were not created.

What I have done is created a normal unit with the name TLeader and then in my missions init I have set grp_badguys = group TLeader; so that spawned units can join the group of the unit I created normally.

Thanks again.

Share this post


Link to post
Share on other sites

glad to help.

and remember to delete groups even when they are empty they don't get erased by itself, so their number builds up against the 144 max. count per side.

greetings Na_Palm

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  

×