Jump to content
aeroson

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

Recommended Posts

hi,

is it possible to load the loadout manager by scrpit not in the mission.sqm ?

Share this post


Link to post
Share on other sites

I seem to be having issues with the load script crashing when I use the Katiba with green tracer rounds - has anyone else encountered this?

This is amazing by the way :)

Share this post


Link to post
Share on other sites

@Mariodu62

Do you respawn without nades/rpg ammo or you just can't use it ?

In init.sqf you can run the loadout manager for every ammo box, like this:

{
 [_x] execVM 'loadout_manager.sqf';  
} forEach nearestObjects [getpos player,["ReammoBox","ReammoBox_F"],15000];

@Genesis92x

Sorry, i wasn't able to reproduce the bug. :(

Share this post


Link to post
Share on other sites

Hi aeroson,

No it's ok now... i just don't understand why ..

thkx for the code...

Share this post


Link to post
Share on other sites

If you are angry because =BTC= revive or Virtual Ammo Box is not loading your loadout correctly, then for you i've created and tested those two takeover scripts:

Takeover =BTC= revive

Just execVM 'takeover_btc.sqf';

It will replace BTC_get_gear and BTC_set_gear.

Takeover Virtual Ammo Box

VAS is using CfgFunctions which means those functions are compiled with compileFinal, so it is impossible to replace them at runtime.

That is why you have to replace file: 'VAS\functions\fn_loadGear.sqf' with this fn_loadGear.sqf

