[Release] BDC's Prevent Loot and Zed Spawn (Safe Zones) for 1.8.0.3

BDC

Well-Known Member
Updated March 30, 2014:

Fix of destroyed building bug: Basically, destroyed buildings, even while in the no zed spawn marker area, were still producing zed spawn. I tracked it down to (I believe) Arma moving the original building position well down into a negative Z coordinate (underneath the terrain level) which would sometimes place the building outside of the spherical marker. The code updated is the portion within the player_spawnCheck.SQF file below to re-orient the Z coordinate to check at 0 meter elevation.

I've also removed the reference to building_spawnzombies.SQF as it's redundant and not needed. Player_spawnCheck.SQF handles everything up front.

------------------------------------------------------------------------------------------------------

Howdy guys,

I've been active in writing scripts for my server for the past few months now. As the server grows, and as our co-op community on it grows and builds its resources, I finally gave in to the cries of my buddies about making certain spots free of zed spawn. It was probably the number one thing I had requested for implementing. So a couple days ago I looked around at some and while I found some great attempts at combating this issue, I didn't feel they hit the target as closely as they could. So I decided to try my hand at writing my own and, surprising, for the first time, I actually had a script that worked the first time without bugs! Imagine that.

Anyways, the modifications done here are intended to keep both Zed AND Loot from spawning in a radius around a given position. I've included the ability to exclude loot from the no-spawn role but by default both loot and spawn are disabled.

The server I've done this on is a pwnzor0z's setup but I believe it'll work on anything.

On to the mod!

Step 1) Get to Variables.SQF

First thing that needs to be done is getting access to variables.sqf. It's located in \dayz_code\init folder and needs to be extracted out to wherrever (I put it in my \dayzserver\MPMissions\dayz1.Chernarus mission folder. From there, you need to modify the init.SQF file to point to the new variables.SQF file.

For those unfamiliar with extracting from dayz_code, there are a zillion threads on here that explain it. It's the first thing and most common thing that's done on nearly every addon or mod done in DayZ.

Step 2) Modify Variables.SQF

There is no real actual place to put this extra code so I picked a spot below "// Action Blockers" (which is around line 230 or so). For ease of configuration, I decided to make this into three global arrays rather than one since it can get awful long and have a lot of numbers:

Code:
//Prevent zed from spawning in specific spots according to position - Used in player_spawncheck.sqf and building_spawnzombies.sqf - ^bdc
PreventZedSpawnPositions = [[6898,11446,0],[5145,2328,0]];
// Devil's Castle 75m, Balota airfield E end of runway (75m)
// Marker positions in X, Y, and Z coordinates; can be derived from Object or Character entries in dBase
PreventZedSpawnDistances = [75,50];
// Radius (in meters) of zed/loot no-spawn markers relative to position in above array
PreventZedSpawnLootInclusions = [true,false];
// Include no-spawning of loot at given position within defined radius (default true per element)

The above example is given with two positions already included which are at the center of Devil's Castle and at the southeastern end of the Balota airfield where the two white hangar buildings are. In this example, both locations prevent zed spawn but only Devil's Castle allows for loot while Balota does not (the true,false flags in PreventZedSpawnLootInclusions). The PreventZedSpawnDistances are the distances away from the center position point given where zed (and possibly loot) won't spawn.

Step 3) Continuing on to Player_SpawnCheck.SQF

Player_Spawncheck.SQF can be found in \dayz_code\compile folder. Extract it out to your MP missions folder (\fixes,\scripts, or whatever) and reference it within compiles.sqf as the one to be read (on or around line 20):

Code:
//player_spawnCheck = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\player_spawnCheck.sqf";
player_spawnCheck = compile preprocessFileLineNumbers "fixes\compiles\player_spawnCheck.sqf"; // Modified for vehicle loot/zed spawn by ^bdc

Comment out the initial line and add the latter. On my server, player_spawnCheck.SQF is located in \dayzserver\MPMissions\dayz1.Chernarus\fixes\scripts folder as a reference.

Modify Player_SpawnCheck.SQF - On or around line 80 or 90 or so, we'll find this chunk of code:

Code:
_type = typeOf _x;
    //_config = configFile >> "CfgBuildingLoot" >> _type;
    _config = missionConfigFile >> "CfgBuildingLoot" >> _type;
    _canSpawn = isClass (_config);
    _dis = _x distance player;
    _checkLoot = ((count (getArray (_config >> "lootPos"))) > 0);
    _islocal = _x getVariable ["", false]; // object created locally via TownGenerator. See stream_locationFill.sqf
 
    //Make sure wrecks always spawn Zeds
    //_isWreck = _x isKindOf "SpawnableWreck";
    //if (_isWreck) then { _force = true; };

Add this chunk below it:

Code:
// If given area flagged as false, then include loot spawn as restricted spawn along with zed - ^bdc
    _xpos = getPosATL _x;
    // Change Z coordinate to 0 as workaround destroyed building bug - ^bdc
    _newpos = [(_xpos select 0),(_xpos select 1),0];
    if (count PreventZedSpawnPositions > 0) then { // variables.sqf
        _count = count PreventZedSpawnPositions;
        for "_y" from 0 to _count do {
            _NoSpawnPos = PreventZedSpawnPositions select _y;
            _NoSpawnDis = PreventZedSpawnDistances select _y;
            _NoSpawnLoot = PreventZedSpawnLootInclusions select _y;
            _SpawnDis = _NoSpawnPos distance _newpos;
            if ((_SpawnDis <= _NoSpawnDis) and (_NoSpawnLoot)) then {
                _canSpawn = false; // skips entire loot/zed spawn routine below
                //diag_log format["Player_spawnCheck: NoSpawnLoot is %5; Prevent pos %1, Bldg pos %2, distance %3, NoSpawnDis %4",_NoSpawnPos,_newpos,_SpawnDis,_NoSpawnDis,_NoSpawnLoot];
            };
        };
    };

This portion, if the safe zone area we're looking at also includes no loot spawning, will cancel the rest of the entire script from running basically.

Now, scroll down further to about line 150-160 or so. We'll find this line:

Code:
//if (_dis > _spawnZedRadius) then {

First thing: Comment this line out and replace it with this:

Code:
if ((_dis > _spawnZedRadius) and (!_NoSpawnZed)) then {

Notice I've added a second variable to check. This specific to keeping zed from spawning although in this safe zone instance we're keeping loot open.

Directly above the "//if (_dis > _spawnZedRadius) then {" commented-out line, we need to add this chunk of code (it will be below the "//Zeds" comment):

Code:
// Check to see if zed are restricted in this area or not - ^bdc
    _NoSpawnZed = false;
    _xpos = getPosATL _x;
    // Change Z coordinate to 0 as workaround destroyed building bug - ^bdc
    _newpos = [(_xpos select 0),(_xpos select 1),0];
    if (count PreventZedSpawnPositions > 0) then { // variables.sqf
        _count = (count PreventZedSpawnPositions - 1);
        for "_y" from 0 to _count do {
            _NoSpawnPos = PreventZedSpawnPositions select _y;
            _NoSpawnDis = PreventZedSpawnDistances select _y;
            _SpawnDis = _NoSpawnPos distance _newpos;
            //diag_log format["Player_spawnCheck: NoSpawnZed currently is %5; Prevent pos %1, Bldg pos %2, distance %3, NoSpawnDis %4 PreventZedSpawnPositions Count %6",_NoSpawnPos,_newpos,_SpawnDis,_NoSpawnDis,_NoSpawnZed,_count];
            if (_SpawnDis <= _NoSpawnDis) then {
                _NoSpawnZed = true;
                //diag_log format["Player_spawnCheck: NoSpawn is true; Prevent pos %1, Bldg pos %2, distance %3, NoSpawnDis %4",_NoSpawnPos,_newpos,_SpawnDis,_NoSpawnDis];
            };
        };
    };

Player_SpawnCheck.SQF is now finished.

Step 4) We're done!

Some may think this is redundant in that I'm modifying a second file called from the first but the procedure does work and it doesn't load out the client machine that's performing this function.

If anyone needs help with this, the help thread will be located here:
http://www.opendayz.net/threads/help-bdcs-prevent-loot-and-zed-spawn-safe-zones-for-1-8-0-3.14703/

Hope everyone enjoys it! We're using it on our server with great success. It's helped quite a bit.

B
 
Last edited:
Wanted to add an example of the no zed (and/or loot) spawn markers as configured on my Taviana server to better show how this modification works. Also, this code can be placed in init.sqf for more simplicity's sake if getting to and wading through variables.sqf turns out to be a pain:

Code:
// NoZed/NoLoot Spawn Markers - ^bdc mod
// Marker positions in X, Y, and Z coordinates; can be derived from Object or Character entries in dBase
// Airport Dubovo (4x spots) South side, RU Mil Barracks/Fortify area, Prison Island, RU Mil Base (Jaroslavski Airport, 5 spots)
// Bandits at Stangrad
PreventZedSpawnPositions = [[16700,10555],[16700,10455],[16700,10355],[16700,10235],[16446,14295],[11900, 21000],[10237,18588],[10282,18490],[10337,18392],[9983,18893],[10156,18724.2],[3350,7550],[3625,7650],[3350,7850],[3450,7850],[3250,8050],[6957.70, 8342.15]];
// Radius (in meters) of zed/loot no-spawn markers relative to position in above array
PreventZedSpawnDistances = [150,150,150,150,150,200,65,65,125,125,150,275,100,150,150,175,150];
// Include no-spawning of loot at given position within defined radius (default true per element)
PreventZedSpawnLootInclusions = [true,true,true,true,false,false,false,false,false,false,false,false,false,false,false,false,true];
 
Back
Top