diff --git a/Sources/epoch_code/compile/functions/EPOCH_fnc_getHitPointsDamageAverage.sqf b/Sources/epoch_code/compile/functions/EPOCH_fnc_getHitPointsDamageAverage.sqf new file mode 100644 index 00000000..d0828d4c --- /dev/null +++ b/Sources/epoch_code/compile/functions/EPOCH_fnc_getHitPointsDamageAverage.sqf @@ -0,0 +1,37 @@ +/* + Author: Aaron Clark - EpochMod.com + + Contributors: + + Description: + Function to check HitPointDamageAverage. + + 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/functions/EPOCH_fnc_getHitPointsDamageAverage.sqf + + Example: + _average = [cursorObject, "steering", 1] call EPOCH_fnc_getHitPointsDamageAverage;; + + Parameter(s): + _this select 0: OBJECT - Object to check Hitpoints + _this select 1: STRING - String to find in Hitpointname (e.g. "wheel"); + _this select 2: SCALAR - Sub-Array in getAllHitPointsDamage to search for String (default = 0) + _this select 3: SCALAR - Sub-Array for Hitpoint-Values in getAllHitPointsDamage (default = 2) + + Returns: + SCALAR +*/ +params [ "_object", "_match", ["_indexIn", 0], ["_indexOut", 2] ]; +_dmg = 0; +_parts = 0; +_allHitPoints = getAllHitPointsDamage _object; +{ + if ((toLower(_x) find _match) != -1) then { + _dmg = _dmg + ((_allHitPoints select _indexOut) select _forEachIndex); + _parts = _parts + 1; + }; +} forEach (_allHitPoints select _indexIn); +(_dmg / _parts) diff --git a/Sources/epoch_code/compile/traders/EPOCH_npcTraderAdd.sqf b/Sources/epoch_code/compile/traders/EPOCH_npcTraderAdd.sqf index fd938ff7..19386532 100644 --- a/Sources/epoch_code/compile/traders/EPOCH_npcTraderAdd.sqf +++ b/Sources/epoch_code/compile/traders/EPOCH_npcTraderAdd.sqf @@ -1,5 +1,5 @@ //[[[cog import generate_private_arrays ]]] -private ["_aiItems","_allowAdd","_array","_config","_cryptoCount","_index","_item","_itemClasses","_itemQtys","_itemTax","_itemWorth","_limit","_qtyIndex","_sizeOut","_slot","_stockLimit","_tax","_uiItem","_worth"]; +private ["_errormsg","_aiItems","_allowAdd","_array","_config","_cryptoCount","_index","_item","_itemClasses","_itemQtys","_itemTax","_itemWorth","_limit","_qtyIndex","_sizeOut","_slot","_stockLimit","_tax","_uiItem","_worth"]; //[[[end]]] params ["_control","_selected"]; @@ -8,6 +8,7 @@ if !(isNull EPOCH_lastNPCtradeTarget) then { _allowAdd = true; _stockLimit = false; _uiItem = (_selected select 0) lbData (_selected select 1); + _errormsg = "Limit one per trade"; _config = 'CfgPricing' call EPOCH_returnConfig; if (isClass(_config >> _uiItem)) then{ @@ -33,6 +34,23 @@ if !(isNull EPOCH_lastNPCtradeTarget) then { }; if (_uiItem isKindOf "Air" || _uiItem isKindOf "Ship" || _uiItem isKindOf "LandVehicle" || _uiItem isKindOf "Tank") then { + if (["CfgEpochClient", "DisallowSellOnDamage", false] call EPOCH_fnc_returnConfigEntryV2) then { + { + _vehicle = _x; + if (local _vehicle && (typeof _vehicle) isequalto _uiItem) then { + { + if ((["wheel",tolower _x] call bis_fnc_instring) || _x isequalto "HitEngine") then { + if (((getAllHitPointsDamage _vehicle) select 2 select _foreachindex) >= 1) then { + _allowAdd = false; + _errormsg = "Cannot be sold - too much damage"; + }; + }; + if (!_allowAdd) exitwith {}; + } foreach ((getAllHitPointsDamage _vehicle) select 0); + }; + if (!_allowAdd) exitwith {}; + } foreach (EPOCH_lastNPCtradeTarget nearEntities[[_uiItem], 30]); + }; // check if a vehicle is already on the list _sizeOut = lbSize 41501; @@ -94,7 +112,7 @@ if !(isNull EPOCH_lastNPCtradeTarget) then { if (_stockLimit) then{ ["Trader has the maximum amount of this item", 5] call Epoch_message; } else { - ["Limit one per trade", 5] call Epoch_message; + [_errormsg, 5] call Epoch_message; }; }; }; diff --git a/Sources/epoch_config/Configs/CfgClientFunctions.hpp b/Sources/epoch_config/Configs/CfgClientFunctions.hpp index 6cc7496d..b1cd513c 100644 --- a/Sources/epoch_config/Configs/CfgClientFunctions.hpp +++ b/Sources/epoch_config/Configs/CfgClientFunctions.hpp @@ -136,6 +136,7 @@ class CfgClientFunctions class giveAttributes {}; class fnc_spawnEffects {}; class fnc_arrayStringToBool {}; + class fnc_getHitPointsDamageAverage {}; }; class environment { diff --git a/Sources/epoch_config/Configs/CfgEpochClient.hpp b/Sources/epoch_config/Configs/CfgEpochClient.hpp index aca15c5b..a95c57dd 100644 --- a/Sources/epoch_config/Configs/CfgEpochClient.hpp +++ b/Sources/epoch_config/Configs/CfgEpochClient.hpp @@ -99,6 +99,7 @@ class CfgEpochClient // Advanced Vehicle Repair UseAdvancedVehicleRepair = "true"; // Switch On / Off Advanced Vehicle Repair (Does not effect SuppressedCraftingItems !) + DisallowSellOnDamage = "false"; // Prevent from selling Vehicles with one or more fully damaged wheel or engine SuppressedCraftingItems[] = {"VehicleRepair","VehicleRepairLg"}; // Suppresed for usage of "Advanced Vehicle Repair" VehicleRepairs[] = { // {Hitpoint, dmg to repair, dmg to replace, mat to repair, mat to replace} {"HitHull",0.33,0.66,"ItemScraps","ItemCorrugated"},