Jump to content
Sign in to follow this  
A-SUICIDAL

Weapon to Backpack - Save Loadout - Player/Weapons Respawn Problem

Recommended Posts

I am using Xeno's backpack script. I'm not sure if it is the most up-to-date version, but it seems to work correctly. I have done alot of searching. This is not an actual backpack, but a script that allows the player to add their primary weapon and primary magazines to a "sort of" invisible backpack. I'm sure that the majority of players and script'ers out their are very familiar with this feature.

I found the backpack script here: Xeno's Backpack Script

I am also using a simple "Save Loadout" script which is applied as an action to an ammo crate, which also works in conjunction with a "Weapon Respawn" script that gives the player back their saved loadout when they respawn. Both the "Save Loadout" and "Weapon Respawn" scripts do not seem compatible with the backpack script that I am using. When the player respawns, instead of having the correct weapon and magazines in their backpack, they instead have a second primary weapon. For instance, if the player had a shotgun in their backpack and an M4 in their hand and saved their loadout, if they then die and respawn - they then have and M4 in their backpack and an M4 in their hands, but no shotgun.

So I am looking for some help trying to get this to work correctly. I would imagine that both the "Save Loadout" and "Weapon Respawn" scripts need additional variables set to make everything work correctly, but I am not exactly sure what to add to make it work. Could somebody please help me with this? This is an extremely useful feature for any mission creator to add to his or her mission, so I am sure that I am not the only one out there that would like to get this working. Aside from the Domi missions out there, I have played other missions that used this feature and those mission had backpack and save loadout problems too. I'm actually surprised that there is not a stand alone download at Armaholic that incorporates all of these scripts as a package.

These are the script that I am using:

loadout_save.sqf

_unit = _this select 1;

_weapons = weapons _unit;
_magazines = magazines _unit;
_backpack = typeOf unitBackpack _unit;
_backpackmagazines = getMagazineCargo _backpack;
_backpackweapons = getWeaponCargo _backpack;

savedloadout = [_weapons,_magazines,typeOf _backpack,_backpackmagazines,_backpackweapons];

hint "Loadout Saved";[/spoiler]

loadout_respawn.sqf

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];
		};
	};
};
}];[/spoiler]

x_init_backpack.sqf

// by Xeno
#define __COMP x
#define FUNC(funcname) __COMP##_fnc_##funcname
#define GVAR(varname) __COMP##_##varname
#define QUOTE(qtext) #qtext
#define __pGetVar(pvarname) (player getVariable #pvarname)
#define __pSetVar player setVariable
#define __prma _p removeAction _id
#define __addbp __pSetVar [#x_pbp_id, _p addAction [_s call FUNC(GreyText), "x_backpack.sqf",[],-1,false]]
#define __addmx _p addMagazine _x
#define __addwx _p addWeapon _x

waitUntil {!isNull player};
sleep 1;

_p = player;

FUNC(GreyText) = {"<t color='#f0bfbfbf'>" + _this + "</t>"};

FUNC(GetDisplayName) = {
private ["_obj_name", "_obj_kind", "_cfg"];
_obj_name = _this select 0; _obj_kind = _this select 1;
_cfg = switch (_obj_kind) do {case 0: {"CfgVehicles"};case 1: {"CfgWeapons"};case 2: {"CfgMagazines"};};
getText (configFile >> _cfg >> _obj_name >> "displayName")
};

FUNC(CreateTrigger) = {
private ["_pos", "_trigarea", "_trigact", "_trigstatem", "_trigger"];
_pos = _this select 0; _trigarea = _this select 1; _trigact = _this select 2; _trigstatem = _this select 3;
_trigger = createTrigger ["EmptyDetector" ,_pos];
_trigger setTriggerArea _trigarea;
_trigger setTriggerActivation _trigact;
_trigger setTriggerStatements _trigstatem;
_trigger
};

FUNC(playerkr) = {
private "_p";
_p = player;
if ((_this select 0) == 0) then {
	_id = __pGetVar(GVAR(pbp_id));
	if (_id != -9999) then {
		__prma;
		__pSetVar [quote(GVAR(pbp_id)), -9999];
	};
} else {
	if (count GVAR(backpack_helper) > 0) then {
		{__addmx} forEach (GVAR(backpack_helper) select 0);
		{__addwx} forEach (GVAR(backpack_helper) select 1);
		GVAR(backpack_helper) = [];
	};
	if (count __pGetVar(GVAR(player_backpack)) == 0) then {
		if (primaryWeapon _p != "" && primaryWeapon _p != " ") then {
			_s = ([primaryWeapon _p,1] call FUNC(GetDisplayName)) + " to Backpack";
			if (__pGetVar(GVAR(pbp_id)) == -9999) then {__addbp};
		};
	} else {
		_s = "Weapon " + ([__pGetVar(GVAR(player_backpack)) select 0,1] call FUNC(GetDisplayName));
		if (__pGetVar(GVAR(pbp_id)) == -9999) then {__addbp};
	};
};
};

