Jump to content
Sign in to follow this  
mcvittees

Creating and deleting a spawned group

Recommended Posts

I've been trowling through these forums for over a week and I can't find an answer to this: How do I spawn a group and give it a name that I can use to delete it later via {deletevehicle _x} foreach units GroupName?

Createunit won't do because it requires an existing group (and I don't want there to be one) and with the bis_spawn_fnc it requires an existing group or a side.

Please help!

Share this post


Link to post
Share on other sites

I doubt you will be getting far if you are not willing to even define a side to spawn the group.

BIS_fnc_spawnGroup spawns a group and returns the created group. Just assign that into a global var.

Share this post


Link to post
Share on other sites

I didn't mean to imply I don't want to define a side (I do) only that it seemed I could only do that or assign my new group to an existing one.

I'll research global variables. ta shk, I'll see how far i get with them.

Share this post


Link to post
Share on other sites

I tested it, by making a script:

waituntil {BIS_fnc_init};
myNewGroup = [getpos player, EAST, 12] call BIS_fnc_spawnGroup;

And then 2 repeatedly triggers:

nul = [] execvm "spawn.sqf"

and

{deletevehicle _x} foreach units myNewGroup

Spawning and deleting works multiple times. :)

You don't need the waituntil line if you are sure you wont spawn the groups right at the beginning of the missions as the function module takes couple of seconds to init.

How to use the spawngroup function: http://forums.bistudio.com/showthread.php?t=74006

Edited by Shuko

Share this post


Link to post
Share on other sites

Wow that looks so simple! I'll be trying that asap!

---------- Post added at 10:59 AM ---------- Previous post was at 09:08 AM ----------

Shk, that works but is there a way do it so I don't need a separate script for each group I want to create? What I mean is, how can I pass from the execution array a name which will then become the global variable in the script?

E.g. (I know this doesn't work, but I'm trying to indicate what I'm trying to achieve).

nul=[GroupName] execvm "spawn.sqf"

GlobalGroupName = _this select 0;

GlobalGroupName = [pos, side, number] call BIS_fnc_spawnGroup;

I think what I am asking is how to make a local variable global? Does my question make sense?

Edit:

I tired making a series of cases to get around the need to specify the global variable from the in the execution array but it didn't seem to work:

//nul=[type] execvm "spawn.sqf";

_type = _this select 0;

switch(_type)do

{

Case 1:

{

Group1 = [getpos player, west, 12] call BIS_fnc_spawnGroup;

};

Case 2:

{

Group2 = [getpos player, west, 12] call BIS_fnc_spawnGroup;

};

Default:

{

hint: "Incorrect value entered"

};

};

if (true) exitwith {};

Share this post


Link to post
Share on other sites

trigger/whatever:

nul = "GroupName" execvm "spawn.sqf"

spawn.sqf:

call compile format ["%1 = [getpos player, EAST, 12] call BIS_fnc_spawnGroup",_this];

Obviously change to an array if you need to pass something else as well.

Share this post


Link to post
Share on other sites
trigger/whatever:

nul = "GroupName" execvm "spawn.sqf"

spawn.sqf:

call compile format ["%1 = [getpos player, EAST, 12] call BIS_fnc_spawnGroup",_this];

Obviously change to an array if you need to pass something else as well.

This is perfect Shk except I can't specify a unit list array i.e.

call compile format ["%1 = [getpos player, EAST, ["RU_Soldier_1","RU_Soldier_2"]] call BIS_fnc_spawnGroup",_this];

and also, I can't spawn Civilians - haven't tried resistance side. :( Anyways around the specify units list and side limitation? (I know I'm demanding, I feel ashamed):o

Share this post


Link to post
Share on other sites

There is no RU_Soldier_1 or RU_Soldier_2 class in Arma 2. They are RU_Soldier and RU_Soldier2. Rest: http://community.bistudio.com/wiki/ArmA_2:_CfgVehicles#Man_Class_Vehicles

Now that we have correct class names, there is multiple ways to pass the unit array, here's two:

call compile format ["%1 = [getpos player, EAST, %2] call BIS_fnc_spawnGroup",_this,["RU_Soldier","RU_Soldier2"]];

call compile format ["%1 = [getpos player, EAST, [""RU_Soldier"",""RU_Soldier2""]] call BIS_fnc_spawnGroup",_this];

You can either double quote the class names or just pass the array to the format command.

To spawn civs (or any side actually), you need to have a center or an unit of that side created. Either use createCenter or just place an unit in the editor, even condition of presence 0% will do.

[getpos player, Civilian, ["RU_Citizen2","RU_Citizen2"]] call BIS_fnc_spawnGroup

Share this post


Link to post
Share on other sites

Shk, thank you so much that did it all! I can't say I fully understand the syntax you've used in these examples as they seem pretty advanced (or maybe my brain is old and slow) but hopefully one day!:)

Share this post


Link to post
Share on other sites

trigger1:

MyNewGroup = [getpos player, west, 12] call BIS_fnc_spawnGroup;

Or if you must

MyNewGroup = call compile preprocessfilelinenumbers "script.sqf";

script.sqf

_return = [getpos player, west, 12] call BIS_fnc_spawnGroup;
[_return,getpos player] call CBA_fnc_taskDefend;
if (isnull _return) then { //group create failed
   hint "Reached 144 group limit!!";
};
_return

Also, when deleting groups, make sure to use deleteGroup to remove them aswell!!!

Share this post


Link to post
Share on other sites

Shk, sorry to bother you again but could you tell me what I need to reformat to get my group to move to waypoints in the script?

//nul = [<"GroupName">,<"Spawn">,<"Wp1">,<"Wp2">] execvm "spawn.sqf"

_grp = _this select 0;

_pos = _this select 1;

_wp1 = _this select 2;

_wp2 = _this select 3;

call compile format ["%1 = [getmarkerpos _pos, EAST, %2] call BIS_fnc_spawnGroup",_grp,["RU_Soldier","RU_Soldier2",]];

Sleep 3;

_waypoint0 = _grp addwaypoint [getmarkerpos _wp1,0];

_waypoint0 setWaypointType "move";

_waypoint0 setWaypointBehaviour "alert";

_waypoint0 setwaypointcombatmode "green";

_waypoint0 setWaypointSpeed "full";

_waypoint1 = _grp addwaypoint [getmarkerpos _wp2,0];

_waypoint1 setWaypointType "SAD";

_waypoint1 setWaypointBehaviour "combat";

_waypoint1 setWaypointformation "wedge";

_waypoint1 setwaypointcombatmode "red";

_waypoint1 setWaypointSpeed "normal";

Share this post


Link to post
Share on other sites

Add:

_grp = call compile format ["%1",_grp];

between call compile and sleep lines. That will change the _grp from a string format group name into an actual group.

And, you have an extra comma after ru_soldier2.

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  

×