Jump to content
Sign in to follow this  
CaptainBravo

Need expert for a simple spawn script

Recommended Posts

Hey everyone,

I have attached a simple mission script for spawning troops inside a helipcopter through waypoint.

However, it is not working and I am sure it is due to something really minor.

So I need some help pointing out the error. :confused:

http://www.filefront.com/14426265/Test_Helicopter_Troops_Spawn.utes.rar

I appreciate all the help in advance.:pray:

Thanks

Share this post


Link to post
Share on other sites

There's a few problems, first of which is you're trying to feed your script what appears to be a gamelogic position, but you have no gamelogics on the map?

Secondly, when you moveInCargo the AI doesn't actually know they are in the vehicle, so when you supposedly TRANSPORT UNLOAD the helo doesn't think it has any cargo and doesn't do anything. You can probably get around that via assignVehicle, but I think this is the wrong approach for whatever you're trying to do, speaking of...

This is a really really weird way of doing this, what exactly are you trying to do? :)

Share this post


Link to post
Share on other sites

Thanks kylania for your response. I thought it might be more complicated than what I initialy thopught :)

What I am trying to do

I am making a mission where Helicopters will continue landing and unloading troops then take off again to bring more troops to battle field.If a helicopter is shut down no more troops.

How?

Having helicopter fly through waypoints and everytime they reached a certain wp troops got created and moved inside helicopter. Then heli will just unload them next WP. Add cycle waypoint for the chopper so process is repeated.

WP1 = move - init field activate script to creat troops and move them to heli

WP2= Unload in battle field

WP3= Cycle

and process gets repeated

Troops will have their own WP so they can move after unload.

Does that make sense? Any easier way of doing it? :confused:

Thanks for your help.

Edited by CaptainBravo
clarifying

Share this post


Link to post
Share on other sites

Ahh, ok that makes sense. Any limit to how many runs they make? Also, that kind of troops? If you use BIS_fnc_spawnGroup you can clean up your code a bit and use any of the pre-made squads from the editor lists.

Also what starts this process? Mission start or a specific objective being completed?

Edited by kylania

Share this post


Link to post
Share on other sites

5 runs per heli then they go back to base.

BIS Function would be ideal specially that it can delete units I believe and I would use pre made infantry squads.

Heli start move by Trigger once an area is clear.

Thanks for your help.

Share this post


Link to post
Share on other sites

Sorry this took so long, dinner and making this dedicated server workable took a while. :)

So.. you'll need the function module, 2 markers (HR_SPAWN and HR_LZ), 2 scripts, a few lines in your init.sqf, and a trigger to set it all off.

OPFOR NOT PRESENT trigger onAct:

titleText ["Airfield is clear!  Reinforcements can now move in.","PLAIN DOWN"]; nul = [] execVM "HR.sqf";

init.sqf:

waituntil {!isnil "bis_fnc_init"};
waituntil {!isnil "BIS_MPF_InitDone"};

That's just to make sure the Functions module and Multiplayer Framework is in place.

HR.sqf:

[color="SeaGreen"]//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: 1ID-CPL. Venori
//////////////////////////////////////////////////////////////////
// Preplace 2 markers.  
// 	"HP_SPAWN" where you want the helos to start from and "reload" at.
//	"HP_LZ" where you want the helos to land.

// Only spawn once, on the server.
[/color]if(!isServer) exitWith{};

[color="SeaGreen"]// Number of waves to bring in.[/color]
HR_wavecount = 5;
publicvariable "HR_wavecount"; 

[color="SeaGreen"]// Create the group with 2 MH-60S[/color]
HR_flightgroup = creategroup west;
HR1 = ([getMarkerPos "HR_SPAWN", 45, "MH60S", HR_flightgroup] call BIS_fnc_spawnVehicle) select 0;
HR1 setVehicleVarName "HR1";
publicvariable "HR1";
sleep 5;
HR2 = ([getMarkerPos "HR_SPAWN", 45, "MH60S", HR_flightgroup] call BIS_fnc_spawnVehicle) select 0;
HR2 setVehicleVarName "HR2";
publicvariable "HR2"; 

[color="SeaGreen"]// Make them fly pretty.[/color]
HR_flightgroup setFormation "COLUMN";
HR_flightgroup setBehaviour "CARELESS";
HR1 flyinHeight 35;
HR2 flyinHeight 40; [color="SeaGreen"]// when flying at the same height they seemed to "wave" a lot.

// Spawn the first wave.[/color]
[hr_flightgroup, "HR_LZ"] execVM "HR_spawnGroup.sqf";

[color="SeaGreen"]// Debug ride-along :)
//p1 assignAsCargo HR2;
//p1 moveinCargo HR2;

// Set the waypoints for the helo group.  Their origin point is waypoint 0.[/color]
_wp = HR_flightgroup addWaypoint [getMarkerpos "HR_LZ", 1];[color="SeaGreen"] // waypoint at the LZ marker.[/color]
_wp1 = HR_flightgroup addWaypoint [getMarkerPos "HR_SPAWN", 1]; [color="SeaGreen"] // waypoint back at the spawn marker.[/color]
_wp2 = HR_flightgroup addWaypoint [getMarkerPos "HR_SPAWN", 1];  [color="SeaGreen"]// Cycle waypoint at spawn marker too.[/color]
[hr_flightgroup, 1] setWaypointType "TR UNLOAD"; [color="SeaGreen"] // Set the 1 (second actual waypoint, hence 1 instead of 0) to TRANSPORT UNLOAD.[/color]
[hr_flightgroup, 2] setWaypointType "MOVE"; [color="SeaGreen"] // set the 2 waypoint to MOVE with the following call to spawn another group:[/color]
[hr_flightgroup, 2] setWaypointStatements ["true", "nul = [hr_flightgroup, ""HR_LZ""] execVM ""HR_spawnGroup.sqf"""];
[hr_flightgroup, 3] setWaypointType "CYCLE";  [color="SeaGreen"]// set the 3 waypoint to CYCLE[/color]