GVAR(backpack_helper) = [];
__pSetVar [quote(GVAR(player_backpack)), []];
__pSetVar [quote(GVAR(pbp_id)), -9999];

GVAR(prim_weap_player) = primaryWeapon _p;

if (GVAR(prim_weap_player) != "" && GVAR(prim_weap_player) != " ") then {
_s = ([GVAR(prim_weap_player),1] call FUNC(GetDisplayName)) + " to Backpack";
__addbp;
};

FUNC(bpcond) = {
(primaryWeapon player != GVAR(prim_weap_player) && primaryWeapon player != " " && !dialog)
};

FUNC(bponact) = {
private "_id";
GVAR(prim_weap_player) = primaryWeapon player;
_id = __pGetVar(GVAR(pbp_id));
if (_id != -9999 && count (__pGetVar(GVAR(player_backpack))) == 0) then {
	player removeAction _id;
	__pSetVar [quote(GVAR(pbp_id)), -9999];
};
if (__pGetVar(GVAR(pbp_id)) == -9999 && count (__pGetVar(GVAR(player_backpack))) == 0 && GVAR(prim_weap_player) != "" && GVAR(prim_weap_player) != " ") then {
	__pSetVar [quote(GVAR(pbp_id)), player addAction [format ["%1 to Backpack", [GVAR(prim_weap_player),1] call FUNC(GetDisplayName)] call FUNC(GreyText), "x_backpack.sqf",[],-1,false]];
};
};

[[0,0,0], [0, 0, 0, false], ["NONE", "PRESENT", true], ["call x_fnc_bpcond","call x_fnc_bponact",""]] call FUNC(CreateTrigger);

_p addEventHandler ["killed", {[0] call FUNC(playerkr)}];
_p addEventHandler ["respawn", {[1] call FUNC(playerkr)}];
[/spoiler]

x_backpack.sqf

// by Xeno
#define __COMP x
#define FUNC(funcname) __COMP##_fnc_##funcname
#define GVAR(varname) __COMP##_##varname
#define QUOTE(qtext) #qtext
#define __pGetVar(pvarname) (player getVariable #pvarname)
#define __pSetVar player setVariable
private ["_anim","_mag_types","_magazines","_mags_backpack","_muzzles","_p","_primary","_s","_pistol","_base"];
_p = player;
_id = __pGetVar(GVAR(pbp_id));
if (_id != -9999) then {
_p removeAction _id;
__pSetVar [quote(GVAR(pbp_id)), -9999];
};

