Skip to content

Commit

Permalink
Merge pull request #20 from DerZade/patch_1.1.2
Browse files Browse the repository at this point in the history
Update 1.2
  • Loading branch information
DerZade authored Mar 30, 2017
2 parents a457a05 + 8713f93 commit da58281
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 34 deletions.
8 changes: 8 additions & 0 deletions addons/zade_boc/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,13 @@ class CfgFunctions
class moduleDisable {};
class pasteRadioSettings {};
};
class arsenal
{
file = "\zade_boc\functions\arsenal";
class arsenalOpened {};
class arsenal_onButtonClick {};
class arsenal_updateUI {};
class arsenal_postInit {postInit = 1;};
};
};
};
4 changes: 2 additions & 2 deletions addons/zade_boc/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ class CfgPatches {
units[] = {"zade_boc_moduleDisable","zade_boc_moduleAdd","zade_boc_moduleOnChest"};
weapons[] = {};
requiredVersion = 0.1;
requiredAddons[] = {"a3_ui_f","A3_Modules_F","ace_main"};
version = "1.1";
requiredAddons[] = {"a3_ui_f","A3_Modules_F","ace_main","ace_common"};
version = "1.2";
author = "DerZade";
};
};
Expand Down
34 changes: 34 additions & 0 deletions addons/zade_boc/functions/arsenal/fn_arsenalOpened.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
params ["_display"];

//exit if BOC is disabled
if (missionNamespace getVariable ['zade_boc_disabled',false]) exitWith {};

//get lowest button that is hidden
private _notshown = 948;
for "_i" from 948 to 945 step -1 do {
if !(ctrlShown (_display displayCtrl _i)) then {
_notshown = _i;
};
};

//default offset of two buttons
private _offset = ((ctrlPosition (_display displayCtrl 932)) select 1) - ((ctrlPosition (_display displayCtrl 930)) select 1);

private _btn = _display ctrlCreate ["RscButtonArsenal", 9233];

//set pos
private _pos = ctrlPosition (_display displayCtrl (_notshown - 1));
_pos set [1, (_pos select 1) + _offset];
_btn ctrlSetPosition _pos;
_btn ctrlCommit 0;

//set color
_btn ctrlSetBackgroundColor [0,0,0,0.5];

//add EH to backpack list and button
(_display displayCtrl 965) ctrlAddEventHandler ["LBSelChanged",zade_boc_fnc_arsenal_updateUI];
_btn ctrlAddEventHandler ["ButtonClick",zade_boc_fnc_arsenal_onButtonClick];

_display displayAddEventHandler ["KeyDown", "params ['_disp','_key']; if (_key isEqualTo 14) then {[_disp] spawn {sleep 0.02; ((_this select 0) displayCtrl 9233) ctrlShow (ctrlShown ((_this select 0) displayCtrl 932));};};"];

[_display] call zade_boc_fnc_arsenal_updateUI;
13 changes: 13 additions & 0 deletions addons/zade_boc/functions/arsenal/fn_arsenal_onButtonClick.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
private _center = missionnamespace getvariable ["BIS_fnc_arsenal_center",player];

private _chestpack = [_center] call zade_boc_fnc_chestpack;
private _backpack = backpack _center;

private _action = ["onback", "onchest"] select (_chestpack isEqualTo "");
if (!(_backpack isEqualTo "") and !(_chestpack isEqualTo "")) then {_action = "swap";};

//exec action
[_center] call (missionNamespace getVariable (format ["zade_boc_fnc_action%1",_action]));

//update arsenal
["ListSelectCurrent"] call BIS_fnc_arsenal;
3 changes: 3 additions & 0 deletions addons/zade_boc/functions/arsenal/fn_arsenal_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (isServer and isMultiplayer) exitWith {};

[missionNamespace, "arsenalOpened", zade_boc_fnc_arsenalOpened] call BIS_fnc_addScriptedEventHandler;
25 changes: 25 additions & 0 deletions addons/zade_boc/functions/arsenal/fn_arsenal_updateUI.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
disableSerialization;
params ["_display"];

if (_display isEqualType controlNull) exitWith { //the onSelChanged EH calls before the actual backpack changed so we have to wait a little bit
[ctrlParent _display] spawn {sleep 0.05; _this call zade_boc_fnc_arsenal_updateUI};
};

//the arsenal unit
private _center = missionnamespace getvariable ["BIS_fnc_arsenal_center",player];

private _chestpack = [_center] call zade_boc_fnc_chestpack;
private _backpack = backpack _center;

private _action = ["onback", "onchest"] select (_chestpack isEqualTo "");
if (!(_backpack isEqualTo "") and !(_chestpack isEqualTo "")) then {_action = "swap";};

(_display displayCtrl 9233) ctrlSetText format ["\zade_boc\data\actions\%1_ca.paa",_action];
(_display displayCtrl 9233) ctrlSetTooltip localize format ["STR_zade_boc_%1",_action];

if ((_backpack isEqualTo "") and (_chestpack isEqualTo "")) then {
(_display displayCtrl 9233) ctrlEnable false;
(_display displayCtrl 9233) ctrlSetTooltip "";
} else {
(_display displayCtrl 9233) ctrlEnable true;
};
2 changes: 1 addition & 1 deletion addons/zade_boc/functions/commands/fn_addChestpack.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private _killedID = _unit addEventHandler ["Killed",zade_boc_fnc_EHKilled];
//create chestpack itself
private _chestpack = createSimpleObject [_chestpackClass, getPos _unit];

_unit forceWalk true;
[_unit, "forceWalk", "BackpackOnChest", true] call ace_common_fnc_statusEffect_set;

