Jump to content

Recommended Posts

                                                                                FUNCTIONS FOR GETTING / SETTING VEHICLE LOADOUT


Hi all,

Here is a script for getting the loadout of any vehicle or crate (any container in fact) then transfer it on another vehicle or crate.

This works in SP or MP.

This functions work also for virtual arsenal, edited, or scripted  with addAction command.

If any uniform, vest or backpack with their own custom loadout inside it, you'll recover the exact loadout for each one.

(I didn't push to keep the same ammo count on each mag...)

So, it's compatible and consistent with some automatic loaded backpacks, which will be loaded as you let them instead of their auto-default loadout.


NB1: The loadout of the receiving container will be replaced by the loadout you get.

NB2: see also the respawn vehicle script for integration of these two functions on respawning vehicles. (script to be issued soon).


parameters:  one objet <vehicle or crate, preferable> applying to  getVehicleLoadout,

                       two objects <new vehicle or crate, old vehicle or crate> applying to  getVehicleLoadout


Limitations: The object you picked the loadout with getVehicleLoadout must not be deleted before you apply the setVehicleLoadout on another object.

                   Not tested, crates and vehicles overall load limitations, if any. I didn't see any of them so far.



car1 call MGI_fnc_getVehicleLoadout;       //  you pick the current loadout of a vehicle;

cursorTarget call MGI_fnc_getVehicleLoadout; // if you're pointing at a backpack on ground, you pick its loadout

                                                                            (must stay on cursorTarget for transferring the whole backpack in a named  vehicle/crate);


[car2,crate1] call MGI_fnc_setVehicleLoadout; // you call the loadout of crate1, previously recorded with  MGI_fnc_getVehicleLoadout;

                                                                            The two objects must be present,
                                                                            not applicable on player or infantry units (see BI commands getUnitLoadout / setUnitLoadout)

                                                                           you apply the loadout of crate1 on car2, these two objects have now the same loadout.

[car2,cursorTarget] call MGI_fnc_setVehicleLoadout; // see above. If you are still on same cursorTarget, you pass the container to the new object

                                                                           (so,new vehicle must be named for debug console usage).



Codes to be run anywhere you need it, locally, preferably on server.





MGI_fnc_getVehicleLoadout = {
  _veh = param [0,objNull, [objNull]];
  _veh setVariable ["MGIallCont",[]];
  (_veh getVariable "MGIallCont") pushBack [_veh,itemCargo _veh,magazineCargo _veh,weaponCargo _veh,backpackCargo _veh];
  {(_veh getVariable "MGIallCont") pushBack [_x select 0,itemCargo (_x select 1),magazineCargo (_x select 1),weaponCargo (_x select 1),[]]} forEach everyContainer _veh;

0 = car1 call MGI_fnc_getVehicleLoadout;          // example






MGI_fnc_setVehicleLoadout = { 
  params [["_newVeh",objNull,[objNull]], ["_oldVeh",objNull,[objNull]]]; 
  if ( {_x isKindOf "CAManBase"} count [_newVeh,_oldVeh] >0 or isnil {_oldVeh getVariable "MGIallCont"}) exitWith {}; 
  if (!isnil {_oldVeh actionParams 0}) then { 
    private _flagArsenalDbl = false;
    if (!isnil {_oldVeh getVariable "bis_addVirtualWeaponCargo_cargo"}) then {
      _newVeh setVariable ["bis_addvirtualweaponcargo_cargo", _oldVeh getVariable ["bis_addvirtualweaponcargo_cargo",""]]
    for "_i" from 0 to (_oldVeh addAction ["",""]) -1 do { 
      if (!_flagArsenalDbl or !(["bis_fnc_arsenal",_oldVeh actionParams _i select 1] call bis_fnc_instring)) then { 
        private _act = _oldVeh actionParams _i; 
        {_act deleteAt 10;true} count [1,2]; 
        [_newVeh,_act] remoteExec ["addaction",0,true]; 
        if(["bis_fnc_arsenal",_oldveh actionParams _i select 1] call bis_fnc_instring) then {_flagArsenalDbl = true}; 
  if (typeOf _newVeh isEqualTo typeOf _oldVeh) then {
    private _oldTexture = getObjectTextures _oldVeh;   
    if ( count _oldTexture > 0) then {
      for "_i" from 0 to count _oldTexture - 1 do { 
        _oldTexture  set [_i,[_i,_oldTexture select _i]] 
      {_newVeh setObjectTextureGlobal _x } forEach _oldTexture; 
    private _animList = animationNames _oldVeh; 
    if (count _animList > 0) then { 
      _ll = [];   
      for "_i" from 0 to count _animList -1 do { 
        _ll pushBack [_animList select _i,_oldveh animationPhase (_animList select _i)]; 
      {_newVeh animate _x} forEach _ll; 
    if (_newVeh isKindOf "air") then {
      private _pylons = getPylonMagazines _oldVeh;
      private _pylonPaths = (configProperties [configFile >> "CfgVehicles" >> typeOf _oldVeh >> "Components" >> "TransportPylonsComponent" >> "Pylons", "isClass _x"]) apply {getArray (_x >> "turret")};
        _newVeh removeWeaponGlobal getText (configFile >> "CfgMagazines" >> _x >> "pylonWeapon")
      } forEach getPylonMagazines _newVeh;
       _newVeh setPylonLoadOut [_forEachIndex + 1, _x, true, _pylonPaths select _forEachIndex]
      } forEach _pylons;
    private _oldTrt = magazinesAllTurrets _oldVeh;
    {_newVeh removeMagazineTurret _x} forEach (magazinesAllTurrets _newVeh apply {[_x select 0,_x select 1]});
    {_newVeh addMagazineTurret _x} forEach _oldTrt;
    _x params ["_cont","_it","_mag","_wp",["_bpk",[]]]; 
    if (_cont isEqualType "") then { 
      _cont = everyContainer _newVeh select (_foreachindex -1) select 1; 
    } else { 
      _cont = _newVeh; 
    clearItemCargoGlobal _cont; 
    clearMagazineCargoGlobal _cont; 
    clearWeaponCargoGlobal _cont; 
    clearBackpackCargoGlobal _cont; 
    {_cont addItemCargoGlobal [_x,1];true} count _it; 
    {_cont addMagazineCargoGlobal [_x,1];true} count _mag; 
    {_cont addWeaponCargoGlobal [_x,1];true} count _wp; 
    {_cont addBackpackCargoGlobal [_x,1];true} count _bpk; 
  } forEach (_oldVeh getVariable ["MGIallCont",[]]); 

0 = [car2,car1] call MGI_fnc_setVehicleLoadout;             // example





  • Like 5

Share this post

Link to post
Share on other sites

Added some lines to save the textures and components for appearance (if any).

For example, Brown MB 4WD with no doors, no rear seat, no roll cage...

Just pay attention for the type of the vehicle. An "I_C_Offroad_02_unarmed_F" (indep.) is different from an "C_Offroad_02_unarmed_F" (civil).

Share this post

Link to post
Share on other sites

Tested in SP / MP hosted. Should be compatible with dedicated server.


Added some features applicable  if both vehicles are same type   (like new & old when respawning, see other script):

- vehicle skins (setObjectTextureGlobal to be tested on dedicated);

- vehicle custom appearance (doors, roll cage, fenders,... and other possibilities as in Editor)

- vehicle armament (turrets and pylons + magazines) as defined.


corrected bug as backpackCargo is defined for most of vehicles but not on static ones.

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