Jump to content
aeroson

GET/SET Loadout (saves and loads pretty much everything)

Recommended Posts

Updated versions frontpaged on the Armaholic homepage.

** all scripts + example mission combined in one archive.

================================================

We have also "connected" these pages to your account on Armaholic.

This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites

I wonder if there'd be an easy way to apply the getloadout and setloadout not only to player's units, but also to AI units in the players' group... I've been trying to add the respawn-eventhandler to AI units already, but it doesn't work, since _target is player for the get- and setloadout.sqf... I suppose changing the target to group player would eventually just lead to the saved loadout being placed on every unit of the group upon respawn of one unit, right?

Share this post


Link to post
Share on other sites

thank you for the update :)

One bug found: When a player is equipped with a bino and also has a laser designator inside his vest /uniform, the bino is removed after respawn and the laser designator is assigned instead.

Edited by goldenfiver

Share this post


Link to post
Share on other sites

Updated / Fixed

set_loadout.sqf v4.3

- Added: now using addItemTo commands

- Fixed: assigned binocular/laser designator is now properly added

@goldenfiver: Thank you, fixed.

@Pergor: These functions accept unit as target parameter, not a group. If you want to do something with each unit (memeber) of player's group you can do it like this:

(not tested and most likely not working, but you get the idea)

// Save loadout of all units in player's group
units_reference=[];
units_loadout=[];
{
units_reference set [_forEachIndex, _x];
units_loadout set [_forEachIndex, [_x] call getLoadout];
} forEach units group player


// Load previously saved loadout of all units in player's group
private["_i"];
{
_i = units_reference find _x;
[units_reference select _i, units_loadout select _i] spawn setLoadout;
} forEach units group player

Share this post


Link to post
Share on other sites

@Pergor: These functions accept unit as target parameter, not a group. If you want to do something with each unit (memeber) of player's group you can do it like this:

(not tested and most likely not working, but you get the idea)

Thank you, but I just added an Respawn-eventhandler for all playable units in the group that aren't a player. That way their gear is completely restored upon respawn (I mean... who cares about the amount of ammo an AI unit carries with him anyways;)).

Share this post


Link to post
Share on other sites

Updated versions frontpaged on the Armaholic homepage.

** all scripts + example mission combined in one archive.

================================================

We have also "connected" these pages to your account on Armaholic.

This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites
@Pergor: These functions accept unit as target parameter, not a group. If you want to do something with each unit (memeber) of player's group you can do it like this:

(not tested and most likely not working, but you get the idea)

// Save loadout of all units in player's group
units_reference=[];
units_loadout=[];
{
units_reference set [_forEachIndex, _x];
units_loadout set [_forEachIndex, [_x] call getLoadout];
} forEach units group player


// Load previously saved loadout of all units in player's group
private["_i"];
{
_i = units_reference find _x;
[units_reference select _i, units_loadout select _i] spawn setLoadout;
} forEach units group player

Hello aeroson,

Thank you very much for your script. I'm very interested about doing the same thing as Pergor, as I want to save all my team's gear (units are sometimes AI), I don't understand where I'm suppose ton insert this piece of code ?

Share this post


Link to post
Share on other sites
Hi,

great set of scripts but I have some questions.

I set a custom loadout that units starts with at mission start.

I set an ammobox with save and load actions and it works great. When you save a loadout, you respawn with it.

But how can I respawn with loadout that I set prior to mission start without saving the loadout at ammobox?

I used

player addEventHandler ["Respawn", {
       [player,loadout] spawn setLoadout;
   }
];

to have the loadout you save at ammobox after respawn.

If I use

loadout = [player] call getLoadout;

I respawn with default unit loadout not the one I set. Without this code I respawn in underwear.

Is there any solution?

@Janez: Instead of

loadout = [player] call getLoadout;

use this

if(!isDedicated) then {
[] spawn {
	waitUntil {!isNull player};
	sleep 5;
	loadout = [player] call getLoadout;
};
};

Hi again,

this worked great for quite some time but I dunno if something changed with your updates or arma updates, so now I spawn with one less magazine for primary weapon with every respawn.