HR_spawnGroup.sqf:

[color="SeaGreen"]//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: 1ID-CPL. Venori
//////////////////////////////////////////////////////////////////
// Called via waypoint with:
// 	nul = [hr_flightgroup, "HR_LZ"] execVM "HR_spawnGroup.sqf";

// Grab the input arguments[/color]
_helogroup = _this select 0;
_lz = _this select 1;  // marker name.

[color="SeaGreen"]// Distance between waypoints for the infantry's patrol waypoints.[/color]
_max_dist_between_waypoints = 100;
[color="SeaGreen"]// Random types of groups to spawn.[/color]
_grouptypes = ["USMC_FireTeam","USMC_FireTeam_MG","USMC_FireTeam_AT","USMC_FireTeam_Support","USMC_HeavyATTeam"];

[color="SeaGreen"]// Only do this if we're the server...[/color]
if(!isServer) exitWith{};

[color="SeaGreen"]// As long as we haven't done all the waves, lets make new ones![/color]
if (HR_wavecount > 0) then {

[color="SeaGreen"]// If the first bird is alive...[/color]
if (alive HR1) then {

	[color="SeaGreen"]// Get a random group type and spawn it.  Do this twice.[/color]
	_grouptype = floor (random count _grouptypes);
	_grp1 = [[0,0,0], west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> _grouptypes select _grouptype)] call BIS_fnc_spawnGroup;
	_grouptype = floor (random count _grouptypes);
	_grp2 = [[0,0,0], west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> _grouptypes select _grouptype)] call BIS_fnc_spawnGroup;

	[color="SeaGreen"]// Assign them and move them to cargo so the helos know they have cargo.[/color]
	{_x assignAsCargo HR1;_x moveInCargo HR1} forEach units _grp1;
	{_x assignAsCargo HR1;_x moveInCargo HR1} forEach units _grp2;
	[color="SeaGreen"]// Not entirely sure we need this, but seemed to cut down on deaths upon disembarkment.[/color]
	_wp = _grp1 addWaypoint [getMarkerpos _lz, 1];
	[_grp1, 1] setWaypointType "GETOUT";
	_wp = _grp2 addWaypoint [getMarkerpos _lz, 1];
	[_grp1, 2] setWaypointType "GETOUT";

	[color="SeaGreen"]// Set group 1 and 2 up to patrol at the LZ.[/color]
	[_grp1, (getMarkerpos _lz), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;
	[_grp2, (getMarkerpos _lz), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;


};

[color="SeaGreen"]// if the second bird is alive...[/color]
if (alive HR2) then {

	[color="SeaGreen"]// Get a random group type and spawn it.  Do this twice.[/color]
	_grouptype = floor (random count _grouptypes);
	_grp3 = [[0,0,0], west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> _grouptypes select _grouptype)] call BIS_fnc_spawnGroup;
	_grouptype = floor (random count _grouptypes);
	_grp4 = [[0,0,0], west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> _grouptypes select _grouptype)] call BIS_fnc_spawnGroup;

	[color="SeaGreen"]//  Assign the groups as cargo and move them into the bird.[/color]
	{_x assignAsCargo HR2;_x moveInCargo HR2} forEach units _grp3;
	{_x assignAsCargo HR2;_x moveInCargo HR2} forEach units _grp4;	
	[color="SeaGreen"]// Safety waypoint...[/color]
	_wp = _grp3 addWaypoint [getMarkerpos _lz, 1];
	[_grp3, 1] setWaypointType "GETOUT";
	_wp = _grp4 addWaypoint [getMarkerpos _lz, 1];
	[_grp4, 1] setWaypointType "GETOUT";

	[color="SeaGreen"]// Have groups 3 and 4 patrol as well.[/color]
	[_grp3, (getMarkerpos _lz), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;
	[_grp4, (getMarkerpos _lz), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;


};
[color="SeaGreen"]// Alert the player that reinforcements are coming.[/color]
_msg = format["Wave %1 spawned",HR_wavecount];
_nic = [nil,nil,rHINT,_msg] call RE;
[color="SeaGreen"]// Reduce the wave count[/color]
HR_wavecount = HR_wavecount - 1;
publicvariable "HR_wavecount"; 

} else {
[color="SeaGreen"]// Once we've done all the waves, delete the flight group.[/color]
_nic = [nil,nil,rHINT,"Reinforcements no longer available!"] call RE;
{{deleteVehicle _x} forEach crew _x;} foreach units HR_flightgroup;
{deleteVehicle _x} foreach units HR_flightgroup;

};

You can see this in action in my demo mission as well. In the demo mission you can use Radio Alpha or Bravo to board either helo to watch it's progress.

Let me know if you have any problems with this or comments. :)

Share this post


Link to post
Share on other sites

Thanks kylania, this is what I was exactly looking and more!

Only question is I wanted to add a couple more helicopters to land in another location but somehow only one spawning. I have included the two scripts that I modiefied for 2nd groupof Helipcopters.

The other questions:

- is how to make the infantry "attack" at FULL speed ?

- How do you specify how large squad spawned in helicopter? are their size pre determined?

- Can you just replace units with 3rd party addons class names in script? Like desert soldiers, Ch-47 Heli?

Thanks for your great help.

//////////////////////////////////////////////////////////////////

// Function file for Armed Assault

// Created by: 1ID-CPL. Venori

//////////////////////////////////////////////////////////////////

// Preplace 2 markers.

// "HP_SPAWN2" where you want the helos to start from and "reload" at.