//set variable
_unit setVariable ["zade_boc_chestpack",[[_chestpackClass,_chestpack],[_getInID,_getOutID,_animID,_killedID],[],[]],true];
Expand Down
2 changes: 1 addition & 1 deletion addons/zade_boc/functions/commands/fn_removeChestpack.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ _unit removeEventHandler ["GetOutMan",(_var select 1) select 1];
_unit removeEventHandler ["AnimDone",(_var select 1) select 2];
_unit removeEventHandler ["Killed",(_var select 1) select 3];

_unit forceWalk false;
[_unit, "forceWalk", "BackpackOnChest", false] call ace_common_fnc_statusEffect_set;

//reset variable
_unit setVariable ["zade_boc_chestpack",nil,true];
Expand Down
2 changes: 1 addition & 1 deletion addons/zade_boc/functions/utility/fn_EHGetOut.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ private _chestpack = [_unit] call zade_boc_fnc_chestpackContainer;
[_chestpack, [[-0.25,-1,0],[0,0,1]]] remoteExec ["setVectorDirAndUp", 0];
[_chestpack, false] remoteExec ["hideObjectGlobal", 0];

_unit forceWalk true;
[_unit, "forceWalk", "BackpackOnChest", true] call ace_common_fnc_statusEffect_set;
3 changes: 3 additions & 0 deletions addons/zade_boc/functions/utility/fn_actionOnBack.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ private _chestpackitems = [_player,false] call zade_boc_fnc_chestpackItems;
private _chestpackmags = [_player] call zade_boc_fnc_chestpackMagazines;
private _radioSettings = +(_player getVariable ["zade_boc_radioSettings",[]]);

//make sure the player has a chestpack and no backpack
if ((_chestpack isEqualTo "") or !(backpack _player isEqualTo "")) exitWith {};

//add pack
_player addBackpackGlobal _chestpack;
clearAllItemsFromBackpack _player;
Expand Down
3 changes: 3 additions & 0 deletions addons/zade_boc/functions/utility/fn_actionOnChest.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ private _backpack = backpack _player;
private _backpackitems = (itemCargo (backpackContainer _player) + weaponCargo (backpackContainer _player) + backpackCargo (backpackContainer _player));
private _backpackmags = [_player] call zade_boc_fnc_backpackMagazines;

//make sure the player has no chestpack and a backpack
if ((_backpack isEqualTo "") or !(([_player] call zade_boc_fnc_chestpack) isEqualTo "")) exitWith {};

//remove all mags out of items to prevent adding mags two times
{
for "_i" from 1 to (_x select 2) do {
Expand Down
3 changes: 3 additions & 0 deletions addons/zade_boc/functions/utility/fn_actionSwap.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ private _chestpackitems = [_player,false] call zade_boc_fnc_chestpackItems;
private _chestpackmags = [_player] call zade_boc_fnc_chestpackMagazines;
private _radioSettings = +(_player getVariable ["zade_boc_radioSettings",[]]);

//make sure the player has chest- and backpack
if ((_backpack isEqualTo "") or ([_player] call zade_boc_fnc_chestpack) isEqualTo "") exitWith {};

//handle attachments in the backpack
{
//remove weapon and add base wepaon
Expand Down
45 changes: 17 additions & 28 deletions addons/zade_boc/functions/utility/fn_backpackMagazines.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Author: DerZade
* Author: DerZade & Jack Ost
* Gets array with all magazines from backpack of the given unit.
*
* Arguments:
Expand All @@ -18,34 +18,23 @@ params ["_unit"];
private _magsArray = [];

{
_mag = _x;
//search for a item in the backpack items which has the same displayname to get a classname
_classname = "";
_displayName = "";
{
_displayName = getText (configFile >> "CfgMagazines" >> _x >> "DisplayName");
if (_mag find _displayName != -1 and _displayName != "") exitWith {_classname = _x;};
} forEach (backpackItems _unit);
_arr = +(toArray _mag);
_mag = _x;
_classname = "";
_displayname = "";

{
_displayName = getText (configFile >> "CfgMagazines" >> _x >> "DisplayName");
if ((_mag find _displayname)!=(-1) and _displayName != "") exitWith {_classname = _x;};
} forEach (backpackItems _unit);

_arr = _x splitString "(";
_size = count _arr;
_temp = (_arr select (_size-2)) splitString "/";
_ammo = parseNumber (_temp select 0);
_temp = (_arr select (_size-1)) splitString "x";
_amount = parseNumber (_temp select 0);

//get ammo of magazine(s)
_arr deleteRange [0,count _displayName+1]; //remove displayname + '('
_ammo = +_arr;
_ammo deleteRange [(_ammo find 47), count _ammo]; //remove everything after '/'
_ammo = parseNumber toString _ammo;

//get amount of magazine(s)
_arr call BIS_fnc_arrayPop; //remove last element ')'
_arr call BIS_fnc_arrayPop; //remove last element 'x'
_amount = [];
_element = _arr call BIS_fnc_arrayPop;
while {_element != 40} do {
[_amount,_element] call BIS_fnc_arrayUnShift;
_element = _arr call BIS_fnc_arrayPop;
};
_amount = parseNumber toString _amount;

_magsArray pushBack [_classname,_ammo,_amount];
_magsArray pushBack [_classname,_ammo,_amount];
} forEach (backpackMagazines _unit);

_magsArray
2 changes: 1 addition & 1 deletion mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "BackpackOnChest";
picture = "logo_boc_ca.paa";
actionName = "GITHUB";
action = "https://github.com/DerZade/BackpackOnChest";
description = "BOC - Version 1.1.1";
description = "BOC - Version 1.2";
logo = "logo_boc_ca.paa";
logoOver = "logo_boc_ca.paa";
tooltip = "BOC";
Expand Down

0 comments on commit da58281

Please sign in to comment.