Here is my loadout

_unit1 = [u1];
{
removeAllWeapons _x;
removeHeadgear _x;
removeUniform _x;
removeVest _x;
removeBackpack _x;
// Equipment
_x addHeadgear 'H_HelmetB';
_x addUniform 'U_B_CombatUniform_mcam';
_x addVest 'V_PlateCarrier1_rgr';
_x addBackpack 'B_TacticalPack_mcamo';
clearMagazineCargo (unitBackpack _x);
// Weapons
_x addItemToUniform '30Rnd_65x39_caseless_mag';
_x addItemToBackpack '3Rnd_HE_Grenade_shell';
_x addWeapon 'arifle_MX_GL_F';
_x addItemToUniform '30Rnd_65x39_caseless_mag';
_x addItemToUniform '30Rnd_65x39_caseless_mag';
_x addItemToUniform '30Rnd_65x39_caseless_mag';
_x addItemToUniform '30Rnd_65x39_caseless_mag';
_x addItemToUniform '30Rnd_65x39_caseless_mag';
_x addItemToVest '30Rnd_65x39_caseless_mag';
_x addItemToVest '30Rnd_65x39_caseless_mag';
_x addItemToVest 'FirstAidKit';
_x addItemToVest 'FirstAidKit';
_x addItemToVest 'HandGrenade';
_x addItemToVest 'HandGrenade';
_x addItemToVest 'HandGrenade';
_x addItemToVest 'HandGrenade';
_x addItemToVest 'B_UavTerminal';
_x assignItem 'B_UavTerminal';
_x addItemToBackpack '3Rnd_HE_Grenade_shell';
_x addItemToBackpack '3Rnd_HE_Grenade_shell';
_x addItemToBackpack '3Rnd_HE_Grenade_shell';
_x addItemToBackpack '3Rnd_HE_Grenade_shell';
_x addItemToBackpack '3Rnd_HE_Grenade_shell';
_x addWeapon 'Rangefinder';
// Attachments
_x addPrimaryWeaponItem 'acc_pointer_IR';
_x addPrimaryWeaponItem 'optic_Hamr';
_x selectWeapon 'arifle_MX_GL_F';
} forEach _unit1;

Share this post


Link to post
Share on other sites

Great script aeroson, much appreciated! One thing though: It's just a minor issue and maybe you know already about it but get_loadout does not save attachments and loaded ammo of a weapon inside the backpack. E.g. I've tested to take a rifle as primary waepon, a pistol as handgun and an additional loaded SMG with optics in my backpack. I've saved my laodout and applied it on another unit (no additional parameters). The SMG was inside the backpack, without the magazine and optics though. Oh, for the record, I took SMG and optics separately and put them together in-game, so the classname of the SMG was not one which would come with optics by default.

Share this post


Link to post
Share on other sites
@Pergor: These functions accept unit as target parameter, not a group. If you want to do something with each unit (memeber) of player's group you can do it like this:

(not tested and most likely not working, but you get the idea)

// Save loadout of all units in player's group
units_reference=[];
units_loadout=[];
{
units_reference set [_forEachIndex, _x];
units_loadout set [_forEachIndex, [_x] call getLoadout];
} forEach units group player


// Load previously saved loadout of all units in player's group
private["_i"];
{
_i = units_reference find _x;
[units_reference select _i, units_loadout select _i] spawn setLoadout;
} forEach units group player

Hi aeroson,

I still can't make this work, would you help to clarify how to do please ? Maybe it would be great to add this function to your script and propose to mission makers to choose if they want to attach it to players only or to AI units too ?

:)

Share this post


Link to post
Share on other sites

I came back to using this great script again for a mission I am putting together and it seems that it is now not allowing anti tank or AA titans to lock on a target. to duplicate the issue just use the sample mission, change the soldier to an AT soldier and put down an enemy vehicle and attempt to lock on.

I used this example in my mission and took me ages to figure it was this that was causing it, thank you for any possible help to sort this out.