// "HP_LZ2" where you want the helos to land.

// Only spawn once, on the server.

if(!isServer) exitWith{};

// Number of waves to bring in.

HR_wavecount = 5;

publicvariable "HR_wavecount";

// Create the group with 2 MH-60S

HR_flightgroup = creategroup west;

HR3 = ([getMarkerPos "HR_SPAWN2", 45, "MH60S", HR_flightgroup] call BIS_fnc_spawnVehicle) select 0;

HR3 setVehicleVarName "HR3";

publicvariable "HR3";

sleep 5;

HR4 = ([getMarkerPos "HR_SPAWN2", 45, "MH60S", HR_flightgroup] call BIS_fnc_spawnVehicle) select 0;

HR4 setVehicleVarName "HR4";

publicvariable "HR4";

// Make them fly pretty.

HR_flightgroup setFormation "COLUMN";

HR_flightgroup setBehaviour "CARELESS";

HR1 flyinHeight 35;

HR2 flyinHeight 40; // when flying at the same height they seemed to "wave" a lot.

// Spawn the first wave.

[hr_flightgroup, "HR_LZ2"] execVM "HR_spawnGroup2.sqf";

// Debug ride-along :)

p1 assignAsCargo HR4;

p1 moveinCargo HR4;

// Set the waypoints for the helo group. Their origin point is waypoint 0.

_wp = HR_flightgroup addWaypoint [getMarkerpos "HR_LZ2", 1]; // waypoint at the LZ marker.

_wp1 = HR_flightgroup addWaypoint [getMarkerPos "HR_SPAWN2", 1]; // waypoint back at the spawn marker.

_wp2 = HR_flightgroup addWaypoint [getMarkerPos "HR_SPAWN2", 1]; // Cycle waypoint at spawn marker too.

[hr_flightgroup, 1] setWaypointType "TR UNLOAD"; // Set the 1 (second actual waypoint, hence 1 instead of 0) to TRANSPORT UNLOAD.

[hr_flightgroup, 2] setWaypointType "MOVE"; // set the 2 waypoint to MOVE with the following call to spawn another group:

[hr_flightgroup, 2] setWaypointStatements ["true", "nul = [hr_flightgroup, ""HR_LZ""] execVM ""HR_spawnGroup.sqf"""];

[hr_flightgroup, 3] setWaypointType "CYCLE"; // set the 3 waypoint to CYCLE

----------------

//////////////////////////////////////////////////////////////////

// Function file for Armed Assault

// Created by: 1ID-CPL. Venori

//////////////////////////////////////////////////////////////////

// Called via waypoint with:

// nul = [hr_flightgroup, "HR_LZ2"] execVM "HR_spawnGroup2.sqf";

// Grab the input arguments

_helogroup = _this select 0;

_lz2 = _this select 1; // marker name.

// Distance between waypoints for the infantry's patrol waypoints.

_max_dist_between_waypoints = 100;

// Random types of groups to spawn.

_grouptypes = ["USMC_FireTeam","USMC_FireTeam_MG","USMC_FireTeam_AT","USMC_FireTeam_Support","USMC_HeavyATTeam"];

// Only do this if we're the server...

if(!isServer) exitWith{};

// As long as we haven't done all the waves, lets make new ones!

if (HR_wavecount > 0) then {

// If the first bird is alive...

if (alive HR3) then {

// Get a random group type and spawn it. Do this twice.

_grouptype = floor (random count _grouptypes);

_grp5 = [[0,0,0], west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> _grouptypes select _grouptype)] call BIS_fnc_spawnGroup;

_grouptype = floor (random count _grouptypes);

_grp6 = [[0,0,0], west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> _grouptypes select _grouptype)] call BIS_fnc_spawnGroup;

// Assign them and move them to cargo so the helos know they have cargo.

{_x assignAsCargo HR3;_x moveInCargo HR3} forEach units _grp5;

{_x assignAsCargo HR3;_x moveInCargo HR3} forEach units _grp6;

// Not entirely sure we need this, but seemed to cut down on deaths upon disembarkment.

_wp = _grp5 addWaypoint [getMarkerpos _lz2, 1];

[_grp5, 1] setWaypointType "GETOUT";

_wp = _grp6 addWaypoint [getMarkerpos _lz2, 1];

[_grp6, 2] setWaypointType "GETOUT";

// Set group 1 and 2 up to patrol at the LZ.

[_grp5, (getMarkerpos _lz2), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;

[_grp6, (getMarkerpos _lz2), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;

};

// if the second bird is alive...

if (alive HR4) then {

// Get a random group type and spawn it. Do this twice.

_grouptype = floor (random count _grouptypes);

_grp7 = [[0,0,0], west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> _grouptypes select _grouptype)] call BIS_fnc_spawnGroup;

_grouptype = floor (random count _grouptypes);

_grp8 = [[0,0,0], west, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> _grouptypes select _grouptype)] call BIS_fnc_spawnGroup;

// Assign the groups as cargo and move them into the bird.

{_x assignAsCargo HR2;_x moveInCargo HR4} forEach units _grp7;

{_x assignAsCargo HR2;_x moveInCargo HR4} forEach units _grp8;

// Safety waypoint...

_wp = _grp7 addWaypoint [getMarkerpos _lz2, 1];

[_grp7, 1] setWaypointType "GETOUT";

_wp = _grp4 addWaypoint [getMarkerpos _lz, 1];

[_grp8, 1] setWaypointType "GETOUT";

// Have groups 3 and 4 patrol as well.