Both of these requires compiled set/get functions (usually in the mission's init.sqf)

getLoadout = compile preprocessFileLineNumbers 'get_loadout.sqf';
setLoadout = compile preprocessFileLineNumbers 'set_loadout.sqf';

If setLoadout or getLoadout is not found it will use original loadout handling functions.

(@Tonic and @Giallustio‎ iam sorry, i was waiting and hesitating for long time, but since you did not managed to fix all the bugs, it was my duty to do so)

Edited by aeroson

Share this post


Link to post
Share on other sites

hi , it is possible to change the output format for save in database ?

for my database i use this format :

[_uniform,_vest,_backpack,_magazines,_primary,_launcher,_handgun,_items,_primitems,_secitems,_handgunitems,_uitems,_vitems,_bitems,_casque,_lunette,_weapons,_chargeur_primaire,_chargeur_secondaire,_chargeur_tertiaire,_curent]

Share this post


Link to post
Share on other sites

Yup sure, just look to the bottom of get_loadout.sqf to see the output format.

For your needs it might look similar to this:

_loadout = [player] call getLoadout;

_yourLoadout = [
 _loadout select 7, // uniform
 _loadout select 9, // vest
 _loadout select 11, // backpack
 0, //_magazines, magazines are part of uniform/vest/backpack items, and currently loaded magazines are used latter
 _loadout select 1, // primary
 _loadout select 5, // secondary/launcher
 _loadout select 3, // handgun
 _loadout select 0, // assigned items 
 _loadout select 2, // primary items
 _loadout select 6, // secondary/launcher items
 _loadout select 4, // handgun items
 _loadout select 8, // uniform items
 _loadout select 10, // vest items
 _loadout select 12, // backpack items
 0, // if _casque means headgear, headgear is part of assignedItems
 0, // no idea what _lunette is (google translator is clueless)
 0, // _weapon, why would you need weapons if you already have them all ? if you mean weapons inside uniform/vest/backpack then its part of uniform/vest/backpack items
 (_loadout select 13) select 0, // if _chargeur_primaire means currenty loaded magazine in primary
 (_loadout select 13) select 2, // if _chargeur_secondaire means currenty loaded magazine in secondary/launcher
 (_loadout select 13) select 1, // if _chargeur_tertiaire means currenty loaded magazine in handgun
 _loadout select 14 // if _curent means currently selected weapon
];

Edited by aeroson

Share this post


Link to post
Share on other sites

hi and thanks a lot for you'r reply aeroson.

for my mission i have to call my saving script like this : _playerGear = [_character] call SES_SaveGear;

So to use you'r script i have to replace with this : _playerGear = [_character] call getLoadout;

i need to change something in the fnc_getloadout.sqf ? or is good ?

I want use you'r script for save and load in my MP mission without all "addaction"

It is possible to setup you'r script to save all the stuff in my Database ?

Thanks for you'r script .

Edit: When i use you'r script fnc_getloadout.sqf with any change , i get this inside my .rpt for the saving result :

playerGear: [array,string,array,string,array,string,array,string,array,string,array,string,array,[[],"",""],"",""]

Edited by kakarot

Share this post


Link to post
Share on other sites
hi and thanks a lot for you'r reply aeroson.

No problem

for my mission i have to call my saving script like this : _playerGear = [_character] call SES_SaveGear;

You can replace SES_SaveGear with this:

SES_SaveGear={
_loadout = [player] call getLoadout;	
_yourLoadout = [
	_loadout select 7, // uniform
	_loadout select 9, // vest
	_loadout select 11, // backpack
	0, //_magazines, magazines are part of uniform/vest/backpack items, and currently loaded magazines are used latter
	_loadout select 1, // primary
	_loadout select 5, // secondary/launcher
	_loadout select 3, // handgun
	_loadout select 0, // assigned items 
	_loadout select 2, // primary items
	_loadout select 6, // secondary/launcher items
	_loadout select 4, // handgun items
	_loadout select 8, // uniform items
	_loadout select 10, // vest items
	_loadout select 12, // backpack items
	0, // if _casque means headgear, headgear is part of assignedItems
	0, // no idea what _lunette is (google translator is clueless)
	0, // _weapon, why would you need weapons if you already have them all ? if you mean weapons inside uniform/vest/backpack then its part of uniform/vest/backpack items
	(_loadout select 13) select 0, // if _chargeur_primaire means currenty loaded magazine in primary
	(_loadout select 13) select 2, // if _chargeur_secondaire means currenty loaded magazine in secondary/launcher
	(_loadout select 13) select 1, // if _chargeur_tertiaire means currenty loaded magazine in handgun
	_loadout select 14 // if _curent means currently selected weapon
];
_yourLoadout; 
};

So to use you'r script i have to replace with this : _playerGear = [_character] call getLoadout;

You don't need to replace you'r SES_SaveGear with my getLoadout if you use function above.

i need to change something in the fnc_getloadout.sqf ? or is good ?

You don't need to change my fnc_getloadout.sqf if you use function above.

I want use you'r script for save and load in my MP mission without all "addaction"

You can use my script without all "addaction". You doing it if you use getLoadout.

It is possible to setup you'r script to save all the stuff in my Database ?

Yes it is possible to setup my script to save all the stuff in you'r Database, use function above.

Thanks for you'r script .

No problem

Edit: When i use you'r script fnc_getloadout.sqf with any change , i get this inside my .rpt for the saving result :

playerGear: [array,string,array,string,array,string,array,string,array,string,array,string,array,[[],"",""],"",""]

That output format is in end of get_loadout.sqf.

You should use my setLoadout, i fixed many errors.

If you use my setLoadout and my getLoadout you don't need to change my getLoadout output format.

Edited by aeroson

Share this post


Link to post
Share on other sites

Hi aeroson,

I still have sometimes issue with the contain of backpack. Lost item or missile for tubes.

i have modified my setloadout as below and i don't have any problem now.

_addbp = {
private ["_target","_item"];
_target = _this select 0;
_item = _this select 1;
if(typename _item == "ARRAY") then {
	if(_item select 0 != "") then {
		if(_loadMagsAmmo) then {
			_target addMagazine _item;
		} else {
			_target addMagazine (_item select 0);
		};
	};
} else {
	if(isClass(configFile>>"CfgMagazines">>_item)) then {
		(unitBackpack _target) addMagazineCargo [_item,1];
	} else {
		if(_item != "") then {
			if(getNumber(configFile>>"CfgVehicles">>_item>>"isbackpack")==1) then {
				(unitBackpack _target) addBackpackCargo [_item,1];  
			} else {
				if(isClass(configFile>>"CfgWeapons">>_item>>"WeaponSlotsInfo") && getNumber(configFile>>"CfgWeapons">>_item>>"showempty")==1) then {
					(unitBackpack _target) addWeaponCargo [_item,1];  
				} else {
					(unitBackpack _target) addItemCargo [_item,1];        
				};
			};
		};
	};
};
};

// add backpack and add backpack items
removeBackpack _target;
_outfit = _data select 11; 
if(_outfit != "") then {
if(getNumber(configFile>>"CfgVehicles">>_outfit>>"isbackpack")==1) then {
	_target addBackpack _outfit;                                                                    
	clearAllItemsFromBackpack _target;
	{
		[_target, _x] call _addbp;
	} foreach (_data select 12);
} else {
	systemchat format["backpack %1 doesn't exist",_outfit];
};
};

Share this post


Link to post
Share on other sites

Thank you Mariodu62, althought i kept _target addItem _item; because you can not add glasses with (unitBackpack _target) addItemCargo [_item,1];

Updated / Fixed

fnc_get_loadout.sqf v3.2

- Added: Saving magazines of assignedItems (laser designator)

- Fixed: Error when trying to add empty googles or headgear

fnc_set_loadout.sqf v4.0

- Added: Loading magazines of assignedItems (laser designator)

- Fixed: Launchers ammo should not disappear anymore

Edited by aeroson

Share this post


Link to post
Share on other sites

Ok... i will check because sometimes, the minedetector goes to my vest, that's why i used additemcacargo.

maybe we have to check for some exceptions.

Share this post


Link to post
Share on other sites

Hello aeroson, thanks for this update.

Did you noticed that the get_loadout function causes an RPT error on a dead unit ?

In the function "_backPackItems", backpackItems returns nothing (nil) for a dead unit.

Unfortunately, in a general way, BIS' commands returns empty values when the unit is dead.

It could be useful to do a global check on the script and throw a warning if the unit in parameter is dead, until BIS fix their commands.

To bypass this death problem, it also could be useful to implement a tool "watching the loadout" by saving the loadout of a unit in its namespace (setVariable) every X seconds and on "Hit/HandleDamage" event. For example :

// Add the watching system on a unit
[unit, ["ammo"]] call watch_loadout;

// Retrieving the unit loadout (even if unit is dead)
_loadout = unit getVariable "loadout";

watch_loadout =
{
   // For example adding event handler on hit or handledamage
   // Adding the unit in a loop thread
};

Maybe you will be interested by the evolution of these two tickets :

Inventory commands doesn't for a dead unit : http://feedback.arma3.com/view.php?id=4644

Request for some additionnal commands : http://feedback.arma3.com/view.php?id=14576

Edited by madbull

Share this post


Link to post
Share on other sites

i confirm that glasses are not put in the backpack but in the uniform and so do the mine detector.

For the mine detector we need additemcargo but for glasses ... i don't know..

Share this post


Link to post
Share on other sites

Hello aeroson,

The set loadout script freezes in two infinite loops.

To fill the uniform or vest, there is this kind of loop :

while { loadUniform _target < 1 } do {
_target addItem PLACEHOLDER_ITEM;
_placeholderCount = _placeholderCount + 1;
};

This loop generally does 10 000 loops to be finished, and can in some conditions never ends (use systemChat to be convinced).

For example if the ItemWatch takes a load of 0.05 in the uniform, and the loadUniform is 0.98, you can't add an additionnal ItemWatch, but the loop doesn't stop.

The ideal implementation could be :

_placeHolderUniformLoad = < computed from configFile, by deviding item mass by uniform capacity, I suppose >;
while { loadUniform _target + _placeHolderUniformLoad <= 1.0 } do {
_target addItem PLACEHOLDER_ITEM;
_placeholderCount = _placeholderCount + 1;
};

But it seems complex and unreliable to compute the ItemWatch load instead of the ArmA engine.

So I suggest this simple and reliable implementation :

while { true } do {
_loadBeforeAdd = loadUniform _target;
_target addItem PLACEHOLDER_ITEM;

// Last addItem has no effect, break without incrementing _placeholderCount
if (loadUniform _target == _loadBeforeAdd) exitWith {};

_placeholderCount = _placeholderCount + 1;
};

Best regards,

Share this post


Link to post
Share on other sites

EDIT : okay, BIS has just fixed the removeBackpack problem below in the today's update.

http://forums.bistudio.com/showthread.php?149636-Development-Branch-Changelog&p=2509459&viewfull=1#post2509459

My suggestion is no longer needed.

---

Hello aeroson,

At the moment, the command removeBackpack is bugged and spawn a dummy bugged backpack on the ground. It is reported here :

http://feedback.arma3.com/view.php?id=14634

http://feedback.arma3.com/view.php?id=7127

So each time we use the set loadout script, it drops a backpack on the ground (even if the unit has no backpack, due to the PLACEHOLDER_BACKPACK).

I added this line at the end of the script to delete the dummy backpack :

{deleteVehicle _x;} forEach nearestObjects [_target, ["GroundWeaponHolder"], 1];

When BIS will debug its command, this line will not produce a bug, but will have no effect.

Edited by madbull
BIS update

Share this post


Link to post
Share on other sites

@Mariodu62: I have no idea why, the placeholders should ensure items are added exactly where you want them. Maybe it has something to do with the way you use the functions ?

@madbull:

Basically the watch_loadout is in the examples (respawn with same gear), iam not using event handler because other scripts might removeAllEventHandlers.

And this load checking idea is brilliant ! Thank you so much.

Updated / Fixed

fnc_set_loadout.sqf v4.1

- Better vest/uniform placeholder filling (madbull)

Edited by aeroson

Share this post


Link to post
Share on other sites

I have started noticing a jerking motion on my character that coincides with the saving of the load out. So it happens every 2 sec or 10 seconds, depending how I have set it up in init.sqf.

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

// Compile scripts
getLoadout = compileFinal preprocessFileLineNumbers "scripts\fnc_get_loadout.sqf";
setLoadout = compileFinal preprocessFileLineNumbers "scripts\fnc_set_loadout.sqf";

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

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

It only happens when my character has the primary weapon on his hands. When switching to handgun the jerking stops.

Any ideas?

I am using versions 3.2 and 4.1 for getloadout and saveloadout.

Share this post


Link to post
Share on other sites

@KadinX

Yes, I noticed the "weapon jump" too. It also causes some other problems like getting out of binoculars, raising weapon, etc.

This is due to the option ["ammo"]. Removing it will solve the problem (but mags ammo will not be saved).

I suppose this is due to the usage of the selectWeapon command if ["ammo"] is used (not verified).

Share this post


Link to post
Share on other sites

I will give it a try but even if it works it will be a compromise :(

Share this post


Link to post
Share on other sites

I am using versions 3.2 and 4.1 for getloadout and saveloadout together with INS revive script and on pretty much every respawn/revive the player looses his map, gps, watch, compass and radio.

Anyone else having similar problems and found a solution?

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

×