waitUntil { !isNull player }; // Wait for player to initialize

// Compile scripts
getLoadout = compile preprocessFileLineNumbers 'get_loadout.sqf';
setLoadout = compile preprocessFileLineNumbers 'set_loadout.sqf';

// Save loadout (including ammo count) every 2 seconds
[] spawn {
   while{true} do {
       if(alive player) then {
           loadout = [player,["ammo"]] call getLoadout;
       };
   sleep 2;  
   };
};

// Load saved loadout (including ammo count) on respawn
player addEventHandler ["Respawn", {
       [player,loadout,["ammo"]] spawn setLoadout;
   }
];  

Share this post


Link to post
Share on other sites

PtPau - I'm looking into a possible solution with currentWeapon as a secondary check to not run if the player is holding a launcher of some kind.

EDIT: I managed to come up with this:

// Save loadout every 2 seconds
[] spawn {
   while{true} do {
_weaponClass = currentWeapon player;
	if(_weaponClass isKindOf "Launcher") exitWith {};
		if(alive player) then {
			loadout = [player] call getLoadout;
		};
   sleep 2;  
   };
};

Thanks to Larrow for pointing out the previous error I had in the fix.

Edited by LKincheloe
Updating information

Share this post


Link to post
Share on other sites

Thanks for the effort BUT this appears not to work, I am sure I had read somewhere that isKindOf does not work on weapons? I have just adjusted the sleep to 10 seconds for a temporary fix, this gives me enough time to lock on.

Share this post


Link to post
Share on other sites

to check if it's a launcher you can do like this...

_weaponClass = getText(configFile >> ""CfgWeapons"" >> currentweapon player>> ""cursor"");
if(_weaponClass in [""missile"",""rocket""]) exitWith {};

Share this post


Link to post
Share on other sites

Try BIS_fnc_itemType . Something like ... UNTESTED so syntax may be slightly wrong but should point you in the right direction

if ( (([_weaponClass] call BIS_fnc_itemType) select 1) == "Launcher") exitWith {};

Share this post


Link to post
Share on other sites

I am trying this with the LEA to preload out , but for some reason having issue every few seconds my man changes back to side weapon then back again ?

Is there any issue using this is LEA ?

Share this post


Link to post
Share on other sites

It's not working for me with opfor players but it's working on blufor players.

I'm using caf agressors mod and hlc ak pack for the weapons but I assume this script supports external addons so I dont see where the problem could be.

Share this post


Link to post
Share on other sites

Would it not be better to use the new MPRespawn & MPKilled EventHandler ?

Share this post


Link to post
Share on other sites

I have enabled the save and loadout manager, is there a way I can get it to not give me my old VAS loadout options? I don't want them present for what i'm doing

Share this post


Link to post
Share on other sites

Excellent script, works superbly. We use this in place of the default BTC Revive loadout saver (which doesn't seem to work anymore).

I made a slight change to the init.sqf to improve efficiency slightly:

Replaced:

// Save loadout every 2 seconds
[] spawn {
   while{true} do {
       if(alive player) then {
           respawnLoadout = [player] call getLoadout;
       };
   sleep 2;  
   };
};

With:

// Save loadout whenever hit (more efficient than above method)
player addEventHandler ["Hit", {
	respawnLoadout = [player] call getLoadout;
}
];

This will save the loadout only when damage is taken (i.e. when needed), rather than saving the loadout every 2 seconds (which may cause some users lag, especially when running other script-heavy mods/missions).

;)

Edit: Also added this (to init.sqf) to save loadout when killed (will still kep HandleDamage EH as a fail-safe):

player addEventHandler ["Killed", {
respawnLoadout = [_this select 0] call getLoadout;
}
];

Edit 2: After some further testing, we've found the "Hit" EH to be more reliable & efficient than the "HandleDamage" EH. The "Killed" EH is also unreliable and not needed. Edited code above ^^

Edited by Goodson

Share this post


Link to post
Share on other sites

I wondered if anyone could help me make a script on 3 units, so i can save the loadout and when they respawn they will have the same gear as in the start? :)

