[Release] BDC's Zed Vehicle Sound Realism Addon

BDC

Well-Known Member
Howdy all zed and troll hunters,

I wrote this addon a while back. This addon modifies Zombie_FindTargetAgent.SQF by adding two chunks of code (one small, one larger) that makes zed respond to the of a vehicle's engine by either walking over to the area of the sound or directly trying to attack the vehicle if it's occupied. The idea is to add a little bit of "realism". After all, zed hear gunshots; why wouldn't they hear an airplane or a heli?

When I first wrote this, I did real measurements of distances based on a bunch of different vehicles idling. I would run out and check to see how far away I could hear a particular vehicle. In this addon, most if not all of the regular DayZ vehicles are specifically configured. Aside from that, if there's a vehicle that's not DayZ-standard (such as those re-enabled from rMod), they fall within the 'Generic' category. The distance values for the five generic categories are configurable. In this mod, zed will only walk towards vehicle engine noise if they do not currently have any targets they're chasing after.

On to the mod.

Step 1) Modify Init.SQF

Here we modify Init.SQF to add a chunk of code that gives configurable options for this mod. Append the following chunk to the very bottom of the file:

Code:
// Zed respond to vehicle engine noise and loiter/run over mod - modifies zombie_findtargetagent.sqf - ^bdc
dayz_ZedVehicleSoundRealism_Enable = true; // Enable/Disable zed responding to vehicle engine noise
dayz_ZedVehicleSoundRealism_DisAudialMaximumRange = 365; // Maximum range in meters a zed will "hear" a vehicle (defines search parameter)
dayz_ZedVehicleSoundRealism_VeryHeavyRainCorrection = 0.40; // Distance correction factor for very heavy rainfall
dayz_ZedVehicleSoundRealism_HeavyRainCorrection = 0.55; // Distance correction factor for very heavy rainfall
dayz_ZedVehicleSoundRealism_ModerateRainCorrection = 0.70; // Distance correction factor for very heavy rainfall
dayz_ZedVehicleSoundRealism_LightRainCorrection = 0.85; // Distance correction factor for very heavy rainfall
dayz_ZedVehicleSoundRealism_DisAudial_GenericPlane = 355; // Default audible distance for non-specific planes/jets
dayz_ZedVehicleSoundRealism_DisAudial_GenericHeli = 315; // Default audible distance for non-specific helicopters
dayz_ZedVehicleSoundRealism_DisAudial_GenericWheeled = 155; // Default audible distance for all wheeled vehicles (tanks, etc)
dayz_ZedVehicleSoundRealism_DisAudial_GenericCar = 65; // Default audible distance for non-specific cars/trucks
dayz_ZedVehicleSoundRealism_DisAudial_GenericBoat = 75; // Default audible distance for non-specific boats
dayz_ZedVehicleSoundRealism_DisAudial_GrossModifier = 1.00; // Default 1.0; multiplier of final distance value calc'd

A detailed explanation of each configuration variable:

dayz_ZedVehicleSoundRealism_Enable -- This enables or disables this addon. More specifically, it either allows or disallows each zed, while running its own looped function looking for targets, from hearing any vehicles. It provides for a quick way to shut the mod off without having to gut it from script files.

dayz_ZedVehicleSoundRealism_DisAudialMaximumRange -- This is the maximum range in meters that a zed could possibly hear a vehicle. On my server, I have it set to 365. However, it may behoove the server owner to keep in mind that this may have an affect on client PC's FPS. I suspect there may be a performance drop if this is set too high. Also, consider the spawn radius of zed on a vanilla DayZ server doesn't extend too far out past 200m.

dayz_ZedVehicleSoundRealism_VeryHeavyRainCorrection -- Corrections factor for very heavy rainfall. Default is 0.40 which represents a correction of 40% of the calculated distance.

dayz_ZedVehicleSoundRealism_HeavyRainCorrection -- Corrections factor for heavy rain. Default 0.55.

dayz_ZedVehicleSoundRealism_ModerateRainCorrection -- Corrections factor for moderate rainfall. Default is 0.70.

dayz_ZedVehicleSoundRealism_LightRainCorrection -- Corrections factor for light rain/sprinkling. Default is 0.85.

dayz_ZedVehicleSoundRealism_DisAudial_GenericPlane -- The distance, in meters, a zed will hear a non-specific, generic plane.

