Jump to content
JoeyCare

Need help with a 'Wave spawn' script with custom loadouts

Recommended Posts

Me and a friend are making a custom map kind of like a MOBA.

 

I've just started scripting so im still very new to all this. So I've been doing the scripting, and my buddy does level design inside the editor.

I've just started on a script that spawns a team on each side every 60 seconds, and sends them over to the other side.

I wanted the units to have a custom loadout, and also despawn when killed so you can't loot their weapons.

So I've been compiling some code that I've found on google, and tried my best to customize it to my use, but I'm getting errors.

 

Here's my code so far:

[] spawn {
    for "_i" from 0 to 1000 do {
            _spawnpos = getMarkerPos "respawn_east";
            _spawnpos = [_spawnpos, 1, 20, 3, 0, 20, 0] call BIS_fnc_findSafePos;
            _grp = [] call compile format
            ["%1 = [, EAST, (configfile >> ""CfgGroups"" >> ""East"" >> ""OPF_F"" >> ""infantry"" >> ""OIA_InfTeam""),[],[],            [0.25,0.4], [0.1,0.1]] call BIS_fnc_spawnGroup; %1",_x];
            {
                removeAllAssignedItems _x;
                removeAllWeapons _x;
                removeAllContainers _x;
                _x addVest "V_BandollierB_khk";
                _x addMagazines ["30Rnd_65x39_caseless_green", 3];
                _x addWeapon "arifle_Khaybar_F";
            };
                    _wp = _grp addWaypoint [getMarkerPos "moveMarker_east", 0];
                    _wp setWaypointType "SEARCHANDDESTROY";
                    _wp setWaypointSpeed "FULL";
                    sleep 60;
    };
};

The errors I'm getting are: 