Share this post


Link to post
Share on other sites

I am not sure if I am doing this right. I am trying to use the =BTC= Takeover but it doesn't seem to be working. Player have different loadouts when they respawn or get revived with =BTC=. Here is how I have it setup.

init.sqf

//=BTC=Revive Gear Replacer
execVM "scripts/takeover_btc.sqf";  

init_player.sqf

[] spawn {
waitUntil {!isNull player};
waitUntil {player == player};

//getLoadout/setLoadout
getLoadout = compile preprocessFileLineNumbers "scripts/get_loadout.sqf";
setLoadout = compile preprocessFileLineNumbers "scripts/set_loadout.sqf";

//loadout replace
player addEventHandler ["Hit", {
       	respawnLoadout = [player] call getLoadout;
   	}
];
}

Share this post


Link to post
Share on other sites

My apologies folks, it has been a while. I will happily accept any pull requests on git. Expect this to be quite a long post (ordered chronologically).

@ Janez: Sorry Janez at the moment iam not willing to spend days debuging, testing and inventing workarounds.

@ IndeedPete: Yup i think there is no way (i didn't try any) to get separate attachments and/or loaded magazines in weapons inside backpack/vest/uniform. The only way to save attachements is if the weapon comes with preconfigured classnames.

@ PtPau, LKincheloe, Mariodu62, Larrow, 1PARA{God-Father}: You are all very clever guys. The issue is the getLoadout makes unit switch thru all weapons really fast. Yup one solution is to check if you are holding launcher, but that only aplies to launchers. That is why i introducted the "repetitve" option flag. If the flag is used, getLoadout won't cycle thru all weapons, but it also won't be able to save each weapon's loaded magazine + ammo count.

                                                 
// Save loadout (including magazine + ammo count) every 2 seconds 
[] spawn { 
   while{true} do { 
       if(alive player) then { 
           loadout = [player,["ammo"]] call getLoadout; //<-- THIS LINE
       }; 
   sleep 2;   
   }; 
}; 

So the the line marked //<-- THIS LINE should be changed to:

           loadout = [player,["ammo","repetitive"]] call getLoadout; //<-- THIS LINE

@ DroopyPiles:

I have enabled the save and loadout manager, is there a way I can get it to not give me my old VAS loadout options? I don't want them present for what i'm doing

None uses old VAS nowadays. It has been hereby remove from the loadout manager. You can redownload it now.

@ MisterGoodson: You are very right. I didn't use the event handler either because revive scripts replaced / removed them. Or because they were not reliable, e.g. if you get killed in one hit, the hit event handler might not fire. Also in Arma 2 the best way to do this was to use the Killed event handler, but in Arma 3 when unit is killed it drops it's weapon. If you are willing to put your life on the line PM me the (revive script's compatible) changes i should made in the first post D:

@ Braae:

I wondered if anyone could help me make a script on 3 units, so i can save the loadout and when they respawn they will have the same gear as in the start? :)

This sounds like the ideal task for Arma Arsenal by Bohemia, but if you wish to use the set/get loadout functions read on:

Run your mission in singleplayer, select your loadout, then in console, save it into variable and then look at the variable and copy it's contents. You can then easily use these loadout contents to load loadout for any unit.

select loadout in game

execute in console: loadout = [player] call getLoadout

watch variable in console: loadout

copy contents of loadout into CLIPBOARD

paste this into your mission file:

unit1 addEventHandle["Respawn", {
_loadout = paste loadout from CLIPBOARD
[_this select 0, _loadout ] call setLoadout;
}];

repeat for all units you want

@ Kilo1:

I am not sure if I am doing this right. I am trying to use the =BTC= Takeover but it doesn't seem to be working. Player have different loadouts when they respawn or get revived with =BTC=. Here is how I have it setup.

First of all the takeovers are not maintained, specifically BTC takeover is for BTC version 0.92 and lastest BTC version is 0.98. The takovers also only replace the loadout handling functions. From the scripts you posted iam unsure of how you are executing the init_player.sqf

Edited by aeroson

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

×