Jump to content
Sign in to follow this  
davt

scripts mochila por xeno

Recommended Posts

i am Spanish and my English is very bad I apologize

: I took it from here

http://forums.bistudio.com/showthread.php?t=115455&highlight=backpack

init.sqs

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

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

;

};

} 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

];

__pSetVar

;

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

;

};

if (__pGetVar(GVAR(pbp_id)) == -9999 && count (__pGetVar(GVAR(player_backpack))) == 0 && GVAR(prim_weap_player) != "" && GVAR(prim_weap_player) != " ") then { __pSetVar

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

;

};

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

];

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

,-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

];

_id = __pGetVar(GVAR(pbp_id));

if (_id != -9999) then { _p removeAction _id;

__pSetVar

; };

__pSetVar

,-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

];

_s = "Weapon " + ([_primary,1] call FUNC(GetDisplayName));

_id = __pGetVar(GVAR(pbp_id));

if (_id == -9999) then {__pSetVar

,-1,false]]};

if (alive player) then {GVAR(backpack_helper) = []};

};

};

I can not make it work

What am I doing wrong?

please help

thanks for your time

Greetings

Edited by Davt

Share this post


Link to post
Share on other sites

1. Always post code using the code tags. What you have becomes pretty much unreadable as indents are gone.

2. Use -showScriptErrors on your startup. What's the error message?

3. You're using init.sqs?

4. Domination code should not be the first thing to start copying, unless you're pretty familiar with the scripting language beforehand.

5. Are the functions already defined/precompiled (as I believe they are in the original)?

Share this post


Link to post
Share on other sites

many thanks CarlGustaffa

it works but if I have a defect "MK17" your boots often fail to pass a backpack and grab a secondary weapon how to solve it?

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 A Mochila", getText(configFile >> "cfgWeapons" >> prim_weap_player >> "displayName")];

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 A Mochila"", getText(configFile >> ""cfgWeapons"" >> prim_weap_player >> ""displayName"")], ""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 A movchila", getText(configFile >> "cfgWeapons" >> (primaryWeapon _p) >> "displayName")];

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

} else {

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

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

};

};

if (true) exitWith {};

x_backcpack.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 ["Arma %1", getText(configFile >> "cfgWeapons" >> _primary >> "displayName")];

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

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 ["Arma %1", getText(configFile >> "cfgWeapons" >> _primary >> "displayName")];

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

};

};

if (true) exitWith {};

the mission a trigger condition "local player"

in AI ACT handle = [] execVM "x_setupbackpack.sqf";

Thanks for your time

Edited by Davt

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  

×