pierremgi 4853 Posted May 27, 2017 (edited) 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. Examples: 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_getVehicleLdout Spoiler MGI_fnc_getVehicleLdout = { params [["_obj",objNull, [objNull]]]; private _allconts = everyContainer _obj; _allconts sort TRUE; _obj setVariable ["MGIallCont",[]]; (_obj getVariable "MGIallCont") pushBack [_obj,getItemCargo _obj,magazinesAmmoCargo _obj,weaponsItemsCargo _obj,backpackCargo _obj]; {(_obj getVariable "MGIallCont") pushBack [_x select 0,getItemCargo (_x select 1),magazinesAmmoCargo (_x select 1),weaponsItemsCargo (_x select 1),[]]} forEach _allconts; }; crate1 call MGI_fnc_getVehicleLdout; // example MGI_fnc_setVehicleLdout Spoiler MGI_fnc_setVehicleLdout ={ params [["_newCont",objNull,[objNull]], ["_oldcont",objNull,[objNull]]]; private _newEvryCont = []; { _x params ["_cont","_it","_mag","_wp",["_bpk",[]]]; _it params [["_typeIt",[]],["_cntIt",[]]]; if (_cont isEqualType "") then { if (_newEvryCont isNotEqualTo []) then { _cont = _newEvryCont select (_foreachindex -1) select 1; }; } else { _cont = _newCont; }; clearItemCargoGlobal _cont; clearMagazineCargoGlobal _cont; clearWeaponCargoGlobal _cont; clearBackpackCargoGlobal _cont; {_cont addItemCargoGlobal [_typeIt #_foreachindex,_cntIt #_foreachindex]} forEach _typeIt; {_cont addMagazineAmmoCargo [_x #0,1,_x #1]} forEach _mag; {_cont addWeaponWithAttachmentsCargoGlobal [_x,1]} forEach _wp; {_cont addBackpackCargoGlobal [_x,1]} forEach _bpk; if (_newEvryCont isEqualTo [] && {everyContainer _cont isNotEqualTo []}) then { _newEvryCont = everyContainer _cont; _newEvryCont sort TRUE; }; } forEach (_oldCont getVariable ["MGIallCont",[]]); }; [car2,crate1] call MGI_fnc_setVehicleLoadout; // example EDITED Edited June 3, 2023 by pierremgi UPDATED for ammo counts in all wpns inside all containers 6 Share this post Link to post Share on other sites
pierremgi 4853 Posted June 7, 2017 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
pierremgi 4853 Posted June 8, 2017 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
pierremgi 4853 Posted June 3, 2023 UPDATED for: - ammo counts in all weapons inside all containers - ammo counts for all magazines inside all containers - corrected: some sub-loadouts (i.e. loadouts inside bacpacks inside vehicle) were sometimes shifted between 2 backpack classes (or uniforms/or vests). The loadouts are correct according to classes now. Share this post Link to post Share on other sites