Zombie/Loot spawn simple (for you experts) scripting assistance needed

joikd

Well-Known Member
Vanilla DayZ spawns x amount of zombies for EACH player within a certain distance of a spawnable building. So, if the building was set to spawn one zombie, if three players closed within the spawning distance of the building, three zombies would spawn. I hate any kind of difficulty scaling, and would like to remove this. It appears that adding an additional check would do this. I was thinking that if the check found more than one player within spawning distance of that building, it would not spawn zombies or loot. This would fit perfectly with my goals of eliminating loot farming, having many more zombies, and allowing a location to be "cleared" of zombies for an extended period of time.

From what my very unqualified understanding tells me of player_spawnCheck.sqf in dayz_code\compile, vanilla DayZ combines the initial check for spawning loot and zombies by checking if the player is within 200 of any "building":
Code:
_nearby = _position nearObjects ["building",200];

Now, if there are any _nearby, I want to add a count to determine how many alive players are within 200 of that "building" (my true purpose is to discover if more than 1 alive player is within 200 of the "building"). If there is more than one player within 200 of the _nearby, don't run the spawning code (maybe an if/then that stops it).

Any help would be greatly appreciated!

Here is the entire player_spawnCheck.sqf"

Code:
_isAir = vehicle player iskindof "Air";
_inVehicle = (vehicle player != player);
_fastRun = _this select 0;
_dateNow = (DateToNumber date);
_age = -1;
if (!_inVehicle) then {
	_position = getPosATL player;
	//waitUntil{_position nearObjectsReady 200};
	_nearby = _position nearObjects ["building",200]; //nearestObjects [player, ["building"], 200];
	_tooManyZs = {alive _x} count (_position nearEntities ["zZombie_Base",400]) > dayz_maxLocalZombies;
	{
		_type = typeOf _x;
		_config = 		configFile >> "CfgBuildingLoot" >> _type;
		_canLoot = 		isClass (_config);		
		if (_canLoot) then {			
			_dis = _x distance player;
			if ((_dis < 120) and (_dis > 30)) then {
				_looted = (_x getVariable ["looted",-0.1]);
				_cleared = (_x getVariable ["cleared",true]);
				/*
				if(isServer) then {
					_dateNow = (DateToNumber date);
					_age = (_dateNow - _looted) * 525948;
				} else {
					_dateNow = serverTime;
					_age = (_dateNow * 60) - _looted;
				};
				*/
				_dateNow = (DateToNumber date);
				_age = (_dateNow - _looted) * 525948;
				//diag_log ("SPAWN LOOT: " + _type + " Building is " + str(_age) + " old" );
				if ((_age > 10) and (!_cleared) and !_inVehicle) then {
					_nearByObj = nearestObjects [(getPosATL _x), ["WeaponHolder","WeaponHolderBase"],((sizeOf _type)+5)];
					{deleteVehicle _x} forEach _nearByObj;
					_x setVariable ["cleared",true,true];
					_x setVariable ["looted",_dateNow,true];
				};
				if ((_age > 10) and (_cleared) and !_inVehicle) then {
					//Register
					_x setVariable ["looted",_dateNow,true];
					//cleanup
					_handle = [_x,_fastRun] spawn building_spawnLoot;
					waitUntil{scriptDone _handle};
				};
			};
			if ((time - dayz_spawnWait) > dayz_spawnDelay) then {
				if (dayz_spawnZombies < dayz_maxLocalZombies) then {
					if (!_tooManyZs) then {
						private["_zombied"];
						_zombied = (_x getVariable ["zombieSpawn",-0.1]);
						_dateNow = (DateToNumber date);
						_age = (_dateNow - _zombied) * 525948;
						if (_age > 5) then {
							_bPos = getPosATL _x;
							_zombiesNum = {alive _x} count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]);
							if (_zombiesNum == 0) then {
								//Randomize Zombies
								_x setVariable ["zombieSpawn",_dateNow,true];
								_handle = [_x,_fastRun] spawn building_spawnZombies;
								waitUntil{scriptDone _handle};
							//} else {
								//_x setVariable ["zombieSpawn",_dateNow,true];
							};
						};
					};
				} else {
					dayz_spawnWait = time;
					dayz_spawnZombies = 0;
				};
			};
		};
		if (!_fastRun) then {
			sleep 0.1;
		};
	} forEach _nearby;
};



Here are some snippets of code I found that might relate, and maybe can be pieced together:

Code:
if (count _nearby > 0) then {



_nearby = (getPosATL _dog) nearEntities ["CAAnimalBase",_senseSkill];



if (count _nearBy == 0) then {



_nearby = _position nearObjects ["building",200]; //nearestObjects [player, ["building"], 200];



if (alive _projectile && !(isNull _projectile)) then {_currentNear = (Position _projectile) nearEntities [["CAManBase","AllVehicles"],15];};





_nearMen = (position _spot) nearEntities [["Man"],50];



_nearby = (getPosATL _dog) nearEntities ["CAAnimalBase",_senseSkill];



if (!_nearByPlayer and !_nearBy) then {



_nearByPlayer = ({isPlayer _x} count (_position nearEntities ["CAManBase",30])) > 0;



_nearby = {isPlayer _x} count (_x nearEntities [[""CAManBase""], 100]);" \n
 
Well, I figured out how to create a "cleared" zone of 200 around each player with the 300-500 ring causing zombie spawns. So, once you clear the area 200 around you, zombies will not spawn in the 200 ring at all (they might creep in from outside the 200 ring on their own, though).

I also got rid of multiple players causing zombie spawns from the same building while more than one player is in the building's spawn range (500 for me). Basically, before a building spawns zombies for a player, it checks to see if another player is within 500 of the building. If there is, it does not spawn any zombies. I guess there is a chance that multiple players could cross the 500 barrier before the building checks (current vanilla code does not check the nearest building first), but, hopefully, that should be rare.

I am now running with 4x vanilla zombies--fun testing with the SAW! Once I add the zombie damage changes (zombies will require additional non-head shots to take them down), zombies should be an actual threat!

As I am still testing and making changes I won't post the current code. If anyone is interested in any of this, let me know, and I will give you whatever is my latest work (at that time).
 
Well, I figured out how to create a "cleared" zone of 200 around each player with the 300-500 ring causing zombie spawns. So, once you clear the area 200 around you, zombies will not spawn in the 200 ring at all (they might creep in from outside the 200 ring on their own, though).

I also got rid of multiple players causing zombie spawns from the same building while more than one player is in the building's spawn range (500 for me). Basically, before a building spawns zombies for a player, it checks to see if another player is within 500 of the building. If there is, it does not spawn any zombies. I guess there is a chance that multiple players could cross the 500 barrier before the building checks (current vanilla code does not check the nearest building first), but, hopefully, that should be rare.

I am now running with 4x vanilla zombies--fun testing with the SAW! Once I add the zombie damage changes (zombies will require additional non-head shots to take them down), zombies should be an actual threat!

As I am still testing and making changes I won't post the current code. If anyone is interested in any of this, let me know, and I will give you whatever is my latest work (at that time).

I know this is a old thread but I've been searching for the Zombies health and damage/hitboxes. I'm trying to get my server to where zombies hit for a ton, and are almost impossible to kill without headshots.

Basically I'm going to have zombies with 150k health, normal body shots doing normal damage but headshots being a 1 shot kill.
 
Joikd,

Can I get a copy of the latest code, it sounds like exactly what I am trying to do.
 
Back
Top