if (count __pGetVar(GVAR(player_backpack)) == 0) then {
_primary = primaryWeapon _p;
if (_primary != "") then {
	_mag_types = getArray(configFile>> "cfgWeapons" >> _primary >> "magazines");
	{_mag_types set [_forEachIndex, toUpper _x]} forEach _mag_types;
	_magazines = magazines _p;
	_mags_backpack = [];
	{_tou = toUpper _x;if (_tou in _mag_types) then {_mags_backpack set [count _mags_backpack, _tou]}} forEach _magazines;
	_muzzles = getArray(configFile>> "cfgWeapons" >> _primary >> "muzzles");
	if (count _muzzles == 2) then {
		_mag_types = getArray(configFile>> "cfgWeapons" >> _primary >> (_muzzles select 1) >> "magazines");
		{_tou = toUpper _x;if (_tou in _mag_types) then {_mags_backpack set [count _mags_backpack, _tou]}} forEach _magazines;
	};
	_weapons = weapons _p;
	GVAR(backpack_helper) = [_magazines, _weapons];
	_pistol = "";
	{if (getNumber (configFile >> "CfgWeapons" >> _x >> "Type") == 2) exitWith {_pistol = _x}} forEach _weapons;
	if (_pistol != "") then {_p removeWeapon _pistol};
	{_p removeMagazine _x} forEach _mags_backpack;
	_p removeWeapon _primary;
	_anim = animationState _p;
	__pSetVar [quote(GVAR(player_backpack)), [_primary, _mags_backpack]];
	waitUntil {animationState player != _anim || !alive player};
	if (!alive player) exitWith {};
	_p = player;
	_s = "Weapon " + ([_primary,1] call FUNC(GetDisplayName));
	if (_pistol != "") then {
		_p addWeapon _pistol; _p selectWeapon _pistol;
	};
	if (__pGetVar(GVAR(pbp_id)) == -9999) then {__pSetVar [quote(GVAR(pbp_id)), _p addAction [_s call FUNC(GreyText), "x_backpack.sqf",[],-1,false]]};
	if (alive player) then {GVAR(backpack_helper) = []};
};
} else { // switch weapon
_primary = primaryWeapon _p;
if (_primary == "") then {
	{_p addMagazine _x} forEach (__pGetVar(GVAR(player_backpack)) select 1);
	_p addWeapon (__pGetVar(GVAR(player_backpack)) select 0);
	_muzzles = getArray(configFile>>"cfgWeapons" >> (__pGetVar(GVAR(player_backpack)) select 0) >> "muzzles");
	_p selectWeapon (__pGetVar(GVAR(player_backpack)) select 0);
	_p selectWeapon (_muzzles select 0);
	_s = format ["%1 to Backpack", [__pGetVar(GVAR(player_backpack)) select 0,1] call FUNC(GetDisplayName)];
	__pSetVar [quote(GVAR(player_backpack)), []];
	_id = __pGetVar(GVAR(pbp_id));
	if (_id != -9999) then {
		_p removeAction _id;
		__pSetVar [quote(GVAR(pbp_id)), -9999];
	};
	__pSetVar [quote(GVAR(pbp_id)), _p addAction [_s call FUNC(GreyText), "x_backpack.sqf",[],-1,false]];
} else {
	_mag_types = getArray(configFile>> "cfgWeapons" >> _primary >> "magazines");
	{_mag_types set [_forEachIndex, toUpper _x]} forEach _mag_types;
	_magazines = magazines _p;
	_mags_backpack = [];
	{_tou = toUpper _x;if (_tou in _mag_types) then {_mags_backpack set [count _mags_backpack, _tou]}} forEach _magazines;
	_muzzles = getArray(configFile>> "cfgWeapons" >> _primary >> "muzzles");
	if (count _muzzles == 2) then {
		_mag_types = getArray(configFile>> "cfgWeapons" >> _primary >> (_muzzles select 1) >> "magazines");
		{_tou = toUpper _x;if (_tou in _mag_types) then {_mags_backpack set [count _mags_backpack, _tou]}} forEach _magazines;
	};
	{_p removeMagazine _x} forEach _mags_backpack;
	_weapons = weapons _p;
	GVAR(backpack_helper) = [_mags_backpack, _primary];
	_pistol = "";
	{if (getNumber (configFile >> "CfgWeapons" >> _x >> "Type") == 2) exitWith {_pistol = _x}} 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 (__pGetVar(GVAR(player_backpack)) select 1);
	if (_pistol != "") then {_p addWeapon _pistol};
	_p addWeapon (__pGetVar(GVAR(player_backpack)) select 0);
	_muzzles = getArray(configFile>> "cfgWeapons" >> (__pGetVar(GVAR(player_backpack)) select 0) >> "muzzles");
	_p selectWeapon (__pGetVar(GVAR(player_backpack)) select 0);
	_p selectWeapon (_muzzles select 0);
	__pSetVar [quote(GVAR(player_backpack)), [_primary, _mags_backpack]];
	_s = "Weapon " + ([_primary,1] call FUNC(GetDisplayName));
	_id = __pGetVar(GVAR(pbp_id));
	if (_id == -9999) then {__pSetVar [quote(GVAR(pbp_id)), _p addAction [_s call FUNC(GreyText), "x_backpack.sqf",[],-1,false]]};
	if (alive player) then {GVAR(backpack_helper) = []};
};
};
[/spoiler]

---------- Post added at 09:27 PM ---------- Previous post was at 08:47 PM ----------

I changed 1 thing and it seems to be working now, but I only tested it a little so I can't be certain.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

Hi mate. Just noticed this error. There may be more but this stands out.

loadout_save.sqf

_unit = _this select 1;

_weapons = weapons _unit;
_magazines = magazines _unit;
[color="#FF0000"]_backpack = typeOf unitBackpack _unit;[/color]
_backpackmagazines = getMagazineCargo _backpack;
_backpackweapons = getWeaponCargo _backpack;

savedloadout = [_weapons,_magazines,typeOf _backpack,_backpackmagazines,_backpackweapons];

hint "Loadout Saved";

In that script you get the typeOf backpack... and not the actual backpack... so trying to get the contents of the typeOf backpack won't work!

This should work...

_backpackmagazines = getMagazineCargo unitBackpack _unit;

Edited by twirly
Fixed something

Share this post


Link to post
Share on other sites

Ok, I'll try that now. Actually, the part in red was the one thing I changed and then it started working correctly. I changed it to that because I had noticed that

_backpack = typeOf unitBackpack _unit;

was already being used in the loadout_respawn.sqf script, so I then changed it in the loadout_save.sqf script so they would match.

The loadout_save.sqf script used to have:

_backpack = unitBackpack _unit;

Though I am a little confused about what you said. You highlighted the line in red that referred to the actual backpack, but then you mentioned changing the line below it that referred to the backpack magazines.

Should I change both lines so they look like this:

_backpack = unitBackpack _unit;
_backpackmagazines = getMagazineCargo unitBackpack _unit;

And then what about the line that refers to the backpack weapons?

Should that also be changed to be:

_backpackweapons = getWeaponCargo unitBackpack _unit;

I also just noticed that the loadout_respawn.sqf uses:

_backpackmags

_backpackweap

and loadout_save.sqf uses:

_backpackmagazines

_backpackweapons

So I changed those to match as well(using the shortened version), though I'm not sure how much that matters.

Share this post


Link to post
Share on other sites

Sorry to confuse you mate.... thought you could piece it together :)

Changed it a bit more.... changes in red.

_unit = _this select 1;

_weapons = weapons _unit;
_magazines = magazines _unit;
[color="#FF0000"]_backpacktype[/color] = typeOf unitBackpack _unit;
[color="#FF0000"]_backpackmagazines = getMagazineCargo (unitBackpack _unit);
_backpackweapons = getWeaponCargo (unitBackpack _unit);[/color]

savedloadout = [_weapons,_magazines,[color="#FF0000"]_backpacktype[/color],_backpackmagazines,_backpackweapons];

hint "Loadout Saved";

Thing is getMagazineCargo _backpacktype will not work because it's like saying getMagazineCargo "Assault_Pack_EP1" which is trying to get the magazines from a string and not an object.

unitBackpack _unit would be the actual backpack... so is an object. You can get the contents of the backpack object.

typeOf (unitBackpack _unit) would be the type of backpack... so is a string. No way to get contents from that.

Hope that makes sense.

Also... just noticed the first line is _unit = _this select 1;.... which maybe should be _unit = _this select 0; to select the first element that was passed to the script.

---------- Post added at 04:27 PM ---------- Previous post was at 04:07 PM ----------

Have a Birthday to deal with today... but I did start a little test mission to work it out for you. The "save" and "reload" part anyway. Will look at that later on tonight if I get time mate and upload something somewhere for you. If not will be tomorrow. NZ time of course :)

Edited by twirly

Share this post


Link to post
Share on other sites

Everything you said makes sense. I was kind of wondering how "typeOf" would work too, since there are no actual backpack types in the mission. I will try making some more changes and testing a bit more.

Right now everything seems to work except for one thing, for instance, if I put a shotgun in my backpack and have an M4 in my hand and save my loadout, when I die and respawn I have the same loadout, but if I switch to the shotgun in my backpack before I die, I then respawn without it and wind up with an M4 in my backpack and an M4 in my hand.

I really appreciate all the help you are giving me. This is literally the only bug left in my mission that I am trying to sort out.

Oh, I'm not sure if you meant that it was your Birthday today, but if it is, then I want to wish you a Happy Birthday! :)

Share this post


Link to post
Share on other sites

For the save loadout I tried _unit = _this select 0; but it didn't work, so I went back to using select 1.

I also played around with the loudout_respawn.sqf a bit and I tried using a different EH. Again, since there are no "real" backpacks in my mission, the changes seems to work fine. The problem still exists where - if the player switches to his backpack weapon and dies, he then respawns without it. If there was some way to get the player to switch to primary after dying, it might fix the problem, lol. I don't think that can be made possible.

loadout_save.sqf

_unit = _this select 1;

_weapons = weapons _unit;
_magazines = magazines _unit;
_backpack = unitBackpack _unit;
_backpackmags = getMagazineCargo unitBackpack _unit;
_backpackweap = getWeaponCargo unitBackpack _unit;

savedloadout = [_weapons,_magazines,_backpack,_backpackmags,_backpackweap];

hint "Loadout Saved";

loadout_respawn.sqf

WaitUntil{not isNull player || isDedicated};

player addEventHandler 
[
"respawn",
{
	_weapons = savedloadout select 0;
	_magazines = savedloadout select 1;
	_backpack = savedloadout select 2;
	_backpackmags = savedloadout select 3;
	_backpackweap = savedloadout select 4;

	removeAllWeapons player;
	removeAllItems player;
	removeBackpack player;

	{player addMagazineCargo _x} foreach _backpackmags;
	{player addWeaponCargo _x} foreach _backpackweap;
	{player addMagazine _x} foreach _magazines;
	{player addWeapon _x} foreach _weapons;
	_muzzles = getArray(configFile>>"cfgWeapons" >> primaryWeapon player >> "muzzles");

	player selectWeapon (primaryWeapon player);
}
];

Share this post


Link to post
Share on other sites

If I understand correctly, the script requires you to save your gear via an addaction on an ammo crate. If that’s the case, then I would add to the save gear sqf a line that saves the current primary/secondary weapons of the player to that player. ex:

player setVariable ["SOME_VARIABLE",[primaryweapon player,secondaryweapon player]];

Then On the respawn script run a check:

_weapons = savedloadout select 0;//Refference pulled from code provided.

_primary_weapon = (player getVariable "SOME_VARIABLE") select 0;

_secondary_weapon = (player getVariable "SOME_VARIABLE") select 1;

if !(_primary_weapon in _weapons) then {_weapons = _weapons + [_primary_weapon]};

if !(_secondary_weapon in _weapons) then {_weapons = _weapons + [_secondary_weapon]};

That should add the weapons saved to your player if that weapon is not included in weapons array utilized via the script.

Is your primary weapon on respawn the weapon from your backpack?

---------- Post added at 03:10 PM ---------- Previous post was at 02:37 PM ----------

Try spawning the following in the Killed/Spawn EH your using. The vars are quoted and sleeps/Waituntils are used to monitor the primary weapon so if you do not spawn the script in your EH it will not work.

Ex: [Player] spawn {

_unit = _this select 0;

};

WaitUntil {alive player};

_weapons = savedloadout select 0;

_magazines = savedloadout select 1;

_backpack = savedloadout select 2;

_backpackmags = savedloadout select 3;

_backpackweap = savedloadout select 4;

removeAllWeapons player;

removeAllItems player;

removeBackpack player;

{player addMagazineCargo _x} foreach _backpackmags;

{player addWeaponCargo _x} foreach _backpackweap;

{player addMagazine _x} foreach _magazines;

{player addWeapon _x} foreach _weapons;

_primary_weapon = (player getVariable "SOME_VARIABLE") select 0;

_secondary_weapon = (player getVariable "SOME_VARIABLE") select 1;

if !(_secondary_weapon in _weapons) then {_weapons = _weapons + [_secondary_weapon]};

While {(primaryWeapon player) == ""} do {sleep 0.01};

if (primaryWeapon player != _primary_weapon) then {

_WeapToAddToPack = primaryWeapon player;

if !(_WeapToAddToPack in _backpackweap) then {player addWeaponCargo _BackPackweapon};

WaitUntil {(primaryWeapon player) == "")};

player addWeapon _primary_weapon;

WaitUntil {primaryWeapon player == _primary_weapon};

reload player;

};

---------- Post added at 03:12 PM ---------- Previous post was at 03:10 PM ----------

Try spawning the following in the Killed/Spawn EH your using. The vars are quoted and sleeps/Waituntils are used to monitor the primary weapon so if you do not spawn the script in your EH it will not work.

Ex: [Player] spawn {

_unit = _this select 0;

BLAH;

BLAH;

};

player addEventHandler ["Killed",{[player] spawn {CODE}}];

WaitUntil {alive player};

_weapons = savedloadout select 0;

_magazines = savedloadout select 1;

_backpack = savedloadout select 2;

_backpackmags = savedloadout select 3;

_backpackweap = savedloadout select 4;

removeAllWeapons player;

removeAllItems player;

removeBackpack player;

{player addMagazineCargo _x} foreach _backpackmags;

{player addWeaponCargo _x} foreach _backpackweap;

{player addMagazine _x} foreach _magazines;

{player addWeapon _x} foreach _weapons;

_primary_weapon = (player getVariable "SOME_VARIABLE") select 0;

_secondary_weapon = (player getVariable "SOME_VARIABLE") select 1;

if !(_secondary_weapon in _weapons) then {_weapons = _weapons + [_secondary_weapon]};

While {(primaryWeapon player) == ""} do {sleep 0.01};

if (primaryWeapon player != _primary_weapon) then {

_WeapToAddToPack = primaryWeapon player;

if !(_WeapToAddToPack in _backpackweap) then {player addWeaponCargo _BackPackweapon};

WaitUntil {(primaryWeapon player) == "")};

player addWeapon _primary_weapon;

WaitUntil {primaryWeapon player == _primary_weapon};

reload player;

};

Edited by Kempco

Share this post


Link to post
Share on other sites

Thank you. I'll try what you said now. I'll throw together a sample mission too.

Share this post


Link to post
Share on other sites

I tried what you said and when I tested it - I switched to my backpack weapon and then I died and I respawned with the correct gear. The first thing I thought was "Yay it works now!", but when I tested it further I found out that it only worked if I switched to my backpack weapon before dying. Meaning... if I did not switch to my backpack weapon before I died, I would then respawn with 2 primary weapons. In other words - it was doing the opposite of the problem that was occurring before.

I figured that I might have applied the new changes incorrectly, so I removed the changes and I made a sample mission using the old scripts - previous to the changes you suggested I make. I don't know if you have time to look at the sample mission and maybe apply the changes yourself. I am going to keep trying to see if I can get it to work correctly. I'm starting to think that the problem has something to do with the way the backpack script functionality, because when I switch to my backpack weapon, it normally seems to remember what weapon was in the backpack when I respawn even if I do not save my loadout. It's as if the save loadout script breaks the backpacks memory.

