Jump to content
Sign in to follow this  
Bon

respawn with loadout incl. OA backpacks & -content

Recommended Posts

Hi all,

just saw the new OA beta patch comes with the commands to query a cargo space for weapons and magazines - at last :yay: :yay: :yay:

So first thing I did I scripted the possibility to save the current loadout including OA backpack and its content.

  1. create a script file and name it player_respawn.sqf. Write into it the following code:
    WaitUntil{not isNull player || isDedicated};
    
    player addEventHandler ["Killed",{
    player spawn {
    
    	_unit = _this;
    
    	private ['_magazines','_weapons','_backpack','_backpackweap','_backpackmags'];
    	if(isNil "savedloadout") then {
    		_weapons = weapons _unit;
    		_magazines = magazines _unit;
    		_backpack = typeOf unitBackpack _unit;
    		_backpackmags = getMagazineCargo unitBackpack _unit;
    		_backpackweap = getWeaponCargo unitBackpack _unit;
    	} else {
    		_weapons = savedloadout select 0;
    		_magazines = savedloadout select 1;
    		_backpack = savedloadout select 2;
    		_backpackmags = savedloadout select 3;
    		_backpackweap = savedloadout select 4;
    	};
    
    	WaitUntil{alive player};
    
    	removeAllWeapons player;
    	removeAllItems player;
                   removeBackpack player;
    	{player addMagazine _x} foreach _magazines;
    	{player addWeapon _x} foreach _weapons;
    	if (primaryWeapon player != "") then {
          			player selectWeapon (primaryWeapon player);
            	_muzzles = getArray(configFile>>"cfgWeapons" >> primaryWeapon player >> "muzzles"); // Fix for weapons with grenade launcher
    	        player selectWeapon (_muzzles select 0);
    	};
    	if(_backpack != "") then {
    		player addBackpack _backpack; clearWeaponCargo (unitBackpack player); clearMagazineCargo (unitBackpack player);
    
    		for "_i" from 0 to (count (_backpackmags select 0) - 1) do {
    			(unitBackpack player) addMagazineCargo [(_backpackmags select 0) select _i,(_backpackmags select 1) select _i];
    		};
    		for "_i" from 0 to (count (_backpackweap select 0) - 1) do {
    			(unitBackpack player) addWeaponCargo [(_backpackweap select 0) select _i,(_backpackweap select 1) select _i];
    		};
    	};
    };
    }];
    


    Then write into your init.sqf:

    [] execVM "player_respawn.sqf";
    


    That works already in a sense the player respawns with the loadout she/he died before.

  2. Now you can optionally create another script, let's name it saveloadout.sqf, and write into it the following code:
    _unit = _this select 1;
    
    _weapons = weapons _unit;
    _magazines = magazines _unit;
    _backpack = unitBackpack _unit;
    _backpackmagazines = getMagazineCargo _backpack;
    _backpackweapons = getWeaponCargo _backpack;
    
    savedloadout = [_weapons,_magazines,typeOf _backpack,_backpackmagazines,_backpackweapons];
    
    hint "current loadout saved";
    


  3. Add an action for saving ones current loadout to, lets say, an ammocrate, by writing into the crates init line:
    this addaction ["save loadout","saveloadout.sqf"];
    


hf.

Edited by Bon

Share this post


Link to post
Share on other sites

Cool new commands. Now we can finally add weapons and magazines during a misssion and still keep it JIP-friendly :). Or is there still no weapons and ammo on the server/is it local only?

Share this post


Link to post
Share on other sites

Nice! So for the first part, can I create a file called bla.sqf and then enter execVM "bla.sqf" in init.sqf? Will this work?

Share this post


Link to post
Share on other sites
Nice! So for the first part, can I create a file called bla.sqf and then enter execVM "bla.sqf" in init.sqf? Will this work?

Yes, just put it into a file and call it from the init script.

I recommend to add the line

WaitUntil{isDedicated || not isNull player};

to the very top of the script then, to avoid any initialization problems.

Share this post


Link to post
Share on other sites