[_grp7, (getMarkerpos _lz2), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;

[_grp8, (getMarkerpos _lz2), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;

};

// Alert the player that reinforcements are coming.

_msg = format["Wave %1 spawned",HR_wavecount];

_nic = [nil,nil,rHINT,_msg] call RE;

// Reduce the wave count

HR_wavecount = HR_wavecount - 1;

publicvariable "HR_wavecount";

} else {

// Once we've done all the waves, delete the flight group.

_nic = [nil,nil,rHINT,"Reinforcements no longer available!"] call RE;

{{deleteVehicle _x} forEach crew _x;} foreach units HR_flightgroup;

{deleteVehicle _x} foreach units HR_flightgroup;

};

Edited by CaptainBravo

Share this post


Link to post
Share on other sites

Ahh feature creep...

All the things you want are possible, but would require extensive restructuring of the code as presented (which was exactly what the original design was right? :) Hence "feature creep", the addition of features to a program after the original design requirements are set, often constant and late coming).

To make these changes though it's not as easy as just changing a few variables. Like for the "full speed attack" thing, we'd have to add in another marker or something to mark where they'll attack to as well as having to manually create a waypoint or series of them instead of the elegant 1 line of code to make them patrol.

It's almost starting to get to the point where if you want multiple groups of infantry to appear and attack multiple targets this whole thing of flying them in waves is more complicated than it needs to be. Just spawn the soldiers near their objectives and let them go, sure it's neat to have helicopters fly them in, but will the player actually see this happening, each and every time? If not, this becomes a lot of overheard for nothing.

- is how to make the infantry "attack" at FULL speed ?

You'd have to replace the TaskPatrol functions with SAD waypoints probably.

- How do you specify how large squad spawned in helicopter? are their size pre determined?

Currently each bird gets two pre-formed 3-4 man fire teams, chosen randomly from the list of BIS groups at the top of HR_spawnGroup.sqf. You could easily change that to x number of units, or even specify the very units you wanted, but the design request said "BIS Function would be ideal specially that it can delete units I believe and I would use pre made infantry squads". :) You could even dump that whole section and create the units in a different way.

- Can you just replace units with 3rd party addons class names in script? Like desert soldiers, Ch-47 Heli?

Assuming they had a mod running, sure.

Any of these changes though ups the complexity of the script and how to call it. Instead of just needing 2 markers you'll need 3 markers, per helo group, instead of no arguments you'll need class of helo, if addons aren't available you'll need it to default to normal classes, type of group structure to be used, the type of spawn system to be used, the number of units or classes of units to be used, whether or not to use patrol or waypoints, if patrol is do you patrol near the LZ or a specific location, if specific is it per group or everyone, how far away to you want waypoints, if waypoint option is used then you need the destination marker listed... and so on.

Basically all the options you want are in the code already in one form or another. Instead of the whole >> groups >> thing, replace it with a number and that's how many random units you'll get. If you wanted custom units, use units that have group configs preset. Instead of the MH60S, just replace that with whatever classname for your custom vehicle. Adapt the helo's waypoint code to work for your spawned groups. Ideally it would be one system that could be called many ways via arguments, but it'll take time to develop and have it work correctly. :) A bunch of hard coded versions of the above would work too, but that's just messy but doable.

Share this post


Link to post
Share on other sites

Thanks kylania for your great help. The scripts works great as is. I thought it might be like the Norrin UPS script where you can spawn any units be it BIS or addons without any codes. Since the BIS function spawn is new I was not sure how easy/hard it would be to modify spawn.

I have managed finally to get a second group of helicopters to work and drop troops as well. :yay:

As to why have troops fly in vs just spawn near objective, one of the objectives is to clear and secure landing zone while troops keep cominging in.

As it stands, it works mostly, I just have to figure how to get troops to move to target.

Thanks again for the great help.

:cheers:

Edited by CaptainBravo

Share this post


Link to post
Share on other sites
Thanks kylania, this is what I was exactly looking and more!

Only question is I wanted to add a couple more helicopters to land in another location but somehow only one spawning. I have included the two scripts that I modiefied for 2nd groupof Helipcopters.

The other questions:

- is how to make the infantry "attack" at FULL speed ?

- How do you specify how large squad spawned in helicopter? are their size pre determined?

- Can you just replace units with 3rd party addons class names in script? Like desert soldiers, Ch-47 Heli?

Thanks for your great help.

I've modified the scripts so that they do, or can do, most everything you want now.

The scripts are all dynamic, so you can use two of them at a time for two different locations if you want.

There's a flag for patrol vs Search and Destroy.

There's a flag for either 2 random fireteams or X number of units.

There's a flag for what type of helo you wanted to use, or side even, so the Chinook or Russians should work (untested...)

Desert soldiers didn't work since that unit pack doesn't include cfgGroups.

Here's a taste, I'll post the whole thing tomorrow, it's 3am I need to pass out. :)

Default:
nul = ["firstwave",["HR_SPAWN","HR_LZ"],5,["HR1","HR2"]] execVM "HR.sqf";
-- mission called "firstwave", 5 waves of 2 fireteams patrolling the LZ from 2 helos.

Full options:
nul = ["firstwave",["HR_SPAWN","HR_LZ","HR_PP"],2,["HR1","HR2","HR3"],10,false,"MH60S",west] execVM "HR.sqf";
-- mission called "firstwave", 2 waves of 10 units in each of 3 helos which will Search and Destroy at marker HR_PP.

Share this post


Link to post
Share on other sites

Demo Mission

Here's the code, some of this isn't perfect and the helos still act pretty stupid (first one seems to land at the Patrol Point rather than LZ??) but it should do all you'd requested. :) init.sqf remains the same.

If anyone has some ideas for improving this, I'd appreciate the advice. :)

HR.sqf:

[color="SeaGreen"]//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: 1ID-CPL. Venori
//////////////////////////////////////////////////////////////////
// Preplace 2 markers.  
// 	"HR_SPAWN" where you want the helos to start from and "reload" at.
//	"HR_LZ" where you want the helos to land.
//    (Optional) "HR_PP" where you want the ground troops to attack/patrol.

