Jump to content
Sign in to follow this  
CaptainBravo

HELP: Spawn Vehicles /Planes

Recommended Posts

Lets say I wanted to have a flag that would spawn a empty unlocked vehicle from an select inventory accessible via UI list or scroll menu "Spawn Pickup, Car, Bus...etc."

How might that be accomplished in the most efficient manner?

Share this post


Link to post
Share on other sites

I love the group spawn scripts for infantry and vehicles! They give just about total control over mission design.

Quick related spwan question .. using Urban patrol script, I am trying (with no success) to hide markers of enemy groups on map. Could not find a clear answer on how to hide markers (in MP hosted games).

Any hints are highly appreciated as usual.

Share this post


Link to post
Share on other sites

Can't guarantee this is the best way to do this but in the past I've created an empty marker in the editor, which isn't seen on the game map. When the mission starts I then dynamically create a rectangular marker of the size needed at the empty marker I created in the editor. I then add the UTS script to the units to patrol the dynamically created rectangular marker - if I get a chance I'll post an example but it might be little while before I get to this.

Share this post


Link to post
Share on other sites

Thanks norrin. I will wait for your example mission as creating dynamic markers and adding UPS scripts after mission start has started is a bit outside my range :confused:

Thanks.

Share this post


Link to post
Share on other sites
Thanks norrin. I will wait for your example mission as creating dynamic markers and adding UPS scripts after mission start has started is a bit outside my range :confused:

Thanks.

Test mission with dynamically created (not visible) UPS patrol zones linked with AI respawn

Here it is: http://www.norrin.org/downloads/ArmA2/AI_respawn/aiRespawnUPSdynamicMrkrs.Chernarus.rar

This works a little differently to the previous example. This time we don't add the AI respawn and patrol code to the AI group leaders init lines but instead add it to the dynamic_UPS.sqf.

Here's how to make it work -

1. Copy across the code from the init.sqf into your own init.sqf and the dynamic.UPS.sqf and AI_respawn_UPS folder into your mission directory.