Hi bon, do you have the script compatible with ACE and compatible with reconnections?

Share this post


Link to post
Share on other sites
Hi bon, do you have the script compatible with ACE and compatible with reconnections?

What means ACE compatibility in particular? If you think of the ACE rucksacks, I won't provide that.

There shouldn't occur any problems regarding to MP, JIP etc...

Share this post


Link to post
Share on other sites
What means ACE compatibility in particular? If you think of the ACE rucksacks, I won't provide that.

There shouldn't occur any problems regarding to MP, JIP etc...

yes, ace rucksacks. Did you tried your script after disconnection and reconnection?

Best regards

Share this post


Link to post
Share on other sites

Very few scripts are designed to handle disconnect/reconnect with regards to items, it's hard enough keeping track of items while the client is actually connected. :)

Share this post


Link to post
Share on other sites

This script works perfect exept that if your player's default payload includes a backpack, but you saved your payload with a rocket launcher, after you respawn, you will get both, which is not possible.

I changed the script to add a command :

removebackpack player;

Just after the lines :

removeAllWeapons player;

removeAllItems player;

So it also removes the default backpack when you respawn.

Share this post


Link to post
Share on other sites
This script works perfect exept that if your player's default payload includes a backpack, but you saved your payload with a rocket launcher, after you respawn, you will get both, which is not possible.

I changed the script to add a command :

removebackpack player;

Just after the lines :

removeAllWeapons player;

removeAllItems player;

So it also removes the default backpack when you respawn.

Thx for the hint. Updated the code in the first post.

Share this post


Link to post
Share on other sites

Only thing missing bon is "clear loadout" and the ability to save an older A2 style backpack.

Share this post


Link to post
Share on other sites
Only thing missing bon is "clear loadout" and the ability to save an older A2 style backpack.

1. clear loadout:

savedloadout = nil;

2. whats an A2 style backpack? And don't you come with ACE2 backpacks... That is ACE2 style, not A2 style, and as I mentioned before, I won't provide that.

Share this post


Link to post
Share on other sites
1. clear loadout:

savedloadout = nil;

2. whats an A2 style backpack? And don't you come with ACE2 backpacks... That is ACE2 style, not A2 style, and as I mentioned before, I won't provide that.

It's another weapon slot that is available in A2 and it allows you to carry another weapon, I'm a bit fuzzy on the details I do know that it's available in Domination though. Perhaps someone can enliten us on how it works exactly.

Don't know if this is of any help:

// by Xeno
private ["_anim","_mag_types","_magazines","_mags_backpack","_muzzles","_p","_primary","_s","_pistol","_base"];
_p = player;
if (pbp_id != -9999) then {
_p removeAction pbp_id;
pbp_id = -9999;
};