/*
Required Arguments:

 ["missionname",["HR_SPAWN","HR_LZ","HR_PP"],2,["HR1","HR2","HR3"],8,false,"MH60S",west]

 missionname (Datatype = string)
This is the name of the mission.  It will be used as a public variable to keep track of how many reinforecment waves are left.

 ["Spawn Marker Name","LZ Marker Name","Optional Patrol Point Name"] (Datatype = array of strings)
The first element is the name of the spawn point marker.  The second element is the name of the LZ point marker.  The third element is optional and is the name of the patrol/attack point marker.

 2 (Datatype = number)
This argument is the number of waves to call, how many times the helicopters will bring in troops.

 ["HR1","HR2"] (Datatype = array of strings)
The next argument is an array of strings, each will become the name of a vehicle used by the script.  No limit, but anything more than 2-3 can result in midair collisons. :)

Optional Arguments:

 8 (Datatype = number) (Optional)
Default is 0.  This element controls the type of groups spawned.  If set to 0 two random pre-built fireteams will be spawned (6-8 men per helo) if set to a number greater than 0 that many soldiers will be spawned as one group.

 false (datatype = boolean) (Optional)
Default is true.  If set to false the spawned infantry groups will patrol the LZ or optionally declared Patrol Point.  If set to true they'll Search and Destroy at the location.

 "MH60S" (Datatype = string) (Optional)
Default is "MH60S".  This element is the class name of the vehicle spawned for this script.

 west (Datatype = side) (Optional) (Untested)
Default is west.  This element determines the side of the vehicle being spawned, and therefore the units as well.

Examples:

Default:
nul = ["firstwave",["HR_SPAWN","HR_LZ"],5,["HR1","HR2"]] execVM "HR.sqf";
-- mission called "firstwave", 5 waves of 2 fireteams Search and Destroy at the LZ from 2 helos.

Full options:
nul = ["firstwave",["HR_SPAWN","HR_LZ","HR_PP"],2,["HR1","HR2","HR3"],10,false,"MV22"] execVM "HR.sqf";
-- mission called "firstwave", 2 waves of 10 units in each of 3 Ospreys which will Search and Destroy at marker HR_PP.
*/

// Required arguments[/color]
_missionName = _this select 0; [color="SeaGreen"]// string, name for mission[/color]
_waypoints = _this select 1; [color="SeaGreen"]// array, list of spawn, lz and attack waypoints.[/color]
 _waypointSpawn = _waypoints select 0; [color="SeaGreen"]// string, marker name, spawn point and reload point for helos[/color]
 _waypointLZ = _waypoints select 1; [color="SeaGreen"]// string, marker name, insertion point for helos[/color]
   _waypointPatrol = if (count _waypoints > 2) then {_waypoints select 2} else {_waypointLZ}; [color="SeaGreen"]// string, optional marker name, attack point for ground units, defaults to LZ[/color]
_waveCount = _this select 2; [color="SeaGreen"]// number, how many waves to drop off.[/color]
_vehicles = _this select 3;  [color="SeaGreen"]// array, strings, object names for the helos.[/color]
 _numVehicles = count (_this select 3); [color="SeaGreen"]// number, simple count of how many names were entered.

// Optional arguments[/color]
_groupCount = if (count _this > 4) then {_this select 4} else {0};[color="SeaGreen"] // number, how many units per chopper, overrides fireteam assignment.[/color]
_groupSpawnMethod = if (count _this > 5) then {_this select 5} else {true}; [color="SeaGreen"]// boolean, true = attack point, false = patrol point[/color]
_typeVehicles = if (count _this > 6) then {_this select 6} else {"MH60S"}; [color="SeaGreen"]// string, vehicle class, default "MH60S"[/color]
_vehicleSide = if (count _this > 7) then {_this select 7} else {west}; [color="SeaGreen"]// side, side of the groups created, default west.[/color]

[color="SeaGreen"]// Only spawn once, on the server.[/color]
if(!isServer) exitWith{};

[color="SeaGreen"]// Create the group. [/color]
_grp = creategroup _vehicleSide;
_fleet = [];

[color="SeaGreen"]// For each vehicle name given, create a vehicle and assign it it's wave count.[/color]
for "_x" from 1 to _numVehicles do
{
_veh = ([getMarkerPos _waypointSpawn, 45, _typeVehicles, _grp] call BIS_fnc_spawnVehicle) select 0;
_unitName = _vehicles select (_x - 1);
_veh setVehicleVarName _unitName;
call compile format ["%1 = _veh; publicVariable '%1';", _unitName];
//_veh setVariable[_missionName, 5, true];
sleep 5;
_fleet set [(_x - 1),_veh];
};

[color="SeaGreen"]// Make the group fly groupy.[/color]
_grp setFormation "COLUMN";
_grp setBehaviour "CARELESS"; 

[color="SeaGreen"]// Set the wave count[/color]
call compile format ["%1 = %2; publicVariable '%1';", _missionName, _waveCount,_waypointLZ];

[color="SeaGreen"]// Spawn the first wave.[/color]
[_missionName,_waypointPatrol,_fleet,_groupSpawnMethod,_groupCount] execVM "HR_spawnGroup.sqf";

