Jump to content
Sign in to follow this  
carlostex

Backpack Script

Recommended Posts

These Xeno's scripts are from Arma but still quite useful for Arma 2. Work like a charm. However there's one single thing that i would like to be different:

this is x_setupbackpack.sqf

// by Xeno

private ["_p","_pos","_trigger","_s"];

if (!local player) exitWith {};

_p = player;

_pos = position _p;

player_backpack = [];

pbp_id = -1000;

prim_weap_player = primaryWeapon _p;

_s = format ["%1 to Backpack", prim_weap_player];

if (prim_weap_player != "") then {

pbp_id = _p addAction [_s, "x_backpack.sqf",[],-1,false];

};

// No Weapon fix for backpack

_trigger = createTrigger["EmptyDetector" ,_pos];

_trigger setTriggerArea [0, 0, 0, false];

_trigger setTriggerActivation ["NONE", "PRESENT", true];

_trigger setTriggerStatements["primaryWeapon player != prim_weap_player","prim_weap_player = primaryWeapon player;if (pbp_id != -1 && count player_backpack == 0) then {player removeAction pbp_id;pbp_id = -1;};if (pbp_id == -1 && count player_backpack == 0 && prim_weap_player != """") then {pbp_id = player addAction [format [""%1 to Backpack"", prim_weap_player], ""x_backpack.sqf"",[],-1,false];};",""];

while {true} do {

waitUntil {!alive player};

_p = player;

_weapons = weapons _p;

_magazines = magazines _p;

if (pbp_id != -1000) then {

_p removeAction pbp_id;

};

waitUntil {alive player};

_p = player;

removeAllWeapons _p;

{_p addMagazine _x;} forEach _magazines;

{_p addWeapon _x;} forEach _weapons;

_primw = primaryWeapon _p;

if (_primw != "") then {

_p selectWeapon _primw;

_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");

_p selectWeapon (_muzzles select 0);

};

if (count player_backpack == 0) then {

_s = format ["%1 to Backpack", primaryWeapon _p];

pbp_id = _p addAction [_s, "x_backpack.sqf",[],-1,false];

} else {

_s = format ["Weapon %1", (player_backpack select 0)];

pbp_id = _p addAction [_s, "x_backpack.sqf",[],-1,false];

};

};

if (true) exitWith {};

and this is x_backpack.sqf:

// by Xeno

private ["_p"];

_p = player;

_p removeAction pbp_id;

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 = _mags_backpack + [_x]};

} 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 = _mags_backpack + [_x]};

} forEach _magazines;

};

player_backpack = [_primary, _mags_backpack];

_weapons = weapons _p;

_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;

WaitUntil {animationState player != _anim};

_s = format ["Weapon %1", _primary];

if (_pistol != "") then {

_p addWeapon _pistol;

_p selectWeapon _pistol;

};

pbp_id = _p addAction [_s, "x_backpack.sqf",[],-1,false];

} else { // has no primary

};

} 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)];

player_backpack = [];

_p removeAction pbp_id;

pbp_id = _p addAction [_s, "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 = _mags_backpack + [_x]};

} 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 = _mags_backpack + [_x]};

} forEach _magazines;

};

{

_p removeMagazine _x;

} forEach _mags_backpack;

_weapons = weapons _p;

_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};

{

_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];

pbp_id = _p addAction [_s, "x_backpack.sqf",[],-1,false];

};

};

if (true) exitWith {};

My question is how can i make the script call the Display name (Weapon name) instead of the class name?

Kinda annoying seeing like this:

m16a4_acg to Backpack

instead of

M16A4 ACOG to Backpack

Otherwise the script is awesome. Already asked Xeno's help but got no answer.

Share this post


Link to post
Share on other sites

I'm kinda worried 50 views and no answer is bad news. I'm pretty sure it can be done cause Domination's mission has this kind of script and we can see the weapon name in the action menu instead of classname.

Share this post


Link to post
Share on other sites

Thanks for a reminder of a nice scripter Xeno. :-)

Use this on the addaction preperaton to change to visual displayname:

_configname = prim_weap_player;

_s = format ["Weapon %1", getText(configFile >> "cfgWeapons" >> _configname >> "displayName")];

(Change at appr. places in both scripts value of _configname to:

prim_weap_player; primaryWeapon _p;(player_backpack select 0);_primary;

Also use actiontext "weapon"/"to backpack" as applicable.)

Thanks to nice ammoscript http://www.armaholic.com/forums.php?m=posts&q=12204

Share this post


Link to post
Share on other sites
Thanks for a reminder of a nice scripter Xeno. :-)

Use this on the addaction preperaton to change to visual displayname:

_configname = prim_weap_player;

_s = format ["Weapon %1", getText(configFile >> "cfgWeapons" >> _configname >> "displayName")];

(Change at appr. places in both scripts value of _configname to:

prim_weap_player; primaryWeapon _p;(player_backpack select 0);_primary;

Also use actiontext "weapon"/"to backpack" as applicable.)

Thanks to nice ammoscript http://www.armaholic.com/forums.php?m=posts&q=12204

DUDE THANK YOU ONE THOUSAND TIMES!!!! I'll try and hope i don't fail miserably.

---------- Post added at 04:00 PM ---------- Previous post was at 03:31 PM ----------

BoomBoomSate thank you but and i don't like to be a pain, i really don't understand how scripts work and i didn't think this was this hard. I have no idea of what should i substitute for the code you gave me. I think is because i don't understand how scripts work. Could you highlight the lines that i should replace and the code i should replace them for?

This is still too advanced for me. One day i would like to look to every line of code and understand "what the hell is going on".

Share this post


Link to post
Share on other sites

I placed the two files in a subdirectory of my mission folder, called DOM, to keep things a bit organized:

backpack.sqf

// by Xeno

private ["_p"];

_p = player;

_p removeAction pbp_id;

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 = _mags_backpack + [_x]};

} 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 = _mags_backpack + [_x]};

} forEach _magazines;

};

player_backpack = [_primary, _mags_backpack];

_weapons = weapons _p;

_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;

WaitUntil {animationState player != _anim};

_s = format ["Weapon %1", getText(configFile >> "cfgWeapons" >> _primary >> "displayName")];

if (_pistol != "") then {

_p addWeapon _pistol;

_p selectWeapon _pistol;

};

pbp_id = _p addAction [_s, "dom\x_backpack.sqf",[],-1,false];

} else { // has no primary

};

} 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", getText(configFile >> "cfgWeapons" >> (player_backpack select 0) >> "displayName")];

player_backpack = [];

_p removeAction pbp_id;

pbp_id = _p addAction [_s, "dom\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 = _mags_backpack + [_x]};

} 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 = _mags_backpack + [_x]};

} forEach _magazines;

};

{

_p removeMagazine _x;

} forEach _mags_backpack;

_weapons = weapons _p;

_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};

{

_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", getText(configFile >> "cfgWeapons" >> _primary >> "displayName")];

pbp_id = _p addAction [_s, "dom\x_backpack.sqf",[],-1,false];

};

};

if (true) exitWith {};

x_setupbackpack.sqf

// by Xeno

private ["_p","_pos","_trigger","_s"];

if (!local player) exitWith {};

_p = player;

_pos = position _p;

player_backpack = [];

pbp_id = -1000;

_wCName = "";

_wDName = "";

_wModel = "";

_wType = "";

_wscope = "";

_wPic = "";

_wDesc = "";

prim_weap_player = primaryWeapon _p;

_s = format ["%1 to Backpack", getText(configFile >> "cfgWeapons" >> prim_weap_player >> "displayName")];

if (prim_weap_player != "") then {

pbp_id = _p addAction [_s, "dom\x_backpack.sqf",[],-1,false];

};

// No Weapon fix for backpack

_trigger = createTrigger["EmptyDetector" ,_pos];

_trigger setTriggerArea [0, 0, 0, false];

_trigger setTriggerActivation ["NONE", "PRESENT", true];

_trigger setTriggerStatements[

"primaryWeapon player != prim_weap_player","

prim_weap_player = primaryWeapon player;

if (pbp_id != -1 && count player_backpack == 0) then

{player removeAction pbp_id;pbp_id = -1;};

if (pbp_id == -1 && count player_backpack == 0 && prim_weap_player != """") then

{pbp_id = player addAction [format [""%1 to Backpack"", getText(configFile >> ""cfgWeapons"" >> prim_weap_player >> ""displayName"")], ""dom\x_backpack.sqf"",[],-1,false];};

",""];

while {true} do {

waitUntil {!alive player};

_p = player;

_weapons = weapons _p;

_magazines = magazines _p;

if (pbp_id != -1000) then {

_p removeAction pbp_id;

};

waitUntil {alive player};

_p = player;

removeAllWeapons _p;

{_p addMagazine _x;} forEach _magazines;

{_p addWeapon _x;} forEach _weapons;

_primw = primaryWeapon _p;

if (_primw != "") then {

_p selectWeapon _primw;

_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");

_p selectWeapon (_muzzles select 0);

};

if (count player_backpack == 0) then {

_s = format ["%1 to Backpack", getText(configFile >> "cfgWeapons" >> (primaryWeapon _p) >> "displayName")];

pbp_id = _p addAction [_s, "dom\x_backpack.sqf",[],-1,false];

} else {

_s = format ["Weapon %1", getText(configFile >> "cfgWeapons" >> (player_backpack select 0) >> "displayName")];

pbp_id = _p addAction [_s, "dom\x_backpack.sqf",[],-1,false];

};

};

if (true) exitWith {};

Share this post


Link to post
Share on other sites

Here is a newer version of the backpack script, it shows the display name instead of the class name in the action menu and it adresses some issues the older version had.

First, add the following to init.sqf:

if (!isDedicated) then {
execVM "x_init_backback.sqf";
};

Then create two sqf files (put them into your mission root folder):

x_init_backback.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)}];

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) = []};
};
};

Xeno

Share this post


Link to post
Share on other sites

BoomBoomSate i have to thank you a lot for your pacience and helping me.

Xeno thank your for your scripts, help and magnificent work with the community.

Share this post


Link to post
Share on other sites

What does the script do? I cant tell by reading it

Share this post


Link to post
Share on other sites
Here is a newer version of the backpack script, it shows the display name instead of the class name in the action menu and it adresses some issues the older version had.

First, add the following to init.sqf:

if (!isDedicated) then {
execVM "x_init_backback.sqf";
};

Then create two sqf files (put them into your mission root folder):

x_init_backback.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)}];

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) = []};
};
};

Xeno

where do i get the backpack file i cant seem to find it.

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  

×