Jump to content
Sign in to follow this  
clydefrog

Naming a group created in a script when you call the script

Recommended Posts

As the title says I'm trying to give a spawned group a group name when I call the script, so I can then reference that group in other triggers to check if it has been wiped out e.g. {alive _x} count units groupname == 0

I know I could just give the group and units global names in the script but the idea of the script is I can spawn it multiple times and give the spawned group a different name each time.

Here is a basic script for a spawned group:


_spawnPos = markerPos (_this select 0); 					// Spawning location (marker position)
_grpname = _this select 1;							// group name: Name the group yourself through script call

if (isServer) then {


       _grpname = createGroup east;								// create group

_unit1 = _grpname createUnit ["O_Soldier_SL_F", [_spawnPos select 0,_spawnPos select 1,1], [], 26, "NONE"];
sleep 0.2;
_unit2 = _grpname createUnit ["O_Soldier_AR_F", [_spawnPos select 0,_spawnPos select 1,2], [], 26, "NONE"];
sleep 0.2;
_unit3 = _grpname createUnit ["O_Soldier_lite_F", [_spawnPos select 0,_spawnPos select 1,3], [], 26, "NONE"];
sleep 0.2
_unit4 = _grpname createUnit ["O_medic_F", [_spawnPos select 0,_spawnPos select 1,4], [], 26, "NONE"];
sleep 0.2;

};

Now when I call the script I want to be able to set the group name like in the following example (which doesn't work so far):

for a group named QRF1

nul = ["QRF1spawn",QRF1] execVM "QRF_infgroup.sqf";

Could anybody here please explain to me how I go about doing this?

Thanks

Edited by clydefrog

Share this post


Link to post
Share on other sites

I have a suspicion there's a more efficient way of doing this, but this works. All the same code as you had just change the group name variable and add the two red lines and call it as a string:

nul = ["QRF1spawn",[color="#FF0000"]"[/color]QRF1[color="#FF0000"]"[/color]] execVM "QRF_infgroup.sqf";

_spawnPos = markerPos (_this select 0);                     // Spawning location (marker position)
_[color="#FF0000"]my[/color]grpname = _this select 1;                            // group name: Name the group yourself through script call

if (isServer) then {
       _grpname = createGroup east;                                // create group

_unit1 = _grpname createUnit ["O_Soldier_SL_F", [_spawnPos select 0,_spawnPos select 1,1], [], 26, "NONE"];
sleep 0.2;
[color="#FF0000"]_unit1 setVehicleInit format ["%1 = group this;",_mygrpname];
processinitCommands;[/color]

};  

Share this post


Link to post
Share on other sites
I have a suspicion there's a more efficient way of doing this, but this works. All the same code as you had just change the group name variable and add the two red lines and call it as a string:

nul = ["QRF1spawn",[color="#FF0000"]"[/color]QRF1[color="#FF0000"]"[/color]] execVM "QRF_infgroup.sqf";

_spawnPos = markerPos (_this select 0);                     // Spawning location (marker position)
_[color="#FF0000"]my[/color]grpname = _this select 1;                            // group name: Name the group yourself through script call

if (isServer) then {
       _grpname = createGroup east;                                // create group

_unit1 = _grpname createUnit ["O_Soldier_SL_F", [_spawnPos select 0,_spawnPos select 1,1], [], 26, "NONE"];
sleep 0.2;
[color="#FF0000"]_unit1 setVehicleInit format ["%1 = group this;",_mygrpname];
processinitCommands;[/color]

};  

I love you kylania, thank you, lol.

Share this post


Link to post
Share on other sites

Well since I won't be able to use setVehicleInit very soon since it's being removed, anybody know any simple alternatives to do the same thing?

Share this post


Link to post
Share on other sites
_spawnPos = markerPos (_this select 0);                     // Spawning location (marker position)
_mygrpname = _this select 1;                            // group name: Name the group yourself through script call

if (isServer) then {
       _grpname = createGroup east;                                // create group

       _unit1 = _grpname createUnit ["O_Soldier_SL_F", [_spawnPos select 0,_spawnPos select 1,1], [], 26, "NONE"];
       sleep 0.2;
       [b]call compile format ["%1 = group _unit1 ;",_mygrpname];[/b]
};

Share this post


Link to post
Share on other sites
_spawnPos = markerPos (_this select 0);                     // Spawning location (marker position)
_mygrpname = _this select 1;                            // group name: Name the group yourself through script call

if (isServer) then {
       _grpname = createGroup east;                                // create group

       _unit1 = _grpname createUnit ["O_Soldier_SL_F", [_spawnPos select 0,_spawnPos select 1,1], [], 26, "NONE"];
       sleep 0.2;
       [b]call compile format ["%1 = group _unit1 ;",_mygrpname];[/b]
};

works and is nice and simple, thanks a lot (let's hope they don't remove this command too :P )

p.s. what is call compile format actually doing/what does it mean?

Share this post


Link to post
Share on other sites

format will return "QRF1 = group _unit1"

compile turns it into code {QRF1 = group _unit1}

and call executes that code

educated guess, but i'm sure its something like that :)

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  

×