save_loadout_test.Desert_E.zip

I'm starting to think that maybe I should just remove the backpack stuff from the save loadout script and just tell it to save the player weapons and magazines.

Share this post


Link to post
Share on other sites

Hi mate... as promised... try this. Demo mission download here.... both a .pbo and the raw mission files there in the zip.

Use the .pbo to check it out...start a coop game. There's a radio trigger (Radio Alpha) to save the loadout. Then just kill yourself with a grenade.

See how you get on. If there's still problems we'll sort it out one at a time. Baby steps!

---------- Post added at 03:33 PM ---------- Previous post was at 03:31 PM ----------

Will look at your demo mission now

---------- Post added at 04:07 PM ---------- Previous post was at 03:33 PM ----------

Ran your demo and it seems to work fine. I always respawn with the weapons I had when I chose "Save Loadout".

If I switch to another weapon and don't save the loadout then there's no way to have that weapon as the Primary weapon on respawn... unless you save the loadout again. That makes perfect sense and works the way it should.

Share this post


Link to post
Share on other sites

First I just want to say thanks for all the help. I tried testing your sample .pbo mission, but had 1 small problem where it said that it was dependent on deleted files, so then I opened the mission.sqm file and removed 2 references to something called "msv_bags" so I could then be able to open it in the editor and re-save it as a .pbo and test it.

While I was in the mission folder I noticed right away that there were no "Xeno" backpack scripts and I thought "hmm". I then tested the mission in MP and noticed right away that the player was wearing a backpack and upon scrolling down through the available actions I didn't see an action for "Weapon_Name to backpack". So I think there might be a little misunderstanding as to what it is exactly that I am trying to accomplish. I'm still very grateful for all the work you did. I don't want you to think that I am ungrateful at all. Your mission did test fine and everything works great in it as far as a "real" backpack is involved, but my mission does not have any "real" backpacks in it, but instead there is only the means of an "invisible" backpack. In my actual mission, I use units that are all: USMC > Men > Men (FR), better known as Force Recon, and Force Recon units cannot wear a "real" backpack, that is 1 reason why I am using Xeno's packpack script. The other reason is... I prefer not to have "real" backpacks in my mission since most my friends never bother to use them or don't know how to use them, lol.

I could still very much use some help. If you have time to look at my sample mission and examine a few scripts, you might be able to spot the problem.

To recreate the problem in my mission, simply scroll down and choose the action that puts your rifle into your backpack, then grab another rifle from the ammo crate, then save your loadout. Blow yourself up with c4 and you will respawn with the same weapon loadout. Now try it again, only this time before you blow yourself up, switch to the weapon in your backpack first, now blow yourself up and when you respawn you will no longer have the same weapon in your backpack that was there when you chose "Save Loadout", but you will instead have 2 of the same rifles that you were last holding in your hand.

I think Kempco might have been on to the right track, but in testing his suggested changes I ran into problems where I would respawn and my loadout did save if I switched to my backpack weapon before I died, but didn't save correctly if I didn't switch to my backpack weapon before I died. Same problem as before, but an opposite effect.

---------- Post added 10-18-2012 at 01:04 AM ---------- Previous post was 10-17-2012 at 11:38 PM ----------

In attempt to find a better "save loadout" script, I searched around a bit and found a 2.71 Domi Lingor mission here: http://www.sog-team.com/forum/showthread.php?p=171614

This is the actually link I used to DL it: Download Vincentz_Domi_2_71_V1C.lingor.pbo (4.2 MB)

I don't have Lingor Insland installed, and I don't often extract pbo files, but I extracted the mission and used "Windows Grep" to search through every file that contained any text regarding "backpacks" and found some interesting stuff. The x_backpack.sqf file in my sample mission is almost identical to the one used in the domi mission, so that's a start. I found a save loadout file under "x_client/x_savelayout.sqf", but it's totally different from what I was using. I found a lot of files/scripts that all seemed to be related to a "real" backpack, so I tried to stay focused on just the things needed to make the x_backpack.sqf work correctly in my mission. "x_client/x_setupplayer.sqf" starting at line 813, "x_client/x_playerspawn.sqf" contained a bunch of stuff. I'm not using revive in my mission, but I found some other stuff in "x_revive/xr_main.sqf";

Trying to make sense of all of this is a little over my head. I remember when I once tried to use the lift script from a domi mission and I nearly lost my mind. Then later Xeno released a stand alone domi style lift script at armaholic. I wish he would release a stand alone "weapon to backpack" script that incorporates the save loadout script on respawn. I have a feeling I'm about to lose my mind again, lol.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