[color="SeaGreen"]// Set the waypoints for the helo group.  Their origin point is waypoint 0.[/color]
_wp = _grp addWaypoint [getMarkerpos _waypointLZ, 1]; [color="SeaGreen"]// waypoint at the LZ marker.[/color]
_wp1 = _grp addWaypoint [getMarkerPos _waypointSpawn, 1];  [color="SeaGreen"]// waypoint back at the spawn marker.[/color]
_wp2 = _grp addWaypoint [getMarkerPos _waypointSpawn, 1]; [color="SeaGreen"] // Cycle waypoint at spawn marker too.[/color]
[_grp, 1] setWaypointType "TR UNLOAD";  [color="SeaGreen"]// Set the 1 (second actual waypoint, hence 1 instead of 0) to TRANSPORT UNLOAD.[/color]
[_grp, 2] setWaypointType "MOVE";  [color="SeaGreen"]// set the 2 waypoint to MOVE with the following call to spawn another group:[/color]
_waypointStatements = format["nul = [""%1"", ""%2"", %3, %4, %5, %6] execVM ""HR_spawnGroup.sqf""",_missionName,_waypointPatrol,_fleet,_groupSpawnMethod,_groupCount,_waypointLZ];
[_grp, 2] setWaypointStatements ["true", _waypointStatements];
[_grp, 3] setWaypointType "CYCLE";  [color="SeaGreen"]// set the 3 waypoint to CYCLE[/color]

[color="SeaGreen"]// For some reason the first helo ends up heading to the HR_PP instead of the LZ... I have no idea why. :([/color]

HR_spawngroup.sqf:

[color="SeaGreen"]//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: 1ID-CPL. Venori
//////////////////////////////////////////////////////////////////
// Called via waypoint with:
// 	

/*
nul = [_missionName,_waypointPatrol,_vehicles,_groupSpawnMethod,_groupCount,_waypointLZ] execVM "HR_spawnGroup.sqf"; 
*/

// Grab the input arguments[/color]
_missionName = _this select 0; [color="SeaGreen"]// string, set as a public variable in HR.sqf, used to count waves[/color]
 _currentCount = call compile format ["%1", _missionName]; [color="SeaGreen"]// number, Pull the value from it.[/color]
_waypointPatrol = _this select 1; [color="SeaGreen"]// string, marker name, waypoint to attack or patrol.[/color]
_vehicles = _this select 2; [color="SeaGreen"]// array, vehicle objects of vehicles assigned to 'missionname'[/color]
_groupSpawnMethod = _this select 3; [color="SeaGreen"]// boolean, attack (default/true) or patrol (false)[/color]
_groupCount = _this select 4; [color="SeaGreen"]// false or number, decided if you spawn fireteams or # of units.[/color]
_waypointLZ = _this select 5; [color="SeaGreen"]// string, marker name, waypoint to attack or patrol.[/color]

[color="SeaGreen"]// Hard coded options.[/color]
_max_dist_between_waypoints = 100;  [color="SeaGreen"]// Distance between waypoints for the infantry's patrol waypoints.[/color]
_grouptypes = ["USMC_FireTeam","USMC_FireTeam_MG","USMC_FireTeam_AT","USMC_FireTeam_Support","USMC_HeavyATTeam"];  [color="SeaGreen"]// Random types of groups to spawn.

// Only do this if we're the server...[/color]
if(!isServer) exitWith{};

