From bdfee35a1836d176c67bafbfc9cd518d1ca4cad9 Mon Sep 17 00:00:00 2001 From: "DESKTOP-UH65DCE\\MusTanG" Date: Tue, 5 Dec 2017 18:20:08 -0600 Subject: [PATCH] CfgActions overriding - fire on/off req - a3 hooking ++ [FIXED] BurnBarrel and FirePlace02 UserActions requiring lighter_epoch did not need lighter when performed. [NEW] CfgActions event handler for "Action" ("PrevAction" and "NextAction" - not implemented yet) -Allows ability to override any of the CfgActions/UserActions in Arma 3 and other mods. [ADDED] usedItemRepack function to remove 1 use from the lighter. [ADDED] Require fire extinguisher to "Put Out Fire" on the Burn Barrel [CHANGED] ItemFireExtinguisher now has count = 5 for 5 uses to put out a small fire [ADDED] ItemFireExtinguisher to CfgItemSort and CfgPricing [ADDED] Arma Sling Loading requires ItemRope to sling and returns rope upon release.. [ADDED] Checks for R3F can_lift and Advanced Slingload InitVar. [ADDED] If above mod/script is present disable Arma SlingLoad Hook/Unhook action and key press. [CHANGED] While working with keyDown EH, debug logs show the DIKCodes are being pushed as whole numbers and not the 0x01 as the escape keyDown handler was setup to use and why my tests were failing using the 0x30 for the letter B(Hook/Unhook). [UPGRADED] Changed over the 0x01 and 0x30 to the actionKeys name in order to properly handle those with client using custom keys. [TEASED] Have a commented line in the Light Fire case showing future plans for a fire system(BURN BABY BURN!). [NEW] EPOCH_usedItemRepack Description: Allows adjusting of "ammo" counts in a magazine. Can be used locally and on the server for a remote unit. ``` [_player,_magazine,_change] call EPOCH_usedItemRepack; --- .../EPOCH_KeyDown.sqf | 27 ++++++- .../EPOCH_handleUIActions.sqf | 81 +++++++++++++++++++ .../inventory/EPOCH_usedItemRepack.sqf | 65 +++++++++++++++ .../compile/setup/EPOCH_clientInit.sqf | 12 +++ .../Configs/CfgClientFunctions.hpp | 2 + Sources/epoch_config/Configs/CfgItemSort.hpp | 3 +- Sources/epoch_config/Configs/CfgPricing.hpp | 4 + 7 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 Sources/epoch_code/compile/interface_event_handlers/EPOCH_handleUIActions.sqf create mode 100644 Sources/epoch_code/compile/inventory/EPOCH_usedItemRepack.sqf diff --git a/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyDown.sqf b/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyDown.sqf index 295c0f7c..4a2ede58 100644 --- a/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyDown.sqf +++ b/Sources/epoch_code/compile/interface_event_handlers/EPOCH_KeyDown.sqf @@ -72,7 +72,7 @@ if (_ctrl && _dikCode == EPOCH_keysVolumeDown) then { }; // ESC default to cancel -if (_dikCode == 0x01) then { +if (_dikCode in (actionKeys "ingamePause")) then { if !(isNull EPOCH_Target) then { if !(EPOCH_Target isKindOf "ThingX") then { deleteVehicle EPOCH_Target; @@ -264,4 +264,29 @@ if (_dikCode in (actionKeys "NightVision")) then { }; }; +if(!_ctrl && (_dikCode in (actionKeys "HeliRopeAction")))then{ + _msg = ""; + if(EPOCH_ArmaSlingLoad)then{ + if(driver vehicle player isEqualTo player)then{ + _slung = ropeAttachedObjects vehicle player; + if(_slung isEqualTo [])then{ + if!('ItemRope' in magazines player) then { + _msg = "You need rope to hook"; + _handled = true; + }else{ + player removeItem 'ItemRope'; + }; + }else{ + player addItem 'ItemRope'; + }; + }; + }else{ + _msg = "Hook/Unhook Malfunction, overrode by R3F or AdvSlingLoad"; + _handled = true; + }; + if!(_msg isEqualTo "")then{ + [_msg,5,[[0,0,0,0.2],[1,1,1,1]]] call Epoch_message_stack; + }; +}; + _handled diff --git a/Sources/epoch_code/compile/interface_event_handlers/EPOCH_handleUIActions.sqf b/Sources/epoch_code/compile/interface_event_handlers/EPOCH_handleUIActions.sqf new file mode 100644 index 00000000..e8ed286b --- /dev/null +++ b/Sources/epoch_code/compile/interface_event_handlers/EPOCH_handleUIActions.sqf @@ -0,0 +1,81 @@ +/* + Author: DirtySanchez - ported from DonkeyPunch eXpoch http://DonkeyPunch.INFO + + Contributors: + + Licence: + Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike + + Github: + https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/interface_event_handlers/EPOCH_handleUIActions.sqf +*/ +private['_msg', '_type', '_disableSlingLoad', '_slung']; +params [ + ['_actionObj',objNull], + ['_player',objNull], + ['_index',0], + ['_actionName',''], + ['_actionDisplayName',''], + ['_priority',1], + ['_showWindow',false], + ['_hideOnUse',true], + ['_shortCut',''], + ['_visibility',false], + ['_eventName',''] +]; +_blocked = false; +_msg = ''; +_type = typeOf _actionObj; +switch(true)do{ + case (_actionName isEqualTo 'FireInflame'): { + if!('lighter_epoch' in magazines player) then { + _msg = 'You need a lighter'; + _blocked = true; + }else{ + [player,'lighter_epoch',-1] call EPOCH_usedItemRepack; + //[_actionObj] remoteExec ['EPOCH_server_addToFireSystem',2]; + }; + }; + case (_actionName isEqualTo 'FirePutDown'): { + if(_type isEqualTo 'BurnBarrel_EPOCH')then{ + if!('ItemFireExtinguisher' in magazines player) then { + _msg = 'You need an extinguisher'; + _blocked = true; + }else{ + [player,'ItemFireExtinguisher',-1] call EPOCH_usedItemRepack; + }; + }; + }; + case (_actionName isEqualTo 'HookCargo'): { + if(EPOCH_ArmaSlingLoad)then{ + if(driver vehicle player isEqualTo player)then{ + _slung = ropeAttachedObjects vehicle player; + if(_slung isEqualTo [])then{ + if!('ItemRope' in magazines player) then { + _msg = 'You need rope to hook'; + _blocked = true; + }else{ + player removeItem 'ItemRope'; + }; + }else{ + player addItem 'ItemRope'; + }; + }; + }else{ + _msg = 'Hook Malfunction, overrode by R3F or AdvSlingLoad'; + _blocked = true; + }; + }; + case (_actionName isEqualTo 'UnhookCargo'): { + if(EPOCH_ArmaSlingLoad)then{ + player addItem 'ItemRope'; + }else{ + _msg = 'Unhook Malfunction, overrode by R3F or AdvSlingLoad'; + _blocked = true; + }; + }; +}; +if!(_msg isEqualTo '')then{ + [_msg,5,[[0,0,0,0.2],[1,1,1,1]]] call Epoch_message_stack; +}; +_blocked \ No newline at end of file diff --git a/Sources/epoch_code/compile/inventory/EPOCH_usedItemRepack.sqf b/Sources/epoch_code/compile/inventory/EPOCH_usedItemRepack.sqf new file mode 100644 index 00000000..a4f897a2 --- /dev/null +++ b/Sources/epoch_code/compile/inventory/EPOCH_usedItemRepack.sqf @@ -0,0 +1,65 @@ +/* + Author: DirtySanchez - ported from DonkeyPunch eXpoch http://DonkeyPunch.INFO + + Contributors: + + Licence: + Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike + + Github: + https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/inventory/EPOCH_usedItemRepack.sqf + + Description: + Allows adjustments to mag with least ammo. + Can be used server and client side as addMagazine is a global command + + Local Usage: + [player,'lighter_epoch',-1] call EPOCH_usedItemRepack; + + Global Usage: + [_playerObj,'lighter_epoch',-1] call EPOCH_usedItemRepack; +*/ +private["_msg","_itemMags","_displayName","_itemAmmoType","_mags","_ammoType","_total","_maxAmmo","_wholeMags","_remainder","_index","_usedItemArray"]; +params[ + ["_player",objNull], + ["_item",""], + ["_chg",0] +]; + +if(isNull _player) exitWith {diag_log "[EPOCHDebug] EPOCH_usedItemRepack - player isNull"}; + +if(_item isEqualTo "") exitWith {diag_log "[EPOCHDebug] EPOCH_usedItemRepack - classname is empty string"}; + +if!(isClass(configFile >> "CfgMagazines" >> _item)) exitWith {diag_log format["[EPOCHDebug] EPOCH_usedItemRepack - Classname does not exist",_item]}; + +_msg = ""; +_itemMags = []; +_displayName = getText(configFile >> "CfgMagazines" >> _item >> "displayName"); + +//get all mags of same classname and ammo type +_mags = magazinesAmmo _player; +{ + _x params ["_className","_count"]; + if(_className isEqualTo _item)then{ + _itemMags pushBack _x; + }; +}forEach _mags; + +// if more than 1 sort them by ammo count +if(count _itemMags > 1)then{ + _itemMags = [_itemMags,[],{_x select 1},"ASCEND"] call BIS_fnc_sortBy; +}; + +// adjust the item +if!(_chg isEqualTo 0)then{ + _index = ((count _itemMags) - 1); + _usedItemArray = _itemMags select _index; + _usedItemArray params ["_mag","_count"]; + _itemMags pushBack [_mag, (_count + _chg)]; + _itemMags = _itemMags - [_usedItemArray]; + _player removeMagazines _mag; + { + _player addMagazine _x; + [format["You have used your %1", _displayName],5,[[0,0,0,0.2],[1,1,1,1]]] call Epoch_message_stack; + }forEach _itemMags; +}; diff --git a/Sources/epoch_code/compile/setup/EPOCH_clientInit.sqf b/Sources/epoch_code/compile/setup/EPOCH_clientInit.sqf index b07ee0af..8ba26bff 100644 --- a/Sources/epoch_code/compile/setup/EPOCH_clientInit.sqf +++ b/Sources/epoch_code/compile/setup/EPOCH_clientInit.sqf @@ -53,3 +53,15 @@ EPOCH_playerStaminaMax = 100; enableSentences false; enableRadio false; player setVariable["BIS_noCoreConversations", true]; + +EPOCH_ArmaSlingLoad = true; +_r3fON = if(!isNil "R3F_LOG_CFG_can_lift")then{if!(R3F_LOG_CFG_can_lift isEqualTo [])then{true}else{false}}else{false}; +_advSling = if(!isNil "ASL_ROPE_INIT")then{if(ASL_ROPE_INIT)then{true}else{false}}else{false}; +if (_r3fON || _advSling)then{ + EPOCH_ArmaSlingLoad = false; +}; + +// handle actions, prevactions, nextactions +inGameUISetEventHandler ["Action", "if(!(_this isEqualTo []) && !(_this select 10 in ['PrevAction','NextAction']))then{_this call EPOCH_handleUIActions}"]; +//inGameUISetEventHandler ["NextAction", "_this call EPOCH_handleUIActions"]; +//inGameUISetEventHandler ["PrevAction", "_this call EPOCH_handleUIActions"]; diff --git a/Sources/epoch_config/Configs/CfgClientFunctions.hpp b/Sources/epoch_config/Configs/CfgClientFunctions.hpp index 58937b61..639c3088 100644 --- a/Sources/epoch_config/Configs/CfgClientFunctions.hpp +++ b/Sources/epoch_config/Configs/CfgClientFunctions.hpp @@ -91,6 +91,7 @@ class CfgClientFunctions }; class KeyUp {}; class onChar {}; + class handleUIActions {}; }; class event_handlers { @@ -207,6 +208,7 @@ class CfgClientFunctions class refeshUI {}; class equip {}; class itemTypeSlot {}; + class usedItemRepack {}; }; class servicepoint { diff --git a/Sources/epoch_config/Configs/CfgItemSort.hpp b/Sources/epoch_config/Configs/CfgItemSort.hpp index ff070a82..60f3c617 100644 --- a/Sources/epoch_config/Configs/CfgItemSort.hpp +++ b/Sources/epoch_config/Configs/CfgItemSort.hpp @@ -1128,7 +1128,8 @@ class CfgItemSort "SeedPacket_Hemp", "SeedPacket_Poppy", "SeedPacket_Pumpkin", - "SeedPacket_Sunflower" + "SeedPacket_Sunflower", + "ItemFireExtinguisher" }; Vehicles_Land[] = { "ebike_epoch", // Motorrad diff --git a/Sources/epoch_config/Configs/CfgPricing.hpp b/Sources/epoch_config/Configs/CfgPricing.hpp index 19ecf509..cbf500f3 100644 --- a/Sources/epoch_config/Configs/CfgPricing.hpp +++ b/Sources/epoch_config/Configs/CfgPricing.hpp @@ -1824,6 +1824,10 @@ class CfgPricing { price = 50; }; + class ItemFireExtinguisher + { + price = 50; + } class WoodLog_EPOCH { price = 2;