To recreate the problem in my mission, simply scroll down and choose the action that puts your rifle into your backpack, then grab another rifle from the ammo crate, then save your loadout. Blow yourself up with c4 and you will respawn with the same weapon loadout. Now try it again, only this time before you blow yourself up, switch to the weapon in your backpack first, now blow yourself up and when you respawn you will no longer have the same weapon in your backpack that was there when you chose "Save Loadout", but you will instead have 2 of the same rifles that you were last holding in your hand.

Well.. if you switch to the weapon in your backpack and then don't save your weapons status.... how can it possibly be restored properly?

Reading you wrong ...so scratch that.... but this still applies.

Your demo ran flawlessly for me as long as I saved the loadout.

---------- Post added at 07:25 PM ---------- Previous post was at 07:18 PM ----------

Mate... just verified that again... your mission works well. I always respawn with exactly the same weapons that I saved.

---------- Post added at 07:28 PM ---------- Previous post was at 07:25 PM ----------

Ahhhh... I just got it to happen. Will investigate more.

Share this post


Link to post
Share on other sites

Not in the sample mission, but in my actual coop mission I have a script that activates at mission start for each player that removes all weapons from each player and gives them customized loadouts, then I have another script that autosaves their loadout (without a hint), so if a player doesn't manually save his or her loadout - it will do it for them. This was not absolutely necessary, but in my mission each player has the ability to call a single air-to-ground missile strike every 10 minutes and I wanted to make sure that every player was equipped with a Laser Marker and Battery at mission start - to save them the hassle of equipping the gear themselves. I also did not want players that do not use the "Save Loadout" action to respawn with standard weapons and lose the Laser Marker and Battery that was initially given to them, so the silent autosave loadout script helps, but the player does not start the mission with a weapon in their backpack. I figure that the players can have fun adding a weapon to their backpack themselves and save their own loadouts from then on.

Share this post


Link to post
Share on other sites

Okay here is the issue; you cannot save primaryweapons in backpacks. (I use ACE, did not know you cannot do that). Therefore, you cannot use the backpack as a place holder for the the second weapon. Which I was doing. Ill try to look at the mission tonight, and see what kind of voodoo you got going on.

Edited by Kempco

Share this post


Link to post
Share on other sites

In the x_init_backpack.sqf file there are a few variables that are used, like player_backpack

and prim_weap_player.

The very bottom lines in the x_init_backpack.sqf are:

_p addEventHandler ["killed", {[0] call FUNC(playerkr)}];

_p addEventHandler ["respawn", {[1] call FUNC(playerkr)}];

and FUNC(playerkr) seems to check to see if the backpack is empty or it checks to see what weapon is currently in the backpack and it also controls the "grey" actions that appear in the players menu.

So it seems to me that regardless of the save loadout script, the actually x_init_backpack.sqf script has it's own sort of built in save function, but obviously I'm having trouble getting it to work correctly.

Right now the way it seems to work in my sample mission... If you add a weapon to your backpack and save your loadout and then die, you will respawn with the correct weapon in your backpack along with all of your other gear and weapons. But if you switch to your backpack weapon before you die, it them some how breaks the loadout that you saved - and upon respawning it seems to add to your backpack a duplicate weapon of the weapon you were last holding in your hand before you died. So my guess is that something in the x_init_backpack.sqf is causing the saved loadout to break the moment you add or switch to a weapon in your backpack.

The backpack scripts that I am using acts as a stand alone script. Xeno posted it back in March 2011 here, but he did not post or mention anything about a save loadout script, so maybe he made that script to work without a save loadout script and gave the script some sort of built in save functionality. I can't be certain about this.

After doing some research and extracting a couple of the newer Domination missions that use Xeno's backpack script, I noticed that the missions seem to only use the x_backpack.sqf since I was unable to find a x_init_backpack.sqf being used anywhere in the mission folders. But there were some files that used similar functionality to that of the x_init_backpack.sqf file, but I never found anything that used:

_p addEventHandler ["killed", {[0] call FUNC(playerkr)}];

_p addEventHandler ["respawn", {[1] call FUNC(playerkr)}];

so maybe these EH's in Xeno's x_init_backpack.sqf script need to be used differently in my mission.

If I was a expert at this stuff, then I could probably figure out how to simply take the backpack and save loadout scripts from the Domi mission and put it into my coop mission, but there are so many other things tied into it, like ace, confusing variables and other things, that I wouldn't know how to do it. It would probably be simple for any advanced mission creator, but I'm just not there yet. Still, I am very surprised that a stand alone backpack/save_loadout/player_respawn script was never released. It is one of the things I love most when I play on a Domi server. I usually won't play on a Domi server that doesn't use it. I don't even want to play my own coop missions without it.

Share this post


Link to post
Share on other sites

Xeno uses a lot #defines to shorthand script language. Maybe English isn't his first language or at that level you get board and just rewrite ways to write code. All I know is that he does it, and he does it well. I do not. So Ill try and rewrite the script.