[color="SeaGreen"]// As long as we haven't done all the waves, lets make new ones![/color]
if (_currentCount > 0) then {

{
	[color="SeaGreen"]// Since the helo names were passed as strings, convert them into objects.[/color]
	_helo = call compile format ["%1", _x]; 
	_count = call compile format ["%1", _groupCount]; 

	[color="SeaGreen"]// If the first bird is alive...[/color]
	if (alive _helo) then {
		[color="SeaGreen"]//hint format["Helo %1 is alive! count is %2",_helo,_count];
		// If the group count is a number greater than 0, spawn that many units in a group.[/color]
		if (_count > 0) then {			
			_grp1 = [[0,0,0], side _helo, _count] call BIS_fnc_spawnGroup;
			{_x assignAsCargo _helo;_x moveInCargo _helo} forEach units _grp1;

			[color="SeaGreen"]// This was an attempt to stop the lead chopper from flying to PP, didn't work. :([/color]
			_wp = _grp1 addWaypoint [getMarkerpos _waypointLZ, 1];
			[_grp1, 1] setWaypointType "GETOUT";

			[color="SeaGreen"]// If SAD option, make them SAD otherwise patrol.[/color]
			if (_groupSpawnMethod) then { 
				_wp = _grp1 addWaypoint [getMarkerpos _waypointPatrol, 1]; [color="SeaGreen"]// waypoint at the LZ marker.[/color]
				[_grp1, 2] setWaypointType "SAD";  [color="SeaGreen"]// Search and Destroy.[/color]

			} else { 
				[color="SeaGreen"]// Set group 1 and 2 up to patrol at the LZ.[/color]
				[_grp1, (getMarkerpos _waypointPatrol), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;
			};

		[color="SeaGreen"]// We didn't want x num of men, so spawn two fireteams.[/color]	
		} else {
			[color="SeaGreen"]// Get a random group type and spawn it.  Do this twice.[/color]
			_grouptype = floor (random count _grouptypes);
			_grp1 = [[0,0,0], side _helo, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> _grouptypes select _grouptype)] call BIS_fnc_spawnGroup;
			_grouptype = floor (random count _grouptypes);
			_grp2 = [[0,0,0], side _helo, (configFile >> "CfgGroups" >> "West" >> "USMC" >> "Infantry" >> _grouptypes select _grouptype)] call BIS_fnc_spawnGroup;

			[color="SeaGreen"]// Assign them and move them to cargo so the helos know they have cargo.[/color]
			{_x assignAsCargo _helo;_x moveInCargo _helo} forEach units _grp1;
			{_x assignAsCargo _helo;_x moveInCargo _helo} forEach units _grp2;

			_wp = _grp1 addWaypoint [getMarkerpos _waypointLZ, 1];
			[_grp1, 1] setWaypointType "GETOUT";
			_wp2 = _grp2 addWaypoint [getMarkerpos _waypointLZ, 1];
			[_grp1, 1] setWaypointType "GETOUT";

			if (_groupSpawnMethod) then { 
				_wp3 = _grp1 addWaypoint [getMarkerpos _waypointPatrol, 1]; [color="SeaGreen"]// waypoint at the LZ marker.[/color]
				[_grp1, 2] setWaypointType "SAD";  [color="SeaGreen"]// Search and Destroy.[/color]
				_wp4 = _grp2 addWaypoint [getMarkerpos _waypointPatrol, 1]; // waypoint at the LZ marker.
				[_grp2, 2] setWaypointType "SAD";  [color="SeaGreen"]// Search and Destroy.					[/color]

			} else { 
				[color="SeaGreen"]// Set group 1 and 2 up to patrol at the LZ.[/color]
				[_grp1, (getMarkerpos _waypointPatrol), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;
				[_grp2, (getMarkerpos _waypointPatrol), _max_dist_between_waypoints] call BIS_fnc_taskPatrol;
			};				
		};
	};
} foreach _vehicles;

[color="SeaGreen"]// Alert the player that reinforcements are coming.
//	_msg = format["Wave %1 spawned",_currentCount];
//	_nic = [nil,nil,rHINT,_msg] call RE;
// Reduce the wave count by saving the count number back into the mission name variable[/color]
_currentCount = _currentCount - 1;
call compile format ["%1 = %2; publicVariable '%1';", _missionName, _currentCount];

} else {
[color="SeaGreen"]// Once we've done all the waves, delete the flight group.[/color]
_nic = [nil,nil,rHINT,"Reinforcements no longer available!"] call RE;
{{deleteVehicle _x} forEach crew _x;} foreach _vehicles;
{deleteVehicle _x} foreach _vehicles;

};

Share this post


Link to post
Share on other sites

Thanks kylania for the demo mission and great help.

It works fine after testing a few times. Ocassionally, as you said, the lead heli moving to Patrol Point. I have noticed if you move spawn marker around the heli did land at LZ.

I saw you said you had three helicopters but only saw 2 land. I have added HR3 to script but still end up with two .. any hints how to add 3rd Heli is appreciated :D

Over all great work! Thanks. :bounce3:

Share this post


Link to post
Share on other sites

I thought that might be the case so I moved spawn poit right above player head and only saw 2 :confused:

Edit: never mind, the triggor had only HR1 and HR2 in init field.

Just out of curiousty what is the line below the determines how many waves of reinforcments?

//////////////////////////////////////////////////////////////////

// Function file for Armed Assault

// Created by: 1ID-CPL. Venori

//////////////////////////////////////////////////////////////////

// Preplace 2 markers.

// "HR_SPAWN" where you want the helos to start from and "reload" at.

// "HR_LZ" where you want the helos to land.

// (Optional) "HR_PP" where you want the ground troops to attack/patrol.

/*

Required Arguments:

["missionname",["HR_SPAWN","HR_LZ","HR_PP"],2,["HR1","HR2","HR3"],8,false,"MH60S",west]

missionname (Datatype = string)

This is the name of the mission. It will be used as a public variable to keep track of how many reinforecment waves are left.

["Spawn Marker Name","LZ Marker Name","Optional Patrol Point Name"] (Datatype = array of strings)

The first element is the name of the spawn point marker. The second element is the name of the LZ point marker. The third element is optional and is the name of the patrol/attack point marker.

2 (Datatype = number)

This argument is the number of waves to call, how many times the helicopters will bring in troops.

["HR1","HR2","HR3"] (Datatype = array of strings)

The next argument is an array of strings, each will become the name of a vehicle used by the script. No limit, but anything more than 2-3 can result in midair collisons. :)

Optional Arguments:

8 (Datatype = number) (Optional)

Default is 0. This element controls the type of groups spawned. If set to 0 two random pre-built fireteams will be spawned (6-8 men per helo) if set to a number greater than 0 that many soldiers will be spawned as one group.

false (datatype = boolean) (Optional)

Default is true. If set to false the spawned infantry groups will patrol the LZ or optionally declared Patrol Point. If set to true they'll Search and Destroy at the location.

"MH60S" (Datatype = string) (Optional)

Default is "MH60S". This element is the class name of the vehicle spawned for this script.

west (Datatype = side) (Optional) (Untested)

Default is west. This element determines the side of the vehicle being spawned, and therefore the units as well.

Examples:

Default:

nul = ["firstwave",["HR_SPAWN","HR_LZ"],7,["HR1","HR2","HR3"]] execVM "HR.sqf";

-- mission called "firstwave", 5 waves of 2 fireteams patrolling the LZ from 2 helos.

Full options:

nul = ["firstwave",["HR_SPAWN","HR_LZ","HR_PP"],7,["HR1","HR2","HR3"],10,false,"MV22"] execVM "HR.sqf";

-- mission called "firstwave", 2 waves of 10 units in each of 3 Ospreys which will Search and Destroy at marker HR_PP.

*/

// Required arguments

_missionName = _this select 0; // string, name for mission

_waypoints = _this select 1; // array, list of spawn, lz and attack waypoints.

_waypointSpawn = _waypoints select 0; // string, marker name, spawn point and reload point for helos

_waypointLZ = _waypoints select 1; // string, marker name, insertion point for helos

_waypointPatrol = if (count _waypoints > 2) then {_waypoints select 2} else {_waypointLZ}; // string, optional marker name, attack point for ground units, defaults to LZ

_waveCount = _this select 2; // number, how many waves to drop off.

_vehicles = _this select 3; // array, strings, object names for the helos.

_numVehicles = count (_this select 3); // number, simple count of how many names were entered.

// Optional arguments

_groupCount = if (count _this > 4) then {_this select 4} else {0}; // number, how many units per chopper, overrides fireteam assignment.

_groupSpawnMethod = if (count _this > 5) then {_this select 5} else {true}; // boolean, true = attack point, false = patrol point

_typeVehicles = if (count _this > 6) then {_this select 6} else {"MH60S"}; // string, vehicle class, default "MH60S"

_vehicleSide = if (count _this > 7) then {_this select 7} else {west}; // side, side of the groups created, default west.

// Only spawn once, on the server.

if(!isServer) exitWith{};

// Create the group.

_grp = creategroup _vehicleSide;

_fleet = [];

// For each vehicle name given, create a vehicle and assign it it's wave count.

for "_x" from 1 to _numVehicles do

{

_veh = ([getMarkerPos _waypointSpawn, 45, _typeVehicles, _grp] call BIS_fnc_spawnVehicle) select 0;

_unitName = _vehicles select (_x - 1);

_veh setVehicleVarName _unitName;

call compile format ["%1 = _veh; publicVariable '%1';", _unitName];

//_veh setVariable[_missionName, 5, true];

sleep 5;

_fleet set [(_x - 1),_veh];

};

// Make the group fly groupy.

_grp setFormation "LINE";

_grp setBehaviour "CARELESS";

// Set the wave count

call compile format ["%1 = %2; publicVariable '%1';", _missionName, _waveCount,_waypointLZ];

// Spawn the first wave.

[_missionName,_waypointPatrol,_fleet,_groupSpawnMethod,_groupCount] execVM "HR_spawnGroup.sqf";

// Set the waypoints for the helo group. Their origin point is waypoint 0.

_wp = _grp addWaypoint [getMarkerpos _waypointLZ, 1]; // waypoint at the LZ marker.

_wp1 = _grp addWaypoint [getMarkerPos _waypointSpawn, 1]; // waypoint back at the spawn marker.

_wp2 = _grp addWaypoint [getMarkerPos _waypointSpawn, 1]; // Cycle waypoint at spawn marker too.

[_grp, 1] setWaypointType "TR UNLOAD"; // Set the 1 (second actual waypoint, hence 1 instead of 0) to TRANSPORT UNLOAD.

[_grp, 2] setWaypointType "MOVE"; // set the 2 waypoint to MOVE with the following call to spawn another group:

_waypointStatements = format["nul = [""%1"", ""%2"", %3, %4, %5, %6] execVM ""HR_spawnGroup.sqf""",_missionName,_waypointPatrol,_fleet,_groupSpawnMethod,_groupCount,_waypointLZ];

[_grp, 2] setWaypointStatements ["true", _waypointStatements];

[_grp, 3] setWaypointType "CYCLE"; // set the 3 waypoint to CYCLE

// For some reason the first helo ends up heading to the HR_PP instead of the LZ... I have no idea why. :(

Edited by CaptainBravo

Share this post


Link to post
Share on other sites

No, you don't have to change the actual script at all. If you want to change how it works you just change the options when calling it from a trigger. All the green stuff at the top explains the options.

The actual code to call the helos goes in your trigger.

So change the trigger that's on the map for clearing the airfield to have ["HR1","HR2","HR3"] and it should work.

Share this post


Link to post
Share on other sites

It works great now for the exception of lead heli moving to target area ocassionally.

The demo example the helicopters bring 2 waves, where in the code you can change that?

Thanks for a great script and greater explanation :)

