From effb78fe1319c902380764ec217258df65435c0e Mon Sep 17 00:00:00 2001 From: A Man Date: Thu, 5 May 2022 17:58:09 +0200 Subject: [PATCH] Add new combat function --- SQF/dayz_code/compile/fn_setCombat.sqf | 12 ++++++++++++ SQF/dayz_code/init/compiles.sqf | 2 +- SQF/dayz_code/system/BIS_Effects/fired.sqf | 9 ++------- SQF/dayz_code/system/player_spawn_2.sqf | 8 +------- .../system/scheduler/sched_playerActions.sqf | 2 +- 5 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 SQF/dayz_code/compile/fn_setCombat.sqf diff --git a/SQF/dayz_code/compile/fn_setCombat.sqf b/SQF/dayz_code/compile/fn_setCombat.sqf new file mode 100644 index 000000000..32c8d5a26 --- /dev/null +++ b/SQF/dayz_code/compile/fn_setCombat.sqf @@ -0,0 +1,12 @@ +local _object = _this select 0; +local _setCombatOverTime = _this select 1; + +if (_setCombatOverTime) then { + _object setVariable["combattimeout", diag_tickTime + DZE_CombatTimer]; +} else { + _object setVariable["startcombattimer", 1]; +}; + +if !(_object getVariable ["inCombat",false]) then { + _object setVariable ["inCombat",true,true]; +}; \ No newline at end of file diff --git a/SQF/dayz_code/init/compiles.sqf b/SQF/dayz_code/init/compiles.sqf index 08391ccef..dcda08a07 100644 --- a/SQF/dayz_code/init/compiles.sqf +++ b/SQF/dayz_code/init/compiles.sqf @@ -748,6 +748,7 @@ if (!isDedicated) then { DZ_KeyDown_EH = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\keyboard.sqf"; dayz_EjectPlayer = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\dze_ejectPlayer.sqf"; fnc_isInsideBuilding = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_isInsideBuilding.sqf"; //_isInside = [_unit,_building] call fnc_isInsideBuilding; + fnc_setCombat = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_setCombat.sqf"; }; //Both @@ -781,7 +782,6 @@ local_zombieDamage = compile preprocessFileLineNumbers "\z\addons\dayz_code\comp local_setFuel = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\local_setFuel.sqf"; //Generated when someone refuels a vehicle local_eventKill = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\local_eventKill.sqf"; //Generated when something is killed player_humanityChange = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_humanityChange.sqf"; //New -player_projectileNear = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_projectileNear.sqf"; player_bloodCalc = compile preprocessFileLineNumbers "\z\addons\dayz_code\medical\bloodCalc.sqf"; fn_selectRandomLocation = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_selectRandomLocation.sqf"; fn_addCargo = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_addCargo.sqf"; diff --git a/SQF/dayz_code/system/BIS_Effects/fired.sqf b/SQF/dayz_code/system/BIS_Effects/fired.sqf index fe8bd1954..6977c2d1d 100644 --- a/SQF/dayz_code/system/BIS_Effects/fired.sqf +++ b/SQF/dayz_code/system/BIS_Effects/fired.sqf @@ -1,13 +1,8 @@ if !(isDedicated) then { - private "_amm"; - - _amm = _this select 4; + local _amm = _this select 4; _this call (call compile GetText (configFile >> "CfgAmmo" >> _amm >> "muzzleEffect")); //Handle combat in vehicle if (player in (crew (_this select 0))) then { - if !(player getVariable ["inCombat",false]) then { - player setVariable ["inCombat",true,true]; - }; - player setVariable["combattimeout", diag_tickTime + 30, false]; + [player,true] call fnc_setCombat; }; }; diff --git a/SQF/dayz_code/system/player_spawn_2.sqf b/SQF/dayz_code/system/player_spawn_2.sqf index a0aa8f937..e94496961 100644 --- a/SQF/dayz_code/system/player_spawn_2.sqf +++ b/SQF/dayz_code/system/player_spawn_2.sqf @@ -14,11 +14,6 @@ _timer150 = diag_ticktime; player setVariable ["temperature",dayz_temperatur,true]; player setVariable["friendlies",DZE_Friends,true]; -//[0,0] call player_humanityChange; - -//player addMagazine "Hatchet_swing"; -//player addWeapon "MeleeHatchet"; - while {1 == 1} do { //_start = diag_tickTime; @@ -281,8 +276,7 @@ while {1 == 1} do { _startcombattimer = player getVariable["startcombattimer", 0]; if (_startcombattimer == 1) then { //Do not use _PlayerNearby it makes building impossible, this is handled in player_onPause.sqf just fine - player setVariable["combattimeout", diag_tickTime + 30, false]; - if !(player getVariable["inCombat",false]) then {player setVariable["inCombat",true,true];}; + [player,true] call fnc_setCombat; player setVariable["startcombattimer", 0, false]; }; diff --git a/SQF/dayz_code/system/scheduler/sched_playerActions.sqf b/SQF/dayz_code/system/scheduler/sched_playerActions.sqf index 807ac01e3..6552778d5 100644 --- a/SQF/dayz_code/system/scheduler/sched_playerActions.sqf +++ b/SQF/dayz_code/system/scheduler/sched_playerActions.sqf @@ -9,7 +9,7 @@ sched_playerActions = { }; //combat check - if ((player getVariable ["combattimeout",0] < diag_tickTime) && {player getVariable ["inCombat",false]}) then { + if ((player getVariable ["combattimeout",0] < diag_tickTime) && {player getVariable ["inCombat",false]} && {player getVariable["startcombattimer", 0] == 0}) then { player setVariable ["inCombat", false, true]; };