Share this post


Link to post
Share on other sites

I appreciate that Kempco. I do want the help, but if it involves a lot of work, I'll completely understand if you decide to take a pass.

Share this post


Link to post
Share on other sites

After looking at it some more myself.... I'm sort of with Kempco. I keep throwing it in the "too hard basket" and then coming back to it.

All I can suggest is to not to try to manage the backpack items and let that script handle it. Just manage his other items. Just a thought!

Sorry mate.... but It's just too time consuming to test!

Share this post


Link to post
Share on other sites

Should have this wrapped up latter tonight, latest tomorrow morning. Making Good Progress.

Share this post


Link to post
Share on other sites

Converted the script to FSM so the script can continuously check the primary weapon. If the last known primary has does not match the current the it will either reset the addaction names OR if initiated via the addaction it will redefine the weapons, stored/equipped.

Problem Im having now, is if the unit drops his primarry on the ground, and has no weapons or he drops his primary on the ground and has a backup, everything gets jumbled up. Maybe doing some kind of loop that waits until the dialog is true, checks if the player has a primarry weapon, the waits until the dialog is false and compares the two values, can be worked in to bypass one of the conditions. Hmmmmmmm?

In the mean time, ou could always try ACE, they let you carry 2 weapons NP. If not im gonna need a couple days.

Share this post


Link to post
Share on other sites

It sounds like a lot of work involved. I really appreciate all that you are doing. Again, I don't want you to drive yourself crazy with it, so if it seems like it's too great a task, I'll understand if you want to give up on it.

I like ACE, ACE is great and I do use ACE in some missions that I create, but the mission that I am working on now is about 99% complete and does not require any addons at all and I kind of want to keep it that way. A stand alone Weapon to Backpack - Save Loadout - Player/Weapons Respawn script is something that I would like to use in this mission and in other Vanilla missions that I might make in the future. Without it, my mission will suck. It's one of the things that makes playing Domi so great, I just wish that it wasn't limited to Domi only. There are a lot of mission creators out there that I'm sure would like to use it in their missions too - without always having to install a bunch of addons to make it possible. Addons are fun, but I don't always like to use them in my missions because then my mission feels like less of my own.

Share this post


Link to post
Share on other sites

I really don't want to give up on this. I've spent a lot of time trying to get Xeno's stand alone backpack script to work with both a "save loadout" and "player respawn" scripts, but it didn't work. I just want to get it to work exactly like it does in Domination. I tried using the Domi version of Xeno's backpack script and after over 150 hours of reverse engineering the scripts, removing all the unneeded lines of code and trying to add all of the correct defined variables & includes where they needed to be - basically trying to piece it all together to work in a stand alone sample mission - I finally got to the point where I was not receiving any errors, but the backpack weapon was still not saving correctly, but everything else did save. I continued to work on it and developed more of an understanding as to how it all worked and I felt that I was getting closer to figuring it out - when I then accidentally deleted the sample mission when I was cleaning out some older sample missions that were cluttering my mission directory - thinking that it was an older version. So now I'm back to square 1 again and I just don't know if it's really worth the effort anymore since I nearly had a mind meltdown trying to get it working the first time around.

I still find it amazing that such an awesome backpack feature in Domination was never released as a stand alone sample mission including a save loadout and player respawn with saved gear. Xeno's current stand alone backpack script works great, but it only allows players to respawn with the backpack weapon that was added to the backpack before the player died. I've tried PM'ing Xeno and kindly asking for him help - requesting that he please update his stand alone backpack script with both "save loadout" and "player respawn with saved gear" features, but I haven't heard back from him for quite a while. I kinda figured all along that Xeno must be way too busy with other things to take time out to help little'ol me, which I completely understand, especially when I'm asking a lot of him and we all know he's always busy.

I am still hoping that Xeno or somebody might be able to help me with this. I'm going to keep trying to get it figured out even though I am losing confidence that I will ever get it working correctly. Ever since I got stumped on this I haven't focused or worked on anything else and I still have a mission that is completed, but I don't want to release it without these features since I would never feel happy with the mission. The word "stumped" doesn't even cover it, I feel "stopped".

Share this post


Link to post
Share on other sites

Hi A-SUICIDAL, sorry it's not really on the subject of this thread, but i saw one of your mission for jet training on xfire "[Co-04]AcesHigh"

I have check on google but cant find it anywhere, can you provide me a link where we can download your mission please ?

Again sorry for the off topic.

Share this post


Link to post
Share on other sites

I'll see if I can find a good working copy of it and then I'll test it and make sure everything is working correctly. I'll then zip it up and upload and post a link for download. It might take me a couple of days. I have so many different versions of it.

Back to my original thread... who do I have to pay to get the backpack script to work with a "Save Loadout"?

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  

×