Share this post


Link to post
Share on other sites

I think one of the problems might be this line:

_waypointStatements = format["nul = [""%1"", ""%2"", %3, %4, %5, %6] execVM ""HR_spawnGroup.sqf""",_missionName,_waypointPatro l,_fleet,_groupSpawnMethod,_groupCount,_waypointLZ];

I added in the trailing _waypointLZ late in development, and think I forgot to put "" "" around the %6, that might help, but not sure, i'll test tonight.

Open the mission in the editor, to the right of the player is a trigger, in it's onAct is where you change the settings.

Share this post


Link to post
Share on other sites

Thanks for your help. I have noticed that %3, %4, %5, %6 do not have "" "" . would that make a difference with weird behaviour of lead heli?

To clarify question on reinforcment waves, in the triggor init field:

nul = ["firstwave",["HR_SPAWN","HR_LZ","HR_PP"],3,["HR1","HR2","HR3"],12] execVM "HR.sqf";

is "3" the number of reinforcment waves?

Thanks for great script.

Edited by CaptainBravo

Share this post


Link to post
Share on other sites
Thanks for your help. I have noticed that %3, %4, %5, %6 do not have "" "" . would that make a difference with weird behaviour of lead heli?

%6 should, but the others are fine without.

To clarify question on reinforcment waves, in the triggor init field:

nul = ["firstwave",["HR_SPAWN","HR_LZ","HR_PP"],3,["HR1","HR2","HR3"],12] execVM "HR.sqf";

is "3" the number of reinforcment waves?

Thanks for great script.

Yup, sure is! Glad it's working out for you. :)

I had a few ideas for improving this I might try to work out this weekend.

Share this post


Link to post
Share on other sites

It is working great now, the helicopters still do their wierd landing once in a while but less frequent now that we have added " "

Thanks for making it very easy to modify! :bounce3:

--------

The only observation after testing it heavily in missions is Helicopters is sometimes they will just not land and instead just drop troops from high (50 meters). Not sure if that can be fixed by implmenting land command .. might be a bug with game?

Edited by CaptainBravo
Additional Info

Share this post


Link to post
Share on other sites

Hey kylania,

I just wanted to say thank you for your help. Here is a mission that utilizes your helicopter spawn script.

http://www.armaholic.com/page.php?id=7293

It works most of the time (except when lead heli just goes off to infantry target zone which is certain death!)

Any tips on landing yet?

Thanks for your help.

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  

×