\...[0.1,0.1]] call BIS_fnc_spawnGroup; %1,|#|_x];
{
removeAllAssignedItems _x;
remove...'
Error Undefinded variable in expression: _x
File C:\...\functions\fn_spawnWestGroup.sqf, line 14

Anyone have some tips for a newbie, and care to explain why it's not working?

Share this post


Link to post
Share on other sites

It is because _x variable you trying to use is not initialized.

Share this post


Link to post
Share on other sites
[] spawn {
    for "_i" from 0 to 1000 do {
            _spawnpos = getMarkerPos "respawn_east";
            _spawnpos = [_spawnpos, 1, 20, 3, 0, 20, 0] call BIS_fnc_findSafePos;
            _grp = [_spawnpos, EAST, (configfile >> ""CfgGroups"" >> ""East"" >> ""OPF_F"" >> ""infantry"" >> ""OIA_InfTeam""),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup; 
            {
                removeAllAssignedItems _x;
                removeAllWeapons _x;
                removeAllContainers _x;
                _x addVest "V_BandollierB_khk";
                _x addMagazines ["30Rnd_65x39_caseless_green", 3];
                _x addWeapon "arifle_Khaybar_F";
            } forEach (	units _grp);
            _wp = _grp addWaypoint [getMarkerPos "moveMarker_east", 0];
            _wp setWaypointType "SEARCHANDDESTROY";
            _wp setWaypointSpeed "FULL";
            sleep 60;
    };
};

_x is a "magic" variable that is used inside a forEach loop. So the first time the loop runs, it edits the first unit of the group, the second time the loop runs, it edits the second unit of the group and so on.....

 

Share this post


Link to post
Share on other sites

@dreadpirate

_grp = [_spawnpos, EAST, (configfile >> ""CfgGroups"" >> ""East"" >> ""OPF_F"" >> ""infantry"" >> ""OIA_InfTeam""),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup; 

 

Arma3_2017-02-26_22-38-34.rpt

23:10:05 Error in expression < [getpos player, EAST, (configfile >> ""CfgGroups"" >> ""East"" >> ""OPF_F"" >> >
23:10:05   Error position: <CfgGroups"" >> ""East"" >> ""OPF_F"" >> >
23:10:05   Error Missing )
23:10:05 Error in expression < [getpos player, EAST, (configfile >> ""CfgGroups"" >> ""East"" >> ""OPF_F"" >> >
23:10:05   Error position: <CfgGroups"" >> ""East"" >> ""OPF_F"" >> >
23:10:05   Error Missing )

 

Share this post


Link to post
Share on other sites
20 minutes ago, serena said:

It is because _x variable you trying to use is not initialized.

 

Okay, I'm fairly new to using magic variables and don't quite understand them. Can you explain how I would fix this problem? What does it mean that _x is not initialized?

Share this post


Link to post
Share on other sites

My mistake, try this:

[] spawn {
    for "_i" from 0 to 1000 do {
            _spawnpos = getMarkerPos "respawn_east";
            _spawnpos = [_spawnpos, 1, 20, 3, 0, 20, 0] call BIS_fnc_findSafePos;
            _grp = [_spawnpos, EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam"),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup; 
            {
                removeAllAssignedItems _x;
                removeAllWeapons _x;
                removeAllContainers _x;
		_x addUniform "U_O_CombatUniform_ocamo";
                _x addVest "V_BandollierB_khk";
                _x addMagazines ["30Rnd_65x39_caseless_green", 3];
                _x addWeapon "arifle_Katiba_F";
            } forEach (	units _grp);
            _wp = _grp addWaypoint [getMarkerPos "moveMarker_east", 0];
            _wp setWaypointType "SEARCHANDDESTROY";
            _wp setWaypointSpeed "FULL";
            sleep 60;
    };
};

 

Share this post


Link to post
Share on other sites
Just now, JoeyCare said:

Okay, I'm fairly new to using magic variables and don't quite understand them.

 

The community wiki is a great resource and there is this article about magic variables

  • Like 2

Share this post


Link to post
Share on other sites
Just now, Nikander said:

 

The community wiki is a great resource and there is this article about magic variables

 

Haha yeah, I've been using the wiki extensively. I get what the magic variable does, but could you explain how it gets the variables without being mentioned above in the code? 

For example: 

removeAllAssignedItems _x;

would remove all the assigned items to the group that is being spawned, but how does _x know that it's linked to the group, and where does that happen in the script?

Share this post


Link to post
Share on other sites

In my code, I have:

{
	removeAllAssignedItems _x;
	removeAllWeapons _x;
	removeAllContainers _x;
	_x addUniform "U_O_CombatUniform_ocamo";
	_x addVest "V_BandollierB_khk";
	_x addMagazines ["30Rnd_65x39_caseless_green", 3];
	_x addWeapon "arifle_Katiba_F";
} forEach (units _grp);

It's the forEach command at the end that uses the _x variable.....

Share this post


Link to post
Share on other sites

@JoeyCare,  forEach instruction iterates over elements of array and, for each element executes your commands inside curly braces with element value in _x variable

// This code
{SayHello _x} forEach ["PrivateRyan", "CaptainMiller", "JoeyCare"];

// Equals to:
// step 1: _x = "PrivateRyan";		SayHello _x;
// step 2: _x = "CaptainMiller";	SayHello _x;
// step 3: _x = "JoeyCare";		SayHello _x;
// step 4: end

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites
5 minutes ago, serena said:

@JoeyCare,  forEach instruction iterates over elements of array and, for each element executes your commands inside curly braces with element value in _x variable


// This code
{SayHello _x} forEach ["PrivateRyan", "CaptainMiller", "JoeyCare"];

// Equals to:
// step 1: _x = "PrivateRyan";		SayHello _x;
// step 2: _x = "CaptainMiller";	SayHello _x;
// step 3: _x = "JoeyCare";		SayHello _x;
// step 4: end

 

 

 

 

Oh, I see! Thanks, that clears up a lot! I managed to get the script working, although it doesn't seem to spawn a unit squad with the:

_grp = [_spawnpos, WEST, (configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "BUS_InfAssault"),[],[],[0.25,0.4]] call BIS_fnc_spawnGroup;

but when i use an amount of characters to spawn it works.. 

_grp = [_spawnpos, EAST,5,[],[],[0.25,0.4]] call BIS_fnc_spawnGroup;

 

Share this post


Link to post
Share on other sites

As described here: BIS_fnc_spawnGroup , third argument can be (character details - Can be three different types):

  • a list of character types (Array),
  • an amount of characters to spawn (Number)
  • or a CfgGroups entry (Config)

 

So, configfile >> "CfgGroups" >> "West" >> "BLU_F" >> something lost from here >> "BUS_InfAssault" is legal argument, and your code will work fine with this syntax

Share this post


Link to post
Share on other sites

One small elaboration: (configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Infantry" >> "BUS_InfAssault")

Share this post


Link to post
Share on other sites
16 minutes ago, serena said:

One small elaboration: (configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Infantry" >> "BUS_InfAssault")

 

Oh, just me being stupid. Thanks a lot for the help!

How would i go about if i wanted the units to dissappear when they die? Would that require a lot of extra coding? 

Share this post


Link to post
Share on other sites

Or in your forEach loop from above add a Killed eventhandler

{
	//Your spawning and gear stuff here

	_x addEventHandler [
		"Killed",
		{
			deleteVehicle (_this select 0);
		}
	];
} forEach units _grp;

 

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

×