2. place a couple of empty markers on the map and name them - these are called UPS_z1 and UPS_z2 in the test mission. (NB: these won't show up on the in game map). These will now be the centres of the dynamically created rectangular UPS markers.

3. Create your groups of respawning patrolling units and name their leaders - called g1 and g2 in the test mission.

4. Adapt the dynamic.UPS.sqf to suit your purposes, this is where all the work is done and in the test mission it looks like this

 // Dynamic_UPS.sqf
// Dynamically create UPS marker and activate respawn on AI units.

if (!isServer) exitWith {};

// Dynamically create local rectangular marker at UPS_z1 - note rectangular marker will be visible if local to the server - not visible if not 
_zone_mrker1 = createMarkerLocal["UPS_zone1",[(getMarkerPos "UPS_z1") select 0,(getMarkerPos "UPS_z1") select 1]];
_zone_mrker1 setMarkerShapeLocal "rectangle";
"UPS_zone1" setMarkerSizeLocal [30, 80];

// Dynamically create local rectangular marker at UPS_z2
_zone_mrker2 = createMarkerLocal["UPS_zone2",[(getMarkerPos "UPS_z2") select 0,(getMarkerPos "UPS_z2") select 1]];
_zone_mrker2 setMarkerShapeLocal "rectangle";
"UPS_zone2" setMarkerSizeLocal [30, 80];

sleep 1;

// Now markers are created activate AI respawn scripts on group leaders (G1 and G2) to patrol these markers 
_allUnits = allUnits;
{if (_x == g1) then {[g1, 3, 10, "UPS_z1","UPS_zone1"] execVM "AI_respawn_UPS\AI_respawn_UPS_init.sqf"};}forEach _allUnits; 
{if (_x == g2) then {[g2, 3, 10, "UPS_z2","UPS_zone2"] execVM "AI_respawn_UPS\AI_respawn_UPS_init.sqf"};}forEach _allUnits;  

if (true) exitWith {};

Hopefully the commented code will help you work ou how to use this script in your own missions. For instance,

"UPS_zone1" setMarkerSizeLocal [30, 80];

refers to the size of the rectangular UPS marker dynamically created at the empty UPS_z1 marker that we placed in the editor.

Mate I'm not going to available for at least a couple of weeks now so good luck with this and I'm happy to answer any more questions when I get back.

Edited by norrin

Share this post


Link to post
Share on other sites

Place the functions module in the editor.

_vec_array = [markerPos "some_marker", random 360, "A10", west] call BIS_fnc_spawnVehicle;

Place the above info into a trigger.

That's it. Paramters and return values:

Parameter(s):

_this select 0: desired position (Array).

_this select 1: desired azimuth (Number).

_this select 2: type of the vehicle (String).

_this select 3: side or existing group (Side or Group).

Returns:

Array:

0: new vehicle (Object).

1: all crew (Array of Objects).

2: vehicle's group (Group).

The function will add the correct crew members, fill up all crew positions and will spawn aircrafts in the air, aka flying.

Share this post


Link to post
Share on other sites

@cobra - Mate, I may be wrong but I think he is trying to do something quite different to this as he wants the AI units to not only respawn a set number of times but also for them to use Kronzky's urban patrol script when they respawn. Before you suggest he uses the BIS_patrol function this also works in a different way as to my understanding Bravo wants his respawning AI to patrol a distinct zone as defined by a marker.

I see we've now jumped a page - Bravo please look at my previous post for a solution to your question.

Edited by norrin

Share this post


Link to post
Share on other sites

Awesome scripts Norrin. Took me a little while to figure out how everything worked and adapt it to my own map (I kept the credits intact, in case I decide to upload it for public use). In the end though, I managed to make a Defense map that's pretty intense and really fun.

Share this post


Link to post
Share on other sites

Hi Norrin,

Thank you very much for posting the mission example. That is exactly what I was looking for!! UPS AI with the group respawn!

2 questions (they never seem to end sorry):

- I assume that vehicles do not work with this one? When I place vehicles, they do not move.

- Since the marker is invisible I assume the patrol range (80 in example) is that from the respawn point for the group? What do I need to change if I wanted them to patrol a different zone?

Thanks for your great help.

Share this post


Link to post
Share on other sites

Wow this is quite a thread for noobs to sink their teeth in. Many thanks to Norrin - the stuff from Murray's Arma guide wasn't working for some reason. This does.

chopperSpawn_trigger as I only need my jets to spawn once. Can I create more than one flying jet with that script rather than creating a whole new set of waypoints and scripts for each new jet? I know the starting position probably has to be different, not to smack the two jets together. Is it a matter of

_group = createGroup EAST;

and then another

_group2 = createGroup EAST;

?

Share this post


Link to post
Share on other sites

If you use move and a random position, I think the chances of the jets somehow managing to spawn at such a time as to approach the same waypoint at the same randomized position is minimal... Especially if you only spawn them once.

But then again you never know with the Arma AI...

Share this post


Link to post
Share on other sites

With regards to Norrin's script:

// spawn_vcl.sqf

// JULY 2009 - norrin

if (!isServer) exitWith {};

_type = _this select 0;

_marker_pos = _this select 1;

// Create Vehicle

_vcl_new = _type createVehicle (getMarkerPos _marker_pos);

// Create Crew

_group = createGroup EAST;

"Ins_soldier_crew" createUnit [(getMarkerPos _marker_pos), _group];

"Ins_soldier_crew" createUnit [(getMarkerPos _marker_pos), _group];

"Ins_soldier_crew" createUnit [(getMarkerPos _marker_pos), _group];

_unitsGroup = units _group;

// Move crew in Vehicle

for [{ _loop = 0 },{ _loop < count _unitsGroup},{ _loop = _loop + 1}] do

{

_guy = _unitsGroup select _loop;

_guy setSkill 0.8;

if (_loop == 0) then {_guy moveInDriver _vcl_new};

if (_loop == 1) then {_guy moveInGunner _vcl_new};

if (_loop == 2) then {_guy moveInCargo _vcl_new};

sleep 0.1;

};

sleep 1;

// Add waypoints

_waypoint0 = _group addwaypoint[getmarkerpos"WP1",0];

_waypoint0 setwaypointtype"Move";

_waypoint1 = _group addwaypoint[getmarkerpos"WP2",0];

_waypoint1 setwaypointtype"Move";

How do I modify it so multiple vehicles belonging to the same group are spawned and all follow the waypoints added at the bottom?

Could I make _group a variable passed to the script and then run it three times?

i.e.

_grp = _this select 2;

_group = _grp

Share this post


Link to post
Share on other sites

:)This is my bodge mod of Norrin's script. Bet there is a more sophisticated (i.e. simple) way of doing this but baby steps :

// spawn_vcl.sqf

// JULY 2009 - norrin

//nul=["vehicle type","vehicle type","vehicle type","Spawn point marker","WP1 marker","wp2 Marker"] execvm "spawn_vcl.sqf";

if (!isServer) exitWith {};

_type1 = _this select 0;

_type2 = _this select 1;

_type3 = _this select 2;

_marker_pos = _this select 3;

_wp1 = _this select 4;

_wp2 = _this select 5;

// Create Vehicle

_vcl_new_1 = _type1 createVehicle [(getMarkerPos _marker_pos);

_vcl_new_2 = _type2 createVehicle [(getMarkerPos _marker_pos select 0)-10*sin(90),(getmarkerpos _marker_pos select 1)-10*cos(90)];

_vcl_new_3 = _type3 createVehicle [(getMarkerPos _marker_pos select 0)-20*sin(90),(getmarkerpos _marker_pos select 1)-20*cos(90)];

_vcl_new_1 setdir 90;

_vcl_new_2 setdir 90;

_vcl_new_3 setdir 90;

// Create Crew

_group = createGroup EAST;

"Ins_soldier_crew" createUnit [(getMarkerPos _marker_pos), _group];

"Ins_soldier_crew" createUnit [(getMarkerPos _marker_pos), _group];

"Ins_soldier_crew" createUnit [(getMarkerPos _marker_pos), _group];

"Ins_soldier_crew" createUnit [(getMarkerPos _marker_pos), _group];

"Ins_soldier_crew" createUnit [(getMarkerPos _marker_pos), _group];

"Ins_soldier_crew" createUnit [(getMarkerPos _marker_pos), _group];

_unitsGroup = units _group;

// Move crew in Vehicle

for [{ _loop = 0 },{ _loop < count _unitsGroup},{ _loop = _loop + 1}] do

{

_guy = _unitsGroup select _loop;

_guy setSkill 0.8;

if (_loop == 0) then {_guy moveInDriver _vcl_new_1};

if (_loop == 1) then {_guy moveInGunner _vcl_new_1};

if (_loop == 3) then {_guy moveInDriver _vcl_new_2};

if (_loop == 4) then {_guy moveInGunner _vcl_new_2};

if (_loop == 5) then {_guy moveInDriver _vcl_new_3};

if (_loop == 6) then {_guy moveInGunner _vcl_new_3};

sleep 0.1;

};

sleep 1;

// Add waypoints

_waypoint0 = _group addwaypoint[getmarkerpos _wp1,0];

_waypoint0 setwaypointtype"Move";

_waypoint1 = _group addwaypoint[getmarkerpos _wp2,0];

_waypoint1 setwaypointtype"Move";

This will create a group of vehicles that will have drivers and gunners who will drive to the waypoints listed. You need to play with the values in brackets after SIN and COS to set where in relation to the first vehcile the others spawn, but they'll all be spaced 10m apart. Also SetDir will set the direction the spawned vehicles face.

Adding in more vehicles and crew is just a matter of copy and pasting lines and incrementing the numbers above.

Edited by mcvittees

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  

×