if (count player_backpack == 0) then {
_primary = primaryWeapon _p;
if (_primary != "") then {
	_mag_types = getArray(configFile>> "cfgWeapons" >> _primary >> "magazines");
	_magazines = magazines _p;
	_mags_backpack = [];
	{
		if (_x in _mag_types) then {
			[_mags_backpack, _x] call BIS_fnc_arrayPush;
		};
	} forEach _magazines;
	_muzzles = getArray(configFile>> "cfgWeapons" >> _primary >> "muzzles");
	if (count _muzzles == 2) then {
		_mag_types = getArray(configFile>> "cfgWeapons" >> _primary >> (_muzzles select 1) >> "magazines");
		{
			if (_x in _mag_types) then {
				[_mags_backpack, _x] call BIS_fnc_arrayPush;
			};
		} forEach _magazines;
	};
	_weapons = weapons _p;
	d_backpack_helper = [_magazines, _weapons];
	_pistol = "";
	{
		scopeName "pistolsearch";
		_base = inheritsFrom (configFile >> "cfgWeapons" >> _x);
		for "_xs" from 1 to 3 do {
			if (configName _base == "Pistol") then {
				_pistol = _x;
				breakOut "pistolsearch";
			};
			_base = inheritsFrom (configFile >> "cfgWeapons" >> (configName _base));
		};
	} forEach _weapons;
	if (_pistol != "") then {
		_p removeWeapon _pistol;
	};
	{
		_p removeMagazine _x;
	} forEach _mags_backpack;
	_p removeWeapon _primary;
	_anim = animationState _p;
	player_backpack = [_primary, _mags_backpack];
	waitUntil {animationState player != _anim || !alive player};
	if (!alive player) exitWith {};
	_p = player;
	_s = format ["Weapon %1", [_primary,1] call XfGetDisplayName];
	if (_pistol != "") then {
		_p addWeapon _pistol;
		_p selectWeapon _pistol;
	};
	if (pbp_id == -9999) then {
		pbp_id = _p addAction [_s call XGreyText, "x_scripts\x_backpack.sqf",[],-1,false];
	};
	if (alive player) then {
		d_backpack_helper = [];
	};
};
} else { // switch weapon
_primary = primaryWeapon _p;
if (_primary == "") then {
	{
		_p addMagazine _x;
	} forEach (player_backpack select 1);
	_p addWeapon (player_backpack select 0);
	_muzzles = getArray(configFile>>"cfgWeapons" >> (player_backpack select 0) >> "muzzles");
	_p selectWeapon (player_backpack select 0);
	_p selectWeapon (_muzzles select 0);
	_s = format ["%1 to Backpack", [player_backpack select 0,1] call XfGetDisplayName];
	player_backpack = [];
	if (pbp_id != -9999) then {
		_p removeAction pbp_id;
		pbp_id = -9999;
	};
	if (pbp_id == -9999) then {
		pbp_id = _p addAction [_s call XGreyText, "x_scripts\x_backpack.sqf",[],-1,false];
	};
} else {
	_mag_types = getArray(configFile>> "cfgWeapons" >> _primary >> "magazines");
	_magazines = magazines _p;
	_mags_backpack = [];
	{
		if (_x in _mag_types) then {
			[_mags_backpack, _x] call BIS_fnc_arrayPush;
		};
	} forEach _magazines;
	_muzzles = getArray(configFile>> "cfgWeapons" >> _primary >> "muzzles");
	if (count _muzzles == 2) then {
		_mag_types = getArray(configFile>> "cfgWeapons" >> _primary >> (_muzzles select 1) >> "magazines");
		{
			if (_x in _mag_types) then {
				[_mags_backpack, _x] call BIS_fnc_arrayPush;
			};
		} forEach _magazines;
	};
	{
		_p removeMagazine _x;
	} forEach _mags_backpack;
	_weapons = weapons _p;
	d_backpack_helper = [_mags_backpack, _primary];
	_pistol = "";
	{
		scopeName "pistolsearch2";
		_base = inheritsFrom (configFile >> "cfgWeapons" >> _x);
		for "_xs" from 1 to 3 do {
			if (configName _base == "Pistol") then {
				_pistol = _x;
				breakOut "pistolsearch2";
			};
			_base = inheritsFrom (configFile >> "cfgWeapons" >> (configName _base));
		};
	} forEach _weapons;
	if (_pistol != "") then {
		_p removeWeapon _pistol;
	};
	_p removeWeapon _primary;
	sleep 1;
	_anim = animationState _p;
	waitUntil {animationState player != _anim || !alive player};
	if (!alive player) exitWith {};
	_p = player;
	{
		_p addMagazine _x;
	} forEach (player_backpack select 1);
	if (_pistol != "") then {
		_p addWeapon _pistol;
	};
	_p addWeapon (player_backpack select 0);
	_muzzles = getArray(configFile>> "cfgWeapons" >> (player_backpack select 0) >> "muzzles");
	_p selectWeapon (player_backpack select 0);
	_p selectWeapon (_muzzles select 0);
	player_backpack = [_primary, _mags_backpack];
	_s = format ["Weapon %1", [_primary,1] call XfGetDisplayName];
	if (pbp_id == -9999) then {
		pbp_id = _p addAction [_s call XGreyText, "x_scripts\x_backpack.sqf",[],-1,false];
	};
	if (alive player) then {
		d_backpack_helper = [];
	};
};
};

if (true) exitWith {};

Share this post


Link to post
Share on other sites

Scripted backpacks and additional "on back weapons" allows players to have infinite ammo, taking away an important realism aspect of the game. Are you sure you want to go that route? I've disabled the backpack and weapononback system ages ago. BIS backpack system doesn't allow for this exploit.

Share this post


Link to post
Share on other sites
Scripted backpacks and additional "on back weapons" allows players to have infinite ammo, taking away an important realism aspect of the game. Are you sure you want to go that route? I've disabled the backpack and weapononback system ages ago. BIS backpack system doesn't allow for this exploit.

I did not know that.

How can I allow players to get a backpack with having to put on on everyone, can you put them in an ammo crate or something?

So this should work for clearloadout.sqf?

saveloadout = nil;

hint "Loadout cleared.";

How can we change the init to only work say within 2m?

EDIT: Just tested and clear loadout does not work, you still respawn with the saved loadout.

Edited by callihn

Share this post


Link to post
Share on other sites

Awesome yet again Bon.

Been looking for something like this for a while.

Thanks

Share this post


Link to post
Share on other sites

So this works nice but I have one problem. I have a coop mission for 6. Each of them has different starting loadout. All of them are in one team. When player respawns everything works great but when AI is in control of that slot AI does not respawn with loadout it had on mission start. What to do so the AI respawns with loadout from beginning of the mission?

Share this post


Link to post
Share on other sites

How does the weapon on back thing give unlimited ammo? Is there a way to exploit it to actually refill your magazines? If yes, then this is indeed pretty bad...

To make it work with AI you'd have to add an eventhandler on each of them as well as check where they are actually local as the script needs to run there, and of course if they change locality during the mission you need to deal with that as well... Overall not a simple task at all, but not impossible either.

Share this post


Link to post
Share on other sites

Like in Domination, if you use the builtin features to see what others are carrying, and find them to be carrying one Stanag mag, one M107 mag, and the rest grenades, that's a pretty strong indication on how they play ;) When you swap guns the other ammo is (maybe was, haven' checked in a while) also stored in this magic packpack/weapononback using arrays. Since you cannot count or set ammo for a magazine, you get them back full when you change back again. Using vanilla backpack system doesn't allow this, as it's actual contents are stored in a remote place. I'm not suggesting everyone uses this exploit, but even a few is enough to ruin the whole feeling for me, and I have caught (and exposed) quite a few doing it.

Share this post


Link to post
Share on other sites

Why does the magazine go in the back anyway? I thought when you put weapon on back it only puts the weapon on back while magazine stays in your inventory? Is the problem you're describing also in ACE's weapon on back? Note that I'm talking about putting weapon on back, not magazines in backpack.

Share this post


Link to post
Share on other sites
The following eventhandler goes somewhere where you can be sure "player" is initialized:

What does this mean? Should it be put in the init field of the player? Or maybe in the mission.sqm? I don't understand, Bon.

Share this post


Link to post
Share on other sites

Anywhere, where you are sure the player variable is initialized and that it will be actually done.

A possibility is to put in init.sqf:

if (!isDedicated) then
{
waitUntil {!isNull player};
player addEventHandler.....
....
};

Share this post


Link to post
Share on other sites

Sorry, guess that was a bit confusing. You have weapononback which may or may not allow the exploit depending on how (weapon only or also its magazine?) it's made (unsure about Domination and ACE on this one), but the big exploit was always the scripted custom backpack (both in Domination and ACE2 for Arma2, but ACE2 may now be updated since OA backpacks, not sure). If you have ACE2, it shouldn't be a problem to test.

Share this post


Link to post
Share on other sites

ACE2 weapon on back simply puts the weapon on back, magazines stay in bag, so I guess it's not a problem. Though I wouldn't be surprised if packing/unpacking magazines in rucks would cause them to be refilled, but I don't use rucks in my missions anyway, due to issues caused by technical limitations and the fact they are simply weren't needed for any mission I ever had in mind.

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
Sign in to follow this  

×