From f03f2454c9f5d53bf456ca31c9f699df2f4c45f0 Mon Sep 17 00:00:00 2001 From: icomrade Date: Sun, 21 Jan 2018 17:26:35 -0500 Subject: [PATCH] Update for A2 1.64 GetHit Replaced vehicle sethit/setvariable method with sethit/gethit and removed setvariable "Hit_" commands for vehicles (hit_partname can now probably be added to the setvariable filters list). Modified object_getHit.sqf return to now provide the selection name in order to reduce redundant config lookups. Returns '[Damage, Part Name]', instead of just 'Damage' Modified vehicle_GetHitpoints.sqf to remove incorrect hipoints from returning. Previously this script would return all hitpoints from any vehicle the current vehicle config inherited from, even if the hitpoint didn't exist in the calling vehicle. this posed a problem since getHit on an invalid part name returns Nil --- .../functions/z_at_sellItems.sqf | 2 +- SQF/dayz_code/actions/repair.sqf | 6 +++-- SQF/dayz_code/actions/repair_vehicle.sqf | 3 ++- SQF/dayz_code/actions/salvage.sqf | 5 ++-- SQF/dayz_code/actions/salvage_vehicle.sqf | 4 +-- SQF/dayz_code/actions/trade_any_bicycle.sqf | 3 +-- .../actions/trade_any_bicycle_old.sqf | 3 +-- SQF/dayz_code/actions/trade_any_vehicle.sqf | 3 +-- .../actions/trade_any_vehicle_free.sqf | 3 +-- .../actions/trade_any_vehicle_old.sqf | 3 +-- SQF/dayz_code/compile/object_getHit.sqf | 5 ++-- SQF/dayz_code/compile/player_zombieAttack.sqf | 3 +-- .../compile/player_zombieSwarmAttack.sqf | 11 +++----- SQF/dayz_code/compile/veh_handleDam.sqf | 14 ++-------- SQF/dayz_code/compile/veh_handleRepair.sqf | 5 +--- SQF/dayz_code/compile/veh_setFixServer.sqf | 4 +-- .../compile/vehicle_getHitpoints.sqf | 14 +++++----- .../compile/server_updateObject.sqf | 26 +++++++++---------- SQF/dayz_server/system/server_monitor.sqf | 4 +-- 19 files changed, 50 insertions(+), 71 deletions(-) diff --git a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_sellItems.sqf b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_sellItems.sqf index ab03b7d1c..f78a1f767 100644 --- a/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_sellItems.sqf +++ b/SQF/dayz_code/actions/AdvancedTrading/functions/z_at_sellItems.sqf @@ -30,7 +30,7 @@ _sellVehicle = { _hitpoints = DZE_myVehicle call vehicle_getHitpoints; { if (["Wheel",_x,false] call fnc_inString) then { - _damage = [DZE_myVehicle,_x] call object_getHit; + _damage = ([DZE_myVehicle,_x] call object_getHit) select 0; _tireDmg = _tireDmg + _damage; _tires = _tires + 1; }; diff --git a/SQF/dayz_code/actions/repair.sqf b/SQF/dayz_code/actions/repair.sqf index f172e4cbf..c58b1af46 100644 --- a/SQF/dayz_code/actions/repair.sqf +++ b/SQF/dayz_code/actions/repair.sqf @@ -34,12 +34,14 @@ if ("ItemToolbox" in items player && (_part in magazines player)) then { // Added Nutrition-Factor for work ["Working",0,[20,40,15,0]] call dayz_NutritionSystem; - _damage = [_vehicle,_hitpoint] call object_getHit; + _hits = [_vehicle,_hitpoint] call object_getHit; + _damage = _hits select 0; + _vehicle removeAction _id; //dont waste loot on undamaged parts if (_damage > 0) then { //Fix the part - _selection = getText(configFile >> "cfgVehicles" >> _type >> "HitPoints" >> _hitpoint >> "name"); + _selection = _hits select 1; [_vehicle, _selection, 0, true] call fnc_veh_handleRepair; _vehicle setvelocity [0,0,1]; diff --git a/SQF/dayz_code/actions/repair_vehicle.sqf b/SQF/dayz_code/actions/repair_vehicle.sqf index 9edc949ae..2f60543d4 100644 --- a/SQF/dayz_code/actions/repair_vehicle.sqf +++ b/SQF/dayz_code/actions/repair_vehicle.sqf @@ -8,7 +8,8 @@ _hitpoints = _vehicle call vehicle_getHitpoints; { _hitpoint = _x; - _damage = [_vehicle,_x] call object_getHit; + _hits = [_vehicle,_x] call object_getHit; + _damage = _hits select 0; _cmpt = toArray (_x); _cmpt set [0,20]; diff --git a/SQF/dayz_code/actions/salvage.sqf b/SQF/dayz_code/actions/salvage.sqf index 19beb821b..6033f987c 100644 --- a/SQF/dayz_code/actions/salvage.sqf +++ b/SQF/dayz_code/actions/salvage.sqf @@ -31,7 +31,8 @@ if (_hasToolbox) then { ["Working",0,[20,40,15,0]] call dayz_NutritionSystem; //Remove melee magazines (BIS_fnc_invAdd fix) false call dz_fn_meleeMagazines; - _damage = [_vehicle,_hitpoint] call object_getHit; + _hits = [_vehicle,_hitpoint] call object_getHit; + _damage = _hits select 0; if (_damage < 1 && {_damage > 0}) then { //Tempfix for issue where certain hitpoints on some vehicles do not get damaged and allow infinite removal _BreakableParts = ["HitGlass1","HitGlass2","HitGlass3","HitGlass4","HitGlass5","HitGlass6","HitLGlass","HitRGlass","HitEngine","HitFuel","HitHRotor"]; if (_hitpoint in _BreakableParts) then { @@ -48,7 +49,7 @@ if (_hasToolbox) then { }; if (_isOK) then { - _selection = getText(configFile >> "cfgVehicles" >> _type >> "HitPoints" >> _hitpoint >> "name"); + _selection = _hits select 1; /*if ((_hitpoint == "HitEngine") or (_hitpoint == "HitFuel")) then { [_vehicle, _selection, 0.89] call fnc_veh_handleDam; } else {*/ diff --git a/SQF/dayz_code/actions/salvage_vehicle.sqf b/SQF/dayz_code/actions/salvage_vehicle.sqf index 51ff94d5a..3b09185ec 100644 --- a/SQF/dayz_code/actions/salvage_vehicle.sqf +++ b/SQF/dayz_code/actions/salvage_vehicle.sqf @@ -41,8 +41,8 @@ if (_is6WheelType) then { { _hitpoint = _x; - _damage = [_vehicle,_x] call object_getHit; - + _hits = [_vehicle,_x] call object_getHit; + _damage = _hits select 0; if !(_x in _RemovedPartsArray) then { //if (_x in ["HitFuel","HitEngine"] && _damage >= 0.89) then {_damage = 1;}; _cmpt = toArray (_x); diff --git a/SQF/dayz_code/actions/trade_any_bicycle.sqf b/SQF/dayz_code/actions/trade_any_bicycle.sqf index a82896b5a..eb10a6e11 100644 --- a/SQF/dayz_code/actions/trade_any_bicycle.sqf +++ b/SQF/dayz_code/actions/trade_any_bicycle.sqf @@ -154,11 +154,10 @@ if (_finished) then { // total damage _tireDmg = 0; - _damage = 0; { if(["Wheel",_x,false] call fnc_inString) then { _damage = [_obj,_x] call object_getHit; - _tireDmg = _tireDmg + _damage; + _tireDmg = _tireDmg + (_damage select 0); _tires = _tires + 1; }; } count _hitpoints; diff --git a/SQF/dayz_code/actions/trade_any_bicycle_old.sqf b/SQF/dayz_code/actions/trade_any_bicycle_old.sqf index f39ccf9eb..0a2e2c7c0 100644 --- a/SQF/dayz_code/actions/trade_any_bicycle_old.sqf +++ b/SQF/dayz_code/actions/trade_any_bicycle_old.sqf @@ -128,11 +128,10 @@ if (_qty >= _qty_in) then { // total damage _tireDmg = 0; - _damage = 0; { if(["Wheel",_x,false] call fnc_inString) then { _damage = [_obj,_x] call object_getHit; - _tireDmg = _tireDmg + _damage; + _tireDmg = _tireDmg + (_damage select 0); _tires = _tires + 1; }; } count _hitpoints; diff --git a/SQF/dayz_code/actions/trade_any_vehicle.sqf b/SQF/dayz_code/actions/trade_any_vehicle.sqf index 1375b3be3..dbd8157d0 100644 --- a/SQF/dayz_code/actions/trade_any_vehicle.sqf +++ b/SQF/dayz_code/actions/trade_any_vehicle.sqf @@ -161,11 +161,10 @@ if (_finished) then { // total damage _tireDmg = 0; - _damage = 0; { if(["Wheel",_x,false] call fnc_inString) then { _damage = [_obj,_x] call object_getHit; - _tireDmg = _tireDmg + _damage; + _tireDmg = _tireDmg + (_damage select 0); _tires = _tires + 1; }; } count _hitpoints; diff --git a/SQF/dayz_code/actions/trade_any_vehicle_free.sqf b/SQF/dayz_code/actions/trade_any_vehicle_free.sqf index ea194f49e..7258e03d1 100644 --- a/SQF/dayz_code/actions/trade_any_vehicle_free.sqf +++ b/SQF/dayz_code/actions/trade_any_vehicle_free.sqf @@ -156,11 +156,10 @@ if (_finished) then { // total damage _tireDmg = 0; - _damage = 0; { if(["Wheel",_x,false] call fnc_inString) then { _damage = [_obj,_x] call object_getHit; - _tireDmg = _tireDmg + _damage; + _tireDmg = _tireDmg + (_damage select 0); _tires = _tires + 1; }; } count _hitpoints; diff --git a/SQF/dayz_code/actions/trade_any_vehicle_old.sqf b/SQF/dayz_code/actions/trade_any_vehicle_old.sqf index e526df4be..8c9db3a4e 100644 --- a/SQF/dayz_code/actions/trade_any_vehicle_old.sqf +++ b/SQF/dayz_code/actions/trade_any_vehicle_old.sqf @@ -136,11 +136,10 @@ if (_qty >= _qty_in) then { // total damage _tireDmg = 0; - _damage = 0; { if(["Wheel",_x,false] call fnc_inString) then { _damage = [_obj,_x] call object_getHit; - _tireDmg = _tireDmg + _damage; + _tireDmg = _tireDmg + (_damage select 0); _tires = _tires + 1; }; } count _hitpoints; diff --git a/SQF/dayz_code/compile/object_getHit.sqf b/SQF/dayz_code/compile/object_getHit.sqf index 6fa31178b..4d6a8d6c8 100644 --- a/SQF/dayz_code/compile/object_getHit.sqf +++ b/SQF/dayz_code/compile/object_getHit.sqf @@ -2,7 +2,6 @@ _unit = _this select 0; _hp = _this select 1; _selection = getText (configFile >> "CfgVehicles" >> (typeOf _unit) >> "HitPoints" >> _hp >> "name"); -_strH = "hit_" + (_selection); -_dam = _unit getVariable [_strH,0]; +_dam = _unit getHit _selection; -_dam \ No newline at end of file +[_dam, _selection]; \ No newline at end of file diff --git a/SQF/dayz_code/compile/player_zombieAttack.sqf b/SQF/dayz_code/compile/player_zombieAttack.sqf index 6c040f096..2992d7fc3 100644 --- a/SQF/dayz_code/compile/player_zombieAttack.sqf +++ b/SQF/dayz_code/compile/player_zombieAttack.sqf @@ -133,8 +133,7 @@ if (_isVehicle) then { }; if (_wound in [ "glass1", "glass2", "glass3", "glass4", "glass5", "glass6" ]) then { - _strH = "hit_" + (_wound); - _dam = _vehicle getVariable [_strH,0]; + _dam = _vehicle getHit _wound; _total = (_dam + _damage); //handle vehicle dmg diff --git a/SQF/dayz_code/compile/player_zombieSwarmAttack.sqf b/SQF/dayz_code/compile/player_zombieSwarmAttack.sqf index 16ae81a51..29e21e165 100644 --- a/SQF/dayz_code/compile/player_zombieSwarmAttack.sqf +++ b/SQF/dayz_code/compile/player_zombieSwarmAttack.sqf @@ -40,16 +40,13 @@ if (_vehicle != player) then { [_unit,"hit",0,false] call dayz_zombieSpeak; if (_wound IN [ "glass1", "glass2", "glass3", "glass4", "glass5", "glass6" ]) then { - _strH = "hit_" + (_wound); - _dam = _vehicle getVariable [_strH,0]; - _total = (_dam + _damage); + _dam = _vehicle getHit _wound; - _woundDamage = _unit getVariable ["hit_"+_wound, 0]; - // we limit how vehicle could be damaged by Z. Above 0.8, the vehicle could explode, which is ridiculous. - _damage = (if (_woundDamage < 0.8 OR {(!(_wound IN dayZ_explosiveParts))}) then {0.1} else {0.01}); + // we limit how _dam could be damaged by Z. Above 0.8, the vehicle could explode, which is ridiculous. + _damage = (if (_dam < 0.8 OR {(!(_wound IN dayZ_explosiveParts))}) then {0.1} else {0.01}); // Add damage to vehicle. the "sethit" command will be done by the gameengine for which vehicle is local //diag_log(format["%1: Part ""%2"" damaged from vehicle, damage:+%3", __FILE__, _wound, _damage]); - _total = [_vehicle, _wound, _woundDamage + _damage, _unit, "zombie", true] call fnc_veh_handleDam; + _total = [_vehicle, _wound, _damage, _unit, "zombie", true] call fnc_veh_handleDam; }; } else { if ((_unit distance player) <= 3) then { diff --git a/SQF/dayz_code/compile/veh_handleDam.sqf b/SQF/dayz_code/compile/veh_handleDam.sqf index 377f3507e..09377d6a0 100644 --- a/SQF/dayz_code/compile/veh_handleDam.sqf +++ b/SQF/dayz_code/compile/veh_handleDam.sqf @@ -14,19 +14,12 @@ or by zombie_attack - return : updated damage for that part broadcast: boolean. if true, then the request will be sent to all players if the vehicle is not local. ************************************************************/ -private["_unit","_selection","_strH","_total","_damage","_needUpdate","_totalDmg"]; +private["_unit","_selection","_total","_damage","_needUpdate","_totalDmg"]; _unit = _this select 0; _selection = _this select 1; _total = _this select 2; - -if (_selection != "") then { - _strH = "hit_" + _selection; - _totalDmg = false; -} else { - _strH = "totalDmg"; - _totalDmg = true; -}; +_totalDmg = if (_selection != "") then {false} else {true}; if (_total >= 0.98) then { _total = 1.0; @@ -34,9 +27,6 @@ if (_total >= 0.98) then { if (local _unit) then { if (_total > 0) then { - if (!_totalDmg) then { - _unit setVariable [_strH, _total, true]; - }; _unit setHit [_selection, _total]; PVDZ_veh_Save = [_unit,"damage",false,_totalDmg]; diff --git a/SQF/dayz_code/compile/veh_handleRepair.sqf b/SQF/dayz_code/compile/veh_handleRepair.sqf index c359e0e74..8facafc23 100644 --- a/SQF/dayz_code/compile/veh_handleRepair.sqf +++ b/SQF/dayz_code/compile/veh_handleRepair.sqf @@ -25,15 +25,12 @@ _hitpointnames = []; if ((isNil "_selection") OR {(!(_selection in _hitpointnames))}) exitWith {_this select 2}; -_SVname = "hit_" + _selection; - _log = format["%1 vehicle:%2#%3 part:""%4"" current_part_damage:%5", __FILE__, typeOf _unit, _unit getVariable ["ObjectID",""], -_selection, _unit getVariable [_SVname, 0] ]; +_selection, _unit getHit _selection ]; if (local _unit) then { // only local unit can set the damage of a vehicle part - _unit setVariable [_SVname, 0, true]; _unit setHit [_selection, 0]; _log = format["%1. setH!t[%2,0]", _log, _selection]; if (!isServer) then { diff --git a/SQF/dayz_code/compile/veh_setFixServer.sqf b/SQF/dayz_code/compile/veh_setFixServer.sqf index 510f00282..de5a993e2 100644 --- a/SQF/dayz_code/compile/veh_setFixServer.sqf +++ b/SQF/dayz_code/compile/veh_setFixServer.sqf @@ -1,13 +1,11 @@ -private["_unit","_selection","_strH","_damage","_total"]; +private["_unit","_selection","_damage","_total"]; _unit = _this select 0; _selection = _this select 1; _damage = _this select 2; if (_selection != "" and local _unit) then { - _strH = "hit_" + (_selection); _unit setHit[_selection,_damage]; //player sidechat str _damage; - _unit setVariable [_strH,_damage,true]; if (_damage == 0) then { [_unit,"repair"] call server_updateObject; } else { diff --git a/SQF/dayz_code/compile/vehicle_getHitpoints.sqf b/SQF/dayz_code/compile/vehicle_getHitpoints.sqf index fcc13959b..c8247d172 100644 --- a/SQF/dayz_code/compile/vehicle_getHitpoints.sqf +++ b/SQF/dayz_code/compile/vehicle_getHitpoints.sqf @@ -1,25 +1,27 @@ -private ["_cfgHitPoints", "_hps", "_funcGetHitPoints"]; +private ["_cfgHitPoints", "_hps"]; _cfgHitPoints = configFile >> "CfgVehicles" >> (typeOf _this) >> "HitPoints"; _hps = []; _funcGetHitPoints = { - for "_i" from 0 to ((count _this) - 1) do + for "_i" from 0 to ((count (_this select 1)) - 1) do { private ["_hp"]; - _hp = configName (_this select _i); + _hp = configName ((_this select 1) select _i); if (!(_hp in _hps)) then { - _hps set [count _hps, _hp]; + _HPCheck = (_this select 0) getHit (getText((_this select 1) >> _hp >> "name")); + if (!isNil "_HPCheck") then { + _hps set [count _hps, _hp]; + }; }; }; }; -//Explore inheritance structure fully while {(configName _cfgHitPoints) != ""} do { - _cfgHitPoints call _funcGetHitPoints; + [_this, _cfgHitPoints] call _funcGetHitPoints; _cfgHitPoints = inheritsFrom _cfgHitPoints; }; diff --git a/SQF/dayz_server/compile/server_updateObject.sqf b/SQF/dayz_server/compile/server_updateObject.sqf index 6a8d975fe..26c3ece24 100644 --- a/SQF/dayz_server/compile/server_updateObject.sqf +++ b/SQF/dayz_server/compile/server_updateObject.sqf @@ -115,24 +115,24 @@ _object_damage = { _damage = damage _object; _array = []; _allFixed = true; - + { _hit = [_object,_x] call object_getHit; - _selection = getText (configFile >> "CfgVehicles" >> _class >> "HitPoints" >> _x >> "name"); - if (_hit > 0) then { + if ((_hit select 0) > 0) then { + _allFixed = false; - _array set [count _array,[_selection,_hit]]; - //diag_log format ["Section Part: %1, Dmg: %2",_selection,_hit]; + _array set [count _array,[(_hit select 1),(_hit select 0)]]; + //diag_log format ["Section Part: %1, Dmg: %2",(_hit select 1),(_hit select 0)]; } else { - _array set [count _array,[_selection,0]]; + _array set [count _array,[(_hit select 1),0]]; }; } forEach _hitpoints; - + if (_allFixed && !_totalDmg) then {_object setDamage 0;}; - - if (_forced) then { + + if (_forced) then { if (_object in needUpdate_objects) then {needUpdate_objects = needUpdate_objects - [_object];}; - _recorddmg = true; + _recorddmg = true; } else { //Prevent damage events for the first 10 seconds of the servers live. if (diag_ticktime - _lastUpdate > 10) then { @@ -143,7 +143,7 @@ _object_damage = { }; }; }; - + if (_recorddmg) then { if (_objectID == "0") then { _key = format["CHILD:306:%1:",_objectUID] + str _array + ":" + str _damage + ":"; @@ -153,8 +153,8 @@ _object_damage = { #ifdef OBJECT_DEBUG diag_log ("HIVE: WRITE: "+ str(_key)); #endif - - _key call server_hiveWrite; + + _key call server_hiveWrite; }; }; diff --git a/SQF/dayz_server/system/server_monitor.sqf b/SQF/dayz_server/system/server_monitor.sqf index 5dd09324b..e9a82f713 100644 --- a/SQF/dayz_server/system/server_monitor.sqf +++ b/SQF/dayz_server/system/server_monitor.sqf @@ -273,9 +273,7 @@ if ((playersNumber west + playersNumber civilian) == 0) exitWith { { _selection = _x select 0; _dam = if (!_isAir && {_selection in dayZ_explosiveParts}) then {(_x select 1) min 0.8;} else {_x select 1;}; - _strH = "hit_" + (_selection); - _object setHit[_selection,_dam]; - _object setVariable [_strH,_dam,true]; + _object setHit [_selection,_dam]; } foreach _hitpoints; [_object,"damage"] call server_updateObject;