From 93ba732e84e0ce05c9cd54197e9d01797d463d9e Mon Sep 17 00:00:00 2001 From: A Man Date: Mon, 27 Apr 2020 18:33:37 +0200 Subject: [PATCH] Update zombie alerting - zombie will be triggered by chemlights only at night now --- SQF/dayz_code/compile/player_alertZombies.sqf | 75 +++++-------------- SQF/dayz_code/compile/player_fired.sqf | 26 +++---- SQF/dayz_code/compile/player_throwObject.sqf | 18 +++-- .../compile/zombie_findTargetAgent.sqf | 26 +++---- 4 files changed, 50 insertions(+), 95 deletions(-) diff --git a/SQF/dayz_code/compile/player_alertZombies.sqf b/SQF/dayz_code/compile/player_alertZombies.sqf index f3a215514..8a222e24e 100644 --- a/SQF/dayz_code/compile/player_alertZombies.sqf +++ b/SQF/dayz_code/compile/player_alertZombies.sqf @@ -1,4 +1,4 @@ -private ["_unit","_distance","_doRun","_pos","_listTalk","_zombie"]; +private ["_unit","_distance","_doRun","_pos","_listTalk","_zombie","_50","_localtargets","_remotetargets","_targets","_dis"]; _unit = _this select 0; _distance = _this select 1; @@ -6,43 +6,32 @@ _doRun = _this select 2; _pos = _this select 3; _listTalk = _pos nearEntities ["zZombie_Base",_distance]; -_inVehicle = (vehicle _unit != _unit); -_isAir = vehicle player iskindof "Air"; -_isLand = vehicle player iskindof "Land"; -_isSea = vehicle player iskindof "Sea"; -_speed = speed (vehicle _unit); { -private["_localtargets","_remotetargets","_targets","_dis"]; - _distance = _distance max floor(_distance*.9); - _dis = _x distance _unit; _zombie = _x; - - switch (true) do { - case (_dis < 51): { + + call { + if (_dis < 51) exitwith { if (_doRun) then { _localtargets = _x getVariable ["localtargets",[]]; _remotetargets = _x getVariable ["remotetargets",[]]; _targets = _localtargets + _remotetargets; if (!(_unit in _targets)) then { - switch (local _x) do { - case false: { - _remotetargets set [count _remotetargets,_unit]; - _x setVariable ["remotetargets",_remotetargets,true]; - }; - case true: { - _localtargets set [count _localtargets,_unit]; - _x setVariable ["localtargets",_localtargets,false]; - }; + if !(local _x) then { + _remotetargets set [count _remotetargets,_unit]; + _x setVariable ["remotetargets",_remotetargets,true]; + } else { + _localtargets set [count _localtargets,_unit]; + _x setVariable ["localtargets",_localtargets,false]; }; }; } else { _zombie setVariable ["myDest",_pos,true]; }; }; - case ((_dis > 50) and (_dis <= 71)): { + if ((_dis > 50) && {_dis <= 71}) exitwith { _50 = round(random 100); if (_50 < 50) then { if (_doRun) then { @@ -50,15 +39,12 @@ private["_localtargets","_remotetargets","_targets","_dis"]; _remotetargets = _x getVariable ["remotetargets",[]]; _targets = _localtargets + _remotetargets; if (!(_unit in _targets)) then { - switch (local _x) do { - case false: { - _remotetargets set [count _remotetargets,_unit]; - _x setVariable ["remotetargets",_remotetargets,true]; - }; - case true: { - _localtargets set [count _localtargets,_unit]; - _x setVariable ["localtargets",_localtargets,false]; - }; + if !(local _x) then { + _remotetargets set [count _remotetargets,_unit]; + _x setVariable ["remotetargets",_remotetargets,true]; + } else { + _localtargets set [count _localtargets,_unit]; + _x setVariable ["localtargets",_localtargets,false]; }; }; } else { @@ -68,31 +54,8 @@ private["_localtargets","_remotetargets","_targets","_dis"]; _zombie setVariable ["myDest",_pos,true]; }; }; - case (_dis > 70): { + if (_dis > 70) exitwith { _zombie setVariable ["myDest",_pos,true]; }; }; - -/* - _zombie = _x; - if (_doRun) then { - _localtargets = _x getVariable ["localtargets",[]]; - _remotetargets = _x getVariable ["remotetargets",[]]; - _targets = _localtargets + _remotetargets; - if (!(_unit in _targets)) then { - switch (local _x) do { - case false: { - _remotetargets set [count _remotetargets,_unit]; - _x setVariable ["remotetargets",_remotetargets,true]; - }; - case true: { - _localtargets set [count _localtargets,_unit]; - _x setVariable ["localtargets",_localtargets,false]; - }; - }; - }; - } else { - _zombie setVariable ["myDest",_pos,true]; - }; -*/ -} forEach _listTalk; \ No newline at end of file +} count _listTalk; diff --git a/SQF/dayz_code/compile/player_fired.sqf b/SQF/dayz_code/compile/player_fired.sqf index e68855737..e7d592017 100644 --- a/SQF/dayz_code/compile/player_fired.sqf +++ b/SQF/dayz_code/compile/player_fired.sqf @@ -9,7 +9,7 @@ _projectile = _this select 6; //Alert Nearby _audible = getNumber (configFile >> "CfgAmmo" >> _ammo >> "audibleFire"); _caliber = getNumber (configFile >> "CfgAmmo" >> _ammo >> "caliber"); -_distance = round(_audible * 10 * _caliber); +_distance = round(_audible * 20 * _caliber); dayz_disAudial = _distance; dayz_firedCooldown = time; @@ -24,11 +24,12 @@ if (_ammo isKindOf "Melee") exitWith { _this call player_harvest; // harvest wood check }; -if ((_ammo isKindOf "SmokeShell") or (_ammo isKindOf "GrenadeHandTimedWest") or (_ammo isKindOf "G_40mm_HE")) then { +if ((_ammo isKindOf "SmokeShell") || {_ammo isKindOf "GrenadeHandTimedWest"} || {_ammo isKindOf "G_40mm_HE"}) then { if (_ammo isKindOf "G_40mm_HE") then { dayz_disAudial = 30 }; [_unit,_ammo] spawn { - private ["_pos","_group","_localtargets","_remotetargets"]; + private ["_pos","_group","_localtargets","_remotetargets","_unit","_ammo","_projectile","_isLocal","_targets"]; + _unit = _this select 0; _ammo = _this select 1; @@ -52,18 +53,15 @@ if ((_ammo isKindOf "SmokeShell") or (_ammo isKindOf "GrenadeHandTimedWest") or _remotetargets = _group getVariable ["remotetargets",[]]; _targets = _localtargets + _remotetargets; if !(_projectile in _targets) then { - switch (_isLocal) do { - case false: { - _remotetargets set [count _remotetargets,_projectile]; - _x setVariable ["remotetargets",_remotetargets,true]; - }; - case true: { - _localtargets set [count _localtargets,_projectile]; - _x setVariable ["localtargets",_localtargets,false]; - }; + if (!_isLocal) then { + _remotetargets set [count _remotetargets,_projectile]; + _x setVariable ["remotetargets",_remotetargets,true]; + } else { + _localtargets set [count _localtargets,_projectile]; + _x setVariable ["localtargets",_localtargets,false]; }; }; - } forEach (_pos nearEntities ["zZombie_Base",50]); + } count (_pos nearEntities ["zZombie_Base",50]); } else { while {alive _projectile} do { _pos = getPosATL _projectile; @@ -100,7 +98,7 @@ if ((_ammo isKindOf "SmokeShell") or (_ammo isKindOf "GrenadeHandTimedWest") or publicVariable "PVDZ_obj_RoadFlare"; [_this] spawn player_throwObject; }; - + //Auto select main weapon after throwing call player_selectWeapon; }; diff --git a/SQF/dayz_code/compile/player_throwObject.sqf b/SQF/dayz_code/compile/player_throwObject.sqf index 116e85f00..c699b8414 100644 --- a/SQF/dayz_code/compile/player_throwObject.sqf +++ b/SQF/dayz_code/compile/player_throwObject.sqf @@ -1,31 +1,33 @@ -private ["_distance","_endPos","_doWait","_vel"]; +if (isNil "dayz_sunRise") exitwith {}; + +private ["_distance","_endPos","_doWait","_vel","_obj","_unit","_ammo","_projectile"]; + _obj = _this select 0; _unit = _obj select 0; -//_weapon = _obj select 1; _ammo = _obj select 4; _projectile = _obj select 6; -waituntil {!isNil "dayz_sunRise"}; - _projectile = nearestObject [_unit,_ammo]; _endPos = getPosATL _projectile; - _doWait = true; + while {_doWait} do { _vel = (velocity _projectile) distance [0,0,0]; if !(alive _projectile) then {_doWait = false}; - if (_vel < 0.1) then {_doWait = false}; + if (_vel < 0.2) then {_doWait = false}; _endPos = getPosATL _projectile; uiSleep 0.01; }; _distance = parseNumber format["%1",(getArray (configFile >> "CfgAmmo" >> _ammo >> "soundHit") select 3)]; -if (_ammo isKindOf "ChemLight") then { +if (_ammo isKindOf "ChemLight" && {daytime > 18 || daytime < 7}) exitwith { _distance = 10; + [_unit,_distance,false,_endPos] call player_alertZombies; }; + if (_ammo isKindOf "RoadFlare") then { - _distance = if ((daytime < (24 - dayz_sunRise)) && (daytime > dayz_sunRise)) then {30} else {60}; + _distance = [60,30] select ((daytime < (24 - dayz_sunRise)) && {daytime > dayz_sunRise}) }; [_unit,_distance,false,_endPos] call player_alertZombies; diff --git a/SQF/dayz_code/compile/zombie_findTargetAgent.sqf b/SQF/dayz_code/compile/zombie_findTargetAgent.sqf index 1e58d5c23..82aa5a8bf 100644 --- a/SQF/dayz_code/compile/zombie_findTargetAgent.sqf +++ b/SQF/dayz_code/compile/zombie_findTargetAgent.sqf @@ -1,32 +1,24 @@ private ["_agent","_range","_target","_targets","_man","_manDis","_localtargets","_remotetargets"]; + _agent = _this; + if (isNull _agent) exitWith {objNull}; // Prevent errors if zombie is suddenly deleted + _target = objNull; _targets = []; -//_targetDis = []; _range = 100; _manDis = 0; - _localtargets = _agent getVariable ["localtargets",[]]; _remotetargets = _agent getVariable ["remotetargets",[]]; - -if (isNil "_localtargets") then{ - _localtargets = []; -}; -if (isNil "_remotetargets") then{ - _remotetargets = []; -}; _targets = _localtargets + _remotetargets; //diag_log ("Targets: " +str(_targets)); -//if (isNil "_targets") exitWith {}; - //Search for objects if (count _targets == 0) then { -//"ThrownObjects","GrenadeHandTimedWest","SmokeShell"] - private["_objects"]; - _objects = _agent nearObjects ["GrenadeHand", 300]; + private "_objects"; + + _objects = _agent nearObjects ["GrenadeHand", 300]; //"ThrownObjects","GrenadeHandTimedWest","SmokeShell"] { if (!(_x in _targets)) then { if (local _x) then { @@ -35,7 +27,7 @@ if (count _targets == 0) then { _remotetargets set [count _remotetargets,_x]; }; }; - } foreach _objects; + } count _objects; }; //Find best target @@ -44,7 +36,7 @@ if (count _targets > 0) then { _manDis = _man distance _agent; //diag_log (str(_man) + str(_manDis)); { - private["_dis"]; + private "_dis"; _dis = _x distance _agent; if (_dis < _manDis) then { _man = _x; @@ -54,7 +46,7 @@ if (count _targets > 0) then { _man = _x; _manDis = _dis; }; - } forEach _targets; + } count _targets; _target = _man; };