dayz_ZedVehicleSoundRealism_DisAudial_GenericHeli -- The distance a zed will hear an undefined heli.

dayz_ZedVehicleSoundRealism_DisAudial_GenericWheeled -- Distance zed will hear a generic wheeled/tracked vehicle such as a tank, APC, that sort of thing.

dayz_ZedVehicleSoundRealism_DisAudial_GenericCar -- Distance a zed will hear an unspecified car or truck type.

dayz_ZedVehicleSoundRealism_DisAudial_GenericBoat -- Distance a non-specific boat type will be heard.

dayz_ZedVehicleSoundRealism_DisAudial_GrossModifier -- This is a configurable modifier that multiplies the final sound distance calculation. The default is 1.00 (meaning no re-calc) but if a server operator feels the sounds are too loud or too soft, this is the overall value that can be adjusted. An example: A value of 2.00 would mean that the distance a zed would hear a generic car, configured for let's say 50, would be at 100 meters.

Step 2) Modify Zombie_FindTargetAgent.SQF

There's two sections we're adding to zombie_findtargetagent.sqf. But firstly, the original can be located in \z\dayz_code\compiles folder. Extract it out and place it in a folder within your mission folder (usually MPMissions\dayz_1.xxx).

Towards the top of the file, look for this section:

Code:
if (isNil "_localtargets") then{
    _localtargets = [];
};
if (isNil "_remotetargets") then{
    _remotetargets = [];
};
_targets = _localtargets + _remotetargets;

Our first chunk of code needs to be added below that:

Code:
// Vehicle to zombie sound realism part 1 - ^bdc
// Chance to clear vehicle target from zombie's targets list if engine shut off
if (count _targets > 0) then {
    {
        _obj = _targets select 0;
        if (_obj isKindOf "AllVehicles") then {  
            _isEngineOn = isEngineOn _obj;
            _Chance = random 100;
            if ((_Chance <= 10) and (!_isEngineOn)) then {
                _targets = _targets - [_obj];  // Clear vehicle target if engine off
                _pos = getPOSATL _obj;
                _agent setVariable ["myDest",_pos];
            };
        };
    } forEach _targets;
};

This first part clears the vehicle out of the zed's array (list) of targets when the engine shuts off.

Down a little further in the file, we'll find this part:

Code:
//Check if too far
if (_manDis > _range) then {
    _targets = _targets - [_target];
    _target = objNull;
};

(continued on post 2)
 
(continued from post 1)

Our second chunk that involves the finding and selection of vehicle engine noise goes here. It's a large one. Add it directly below the section above:

Code:
// Vehicle Zombie sound Realism Mod by ^bdc
// Make zombies wander over to nearby vehicles - vehicle type determines range - Works similar to zombies responding to gunfire or flares
// Zombie will either walk or aggro the nearest running vehicle depending upon its distance
if (dayz_ZedVehicleSoundRealism_Enable) then {
    if (count _targets == 0) then { // Do not execute this if zombie already has any targets
      
        // Reset core variables
        _nearestVehicle = 0;
        _nearestMinDis = 0;
        _nearestVehDist = 375;
        _foundRunningVeh = false;
        _pos = getPosATL _agent;
  
        // Grab nearby vehicles defined by dayz_ZedVehicleSoundRealism_DisAudialMaximumRange - init.sqf
        _objects = _pos nearObjects ["AllVehicles",dayz_ZedVehicleSoundRealism_DisAudialMaximumRange];
        {
            // Reset variables
            _foundVeh = _x;
            _SRange = 0;
            _NRange = 0;
            _CorrectionFactor = 0;
            _isEngineOn = false;
            _MinDis = 18; // default
      
            // Grab Generic Vehicle Type
            _isGenericPlane = _foundVeh isKindOf "plane";
            _isGenericHeli = _foundVeh isKindOf "helicopter";
            _isGenericCar = (_foundVeh isKindOf "car" || _foundVeh isKindOf "truck");
            _isGenericBoat = (_foundVeh isKindOf "mediumboat" || _foundVeh isKindOf "smallboat");
            _isGenericWheeled = _foundVeh isKindOf "tank";
      
            // Grab Specific Vehicle Type
            // Bicycle
            _isBike = (_foundVeh isKindOf "Old_bike_TK_INS_EP1" || _foundVeh isKindOf "Old_bike_TK_CIV_EP1");
            // Motorcycles
            _isDirtBike = (_foundVeh isKindOf "M1030" || _foundVeh isKindOf "TT650_TK_CIV_EP1");
            // 4-Wheeler All Terrain Vehicle (ATV)
            _isATV = (_foundVeh isKindOf "ATV_US_EP1" || _foundVeh isKindOf "ATV_CZ_EP1");
            // Aircraft
            _isCargoPlane = _foundVeh isKindOf "AN2_DZ";
            _isChopperLittleBird = (_foundVeh isKindOf "AH6X_DZ" || _foundVeh isKindOf "MH6J_DZ");
            _isChopperMi17 = _foundVeh isKindOf "Mi17_DZ";
            _isChopperHuey = _foundVeh isKindOf "UH1H_DZ";
            // Trucks/Jeeps
            _isTruckOffroadMil = (_foundVeh isKindOf "BAF_Offroad_D" || _foundVeh isKindOf "BAF_Offroad_W" || _foundVeh isKindOf "Landrover_CZ_EP1");
            _isTruckOffroad = (_foundVeh isKindOf "hilux1_civil_3_open" || _foundVeh isKindOf "hilux1_civil_3_open_EP1");
            _isTruckDatsun = (_foundVeh isKindOf "datsun1_civil_3_open" || _foundVeh isKindOf "datsun1_civil_1_open");
            _isTruckLarge = (_foundVeh isKindOf "UralCivil" || _foundVeh isKindOf "UralCivil2" || _foundVeh isKindOf "V3S_Civ");
            _isJeepMil = _foundVeh isKindOf "UAZ_Unarmed_TK_EP1";
            // Cars/SUV/Bus/Van
            _isVan = _foundVeh isKindOf "S1203_TK_CIV_EP1";
            _isSUV = _foundVeh isKindOf "SUV_TK_EP1";
            _isCar = (_foundVeh isKindOf "car_sedan" || _foundVeh isKindOf "car_hatchback" || _foundVeh isKindOf "Lada1_TK_CIV_EP1" || _foundVeh isKindOf "Lada2" || _foundVeh isKindOf "Skoda" || _foundVeh isKindOf "SkodaGreen" || _foundVeh isKindOf "SkodaBlue" || _foundVeh isKindOf "VohlaLimo_TK_CIV_EP1" || _foundVeh isKindOf "Vohla_2_TK_Civ_EP1");
            _isBus = _foundVeh isKindOf "Ikarus";
            // Tractor
            _isTractor = _foundVeh isKindOf "Tractor";
            // Boats
            _isLifeBoat = _foundVeh isKindOf "PBX";
            _isBoat = _foundVeh isKindOf "Fishing_Boat";
          
            // Gather audible range depending upon vehicle type
            // Generic
            if (_isGenericPlane) then { _SRange = dayz_ZedVehicleSoundRealism_DisAudial_GenericPlane; };
            if (_isGenericHeli) then { _SRange = dayz_ZedVehicleSoundRealism_DisAudial_GenericHeli; };
            if (_isGenericCar) then { _SRange = dayz_ZedVehicleSoundRealism_DisAudial_GenericCar; };
            if (_isGenericBoat) then { _SRange = dayz_ZedVehicleSoundRealism_DisAudial_GenericBoat; };
            if (_isGenericWheeled) then { _SRange = dayz_ZedVehicleSoundRealism_DisAudial_GenericWheeled; };
      
            // Specific (if valid)
            if (_isDirtBike) then { _SRange = 35; };
            if (_isATV or _isLifeBoat) then { _SRange = 45; };
            if (_isCargoPlane) then { _SRange = 355; };
            if (_isChopperLittleBird) then { _SRange = 285; };
            if (_isChopperHuey) then { _SRange = 315; };
            if (_isChopperMi17) then { _SRange = 365; };
            if (_isTruckOffroadMil or _isJeepMil) then { _SRange = 65; };
            if (_isTruckDatsun or _isBus) then { _SRange = 50; };
            if (_isTruckOffroad) then { _SRange = 70; };
            if (_isTruckLarge or _isCar or _isBoat or _isTractor) then { _SRange = 80; };
            if (_isCar or _isVan) then { _SRange = 60; };
            if (_isSUV) then { _SRange = 30; };
            _NRange = _SRange;
      
            // Corrections for rain sound dampening
            _RainAmt = drn_var_DynamicWeather_Rain; // referenced from \z\addons\dayz_code\system\DynamicWeatherEffects.sqf
            if (_RainAmt > 0) then {
                if (_RainAmt > 0.72) then { // very heavy rain
                    _CorrectionFactor = dayz_ZedVehicleSoundRealism_VeryHeavyRainCorrection; };  // 40%          
                if (_RainAmt > 0.53) then { // heavy rain
                    _CorrectionFactor = dayz_ZedVehicleSoundRealism_HeavyRainCorrection; };  // 55%          
                if (_RainAmt > 0.25) then { // medium rain
                    _CorrectionFactor = dayz_ZedVehicleSoundRealism_ModerateRainCorrection; };  // 70%          
                if (_RainAmt <= 0.25) then { // light rain
                    _CorrectionFactor = dayz_ZedVehicleSoundRealism_LightRainCorrection; };  // 85%          
                _NRange = (_SRange * _CorrectionFactor);
            };
          
            // Correction for vehicle idling/low speeds vs higher speeds for lower audible range for non-air vehicles
            if (!_isChopperLittleBird or !_isChopperHuey or !_isChopperMi17 or !_isCargoPlane or !_isGenericPlane or !_isGenericHeli) then {
                _vel = velocity (_foundveh);
                _speed = (_vel distance [0,0,0]);
                if (_speed <= 15) then { // 15kph; presumably idling
                    _NRange = (_NRange * 0.75); // 75% the audible distance
                };
            };
          
            // Gross multiplier
            _NRange = (_NRange * dayz_ZedVehicleSoundRealism_DisAudial_GrossModifier);
          
            if (!_isBike) then {
                _isEngineOn = isEngineOn _foundVeh;
            };
            if (_isEngineOn and !_isBike and (_NRange > 0)) then { // Is the engine on and valid vehicle?
                _disToVehicle = _foundVeh distance _agent; // distance from vehicle to zombie
          
                // Gather minimum aggro distances
                if (_NRange < 100) then { // covers all ground vehicles
                    if (_NRange < 50) then {
                        _MinDis = 18;          
                    } else {
                        _MinDis = 30;
                    };
                };
                if (_NRange >= 100) then { // all choppers and cargo plane
                    _MinDis = (_NRange * 0.22);
                };
              
                // Now that we have our vehicle and sound variables, check if zombie can hear it
                if ((_NRange > 0) and (_disToVehicle < _NRange)) then { // Does the zombie hear it?
                    if (_disToVehicle < _nearestVehDist) then { // Is it closer than the closest one we've found so far?
                        // Set our walking/aggro vehicle target to this one
                        _nearestVehDist = _disToVehicle;
                        _nearestMinDis = _MinDis;
                        _nearestVehicle = _foundVeh;
                        _foundRunningVeh = true;
                    };
                };
              
            };
        } forEach _objects;
      
        // If we found a vehicle with engine running we (zombie) can hear, then determine if we
        // merely walk to it or if we aggro it and go for it
        if (_foundRunningVeh) then {
            if (_nearestVehDist > _nearestMinDis) then { // no aggro; we walk to it
                _VehPos = getPOSATL _nearestVehicle;
                _agent setVariable ["myDest",_VehPos];
            } else { // within visual aggro range - chase it
                _targets set [count _targets, _nearestVehicle];
                _agent setVariable ["localtargets",_localtargets, true]; // ^^
                _agent setVariable ["remotetargets",_remotetargets, true]; // ^^
                _target = _nearestVehicle;
            };
        };
    };
};

(continued on post 3)
 
(continued from post 2)

The only thing left below this should be one line that says "_target" as it's basically the end of the file.

Step 3) Modify Compiles.SQF

To point to the newly modified zombie_findtargetagent.sqf file, we need to modify the compiles.sqf file. On or around line 58 or so, we'll find this entry:

Code:
zombie_findTargetAgent = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\zombie_findTargetAgent.sqf";

Let's comment that sucker out and add a new line to point it to our modified file. Here's what it should look like (or something like):

Code:
//zombie_findTargetAgent = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\zombie_findTargetAgent.sqf";
        zombie_findTargetAgent = compile preprocessFileLineNumbers "scripts\compiles\zombie_findTargetAgent.sqf"; // modified ^bdc

Make sure the scripts\compiles path in here reflects where your modified zombie_findtargetagent.sqf file resides
.

B
 
Back
Top