r/armadev•
PlusP38

Respawning a plane with customized weapon pylons?

Question

The vehicle respawn module respawns the planes with their default loadout instead of the loadout set in the editor. Has anybody figured out how to keep the custom loadouts on respawn?

Posted May 31, 2017, 1:28 AM UTC

12
QS_iron•

Its a good idea to not think of it as "that plane respawning", but rather that plane getting destroyed and a completely new one spawning. The process might be called "respawn" but the old entity has nothing to do with the new entity.

You have to save characteristics of the old entity, and apply these characteristics to the new entity after it is spawned.

the general idea in SQF would look like this:

// old entity saving
missionnamespace setvariable ['tag_var_oldloadout',(getpylonmagazines <oldentity>];

// new entity applying
{
	<newentity> setPylonLoadout [_forEachIndex,_x];
} foreach (missionnamespace getvariable 'tag_var_oldloadout');
2
[deleted]•

[deleted]

1
PlusP38OP•

So in my usual "Why would anyone do it that way???" way, I figured out a fairly convenient (for me) way to do it.

I used

this respawnVehicle [20]

in the init line of the planes, base respawn, with respawn markers, and

private _pylons = PASTEHERE;
private _pylonPaths = (configProperties [configFile >> "CfgVehicles" >> typeOf _vehicle >> "Components" >> "TransportPylonsComponent" >> 
"Pylons", "isClass _x"]) apply {getArray (_x >> "turret")};
private _nonPylonWeapons = [];
{ _nonPylonWeapons append getArray (_x >> "weapons") } forEach ([_vehicle, configNull] call BIS_fnc_getTurrets);
{ _vehicle removeWeaponGlobal _x } forEach ((weapons _vehicle) - _nonPylonWeapons);
{ _vehicle setPylonLoadOut [_forEachIndex + 1, _x, true, _pylonPaths select _forEachIndex] } forEach _pylons;

(from this) with every _vehicle changed to the variable of the vehicle in the On Respawn field.

EDIT: PASTEHERE is where the actual loadout goes.

1
[deleted]•

Just wanted to make this a bit more clear for others like me who may be really new to scripting but want to make this work.

You want to respawn a vehicle. First you need to place a marker wherever you want the craft to respawn at with the prefix respawn_vehicle_west (assuming it's for blufor), you can add any text after that to specify multiple spawn points; they will be picked at random if you have more than one. Then go into attributes > multiplayer > respawn and select respawn on custom position. (I had three different ones named respawn_vehicle_west_1 etc)

Then you place your helicopter or plane you want to respawn and set up the pylons how you want them. You name it something in the variable field of its attributes, in my case "ah6_hydra"

Then in the init line below that you need to tell the craft to copy its pylon settings to your clipboard so you can replace that in the "PASTEHERE" spot.

So in the init line, you put:

copyToClipboard str getPylonMagazines this

Load into the game, then paste the pylon output to a text file or whatever you want, just hang onto it for now.

Then delete the copy line in the init line and replace it verbatim, with:

this respawnVehicle [20]

Then toward the bottom of attributes there's a category called "Event Scripting". You take PlusP38's code and literally find and replace all instances of "_vehicle" with whatever you named your plane/helo, and replace "PASTEHERE" with your pylon settings you copied. In my case:

private _pylons = ["CUP_PylonPod_19Rnd_Rocket_FFAR_M","CUP_PylonPod_19Rnd_Rocket_FFAR_M"];
private _pylonPaths = (configProperties [configFile >> "CfgVehicles" >> typeOf ah6_hydra >> "Components" >> "TransportPylonsComponent" >> 
"Pylons", "isClass _x"]) apply {getArray (_x >> "turret")};
private _nonPylonWeapons = [];
{ _nonPylonWeapons append getArray (_x >> "weapons") } forEach ([ah6_hydra, configNull] call BIS_fnc_getTurrets);
{ ah6_hydra removeWeaponGlobal _x } forEach ((weapons ah6_hydra) - _nonPylonWeapons);
{ ah6_hydra setPylonLoadOut [_forEachIndex + 1, _x, true, _pylonPaths select _forEachIndex] } forEach _pylons;
2
Kill_All_With_Fire•

Where do I paste my final code that I've collected?

2
PlusP38OP•

So I'm assuming you mean the the fully prepared version of the large bit of code, it goes in the On Respawn section of the vehicle's attributes.

If you meant the code that

copyToClipboard str getPylonMagazines this

gives you, there's a spot in the block of code with PASTEHERE where it goes.

If it's neither I might be an idiot and you need to eli5 lol

2
Kill_All_With_Fire•

On Respawn section

I don't see that. I'm using vanilla Eden. Is that an advanced feature or a modded version?

2