Updates refs #1109

This commit is contained in:
Florian Kinder
2014-02-16 22:38:15 +01:00
parent 2ed8ac27fd
commit 2a91d7d5bc
11 changed files with 413 additions and 526 deletions

View File

@@ -1,58 +1,75 @@
private ["_obj","_type","_config","_positions","_iPos","_nearBy","_itemType","_itemTypes","_lootChance","_weights","_cntWeights","_index","_itemTypesSmall","_positionsSmall"];
//_t1 = diag_tickTime;
_obj = _this select 0;
// lower case to prevent issues with differing case for buildings from map to map.
_type = toLower(typeOf _obj);
//diag_log format["Spawning loot for: %1", _type];
/*
Created exclusively for ArmA2:OA - DayZMod.
Please request permission to use/alter/distribute from project leader (R4Z0R49)
*/
//private ["_lootChance","_index","_weights","_cntWeights","_itemType","_qty","_rnd","_iPos","_obj","_type","_config","_pos","_itemTypes","_positions","_bias"];
private ["_lootChance"];
_obj = _this;
_type = typeOf _obj;
_config = configFile >> "CfgBuildingLoot" >> _type;
_pos = [] + getArray (_config >> "lootPos");
_itemTypes = [] + getArray (_config >> "lootType");
_lootChance = getNumber (_config >> "lootChance");
//_countPositions = count _pos;
_qty = 0; // effective quantity of spawned weaponholder
_lootSpawnBias = 67; //67 between 50 and 100. The lower it is, the lower chance some of the lootpiles will spawn
_config = configFile >> "CfgBuildingLoot" >> _type;
if (DZE_MissionLootTable) then {
_config = missionConfigFile >> "CfgBuildingLoot" >> _type;
// shuffles an array
// parameters: array
// example: _myrandomarray = _myNormalArray call _ShuffleArray;
ShuffleArray = {
private ["_ar","_rand_array","_rand"];
_ar = _this;
_rand_array = [];
while {count _ar > 0} do {
_rand = (count _ar);
_rand = floor (random _rand);
_rand_array set [count _rand_array, _ar select _rand];
_ar set [_rand, "randarray_del"];
_ar = _ar - ["randarray_del"];
};
_rand_array;
};
_positions = _pos call ShuffleArray;
_positions = [] + getArray (_config >> "lootPos");
_itemTypes = [] + getArray (_config >> "itemType");
_lootChance = getNumber (_config >> "lootChance");
// bias for this building. The lower it is, the lower chance some of the lootpiles will spawn
_bias = 50 max _lootSpawnBias;
_bias = 100 min _bias;
_bias = (_bias + random(100 - _bias)) / 100;
//diag_log(format["BIAS:%1 LOOTCHANCE:%2", _bias, _lootChance]);
{
if ((random 1) < _lootChance) then {
if (count _x == 3) then {
_rnd = (random 1) / _bias;
_iPos = _obj modelToWorld _x;
_nearBy = nearestObjects [_iPos, ["ReammoBox","WeaponHolder","WeaponHolderBase"], 1];
if (count _nearBy == 0) then {
_index = dayz_CBLBase find _type;
//diag_log format["Found %2 at index: %1", _index,_type];
_weights = dayz_CBLChances select _index;
_cntWeights = count _weights;
_index = floor(random _cntWeights);
_index = _weights select _index;
_itemType = _itemTypes select _index;
[_itemType select 0, _itemType select 1 , _iPos, 0.0] call spawn_loot;
//_obj setVariable ["created",(DateToNumber date),true];
_nearBy = nearestObjects [_iPos, ["ReammoBox"], 2];
if (count _nearBy > 0) then {
_lootChance = _lootChance + 0.05;
};
if (dayz_currentWeaponHolders < dayz_maxMaxWeaponHolders) then {
if (_rnd <= _lootChance) then {
if (count _nearBy == 0) then {
_index = dayz_CBLBase find _type;
_weights = dayz_CBLChances select _index;
_cntWeights = count _weights;
_index = floor(random _cntWeights);
_index = _weights select _index;
_itemType = _itemTypes select _index;
[_itemType select 0, _itemType select 1 , _iPos, 0.0] call spawn_loot;
// diag_log (format["SpawnLoot: Pos: %1, LootType: %2/%3,",_iPos,_itemType select 0,_itemType select 1]);
dayz_currentWeaponHolders = dayz_currentWeaponHolders +1;
//loclout system
_islocal = _obj getVariable ["", false]; // object created locally via TownGenerator. See stream_locationFill.sqf
_obj setVariable ["looted",diag_tickTime + dayz_tickTimeOffset,!_islocal];
};
};
};
//sleep 0.002;
};
} forEach _positions;
_itemTypesSmall = [] + getArray (_config >> "itemTypeSmall");
_positionsSmall = [] + getArray (_config >> "lootPosSmall");
{
if ((random 1) < _lootChance) then {
_iPos = _obj modelToWorld _x;
_nearBy = nearestObjects [_iPos, ["ReammoBox","WeaponHolder","WeaponHolderBase"], 1];
if (count _nearBy == 0) then {
_index = dayzE_CBLSBase find _type;
//diag_log format["Found %2 at index: %1", _index,_type];
_weights = dayzE_CBLSChances select _index;
_cntWeights = count _weights;
_index = floor(random _cntWeights);
_index = _weights select _index;
_itemType = _itemTypesSmall select _index;
[_itemType select 0, _itemType select 1 , _iPos, 0.0] call spawn_loot_small;
//_obj setVariable ["created",(DateToNumber date),true];
};
};
} forEach _positionsSmall;
//["building_spawnLoot.sqf",(diag_tickTime - _t1)] call fnc_dump;
//dayz_currentWeaponHolders;

View File

@@ -7,7 +7,7 @@ _onTheMove = (speed (vehicle player) > 10);
_dateNow = (DateToNumber date);
_maxWildZombies = 3;
_age = -1;
_radius = 200;
_radius = 200;
_position = getPosATL player;
dayz_spawnZombies = 0;
@@ -46,7 +46,7 @@ if ("ItemMap_Debug" in items player) then {
deleteMarkerLocal "Loot30";
deleteMarkerLocal "Loot120";
deleteMarkerLocal "Agro80";
_markerstr = createMarkerLocal ["MaxZeds", _position];
_markerstr setMarkerColorLocal "ColorYellow";
_markerstr setMarkerShapeLocal "ELLIPSE";
@@ -58,7 +58,7 @@ if ("ItemMap_Debug" in items player) then {
_markerstr1 setMarkerShapeLocal "ELLIPSE";
_markerstr1 setMarkerBrushLocal "Border";
_markerstr1 setMarkerSizeLocal [_radius+100, _radius+100];
_markerstr2 = createMarkerLocal ["Agro80", _position];
_markerstr2 setMarkerColorLocal "ColorRed";
_markerstr2 setMarkerShapeLocal "ELLIPSE";
@@ -83,11 +83,11 @@ diag_log ("GlobalZombies: " +str(dayz_CurrentZombies) + "/" +str(dayz_maxGlobalZ
diag_log ("dayz_maxCurrentZeds: " +str(dayz_maxCurrentZeds) + "/" +str(dayz_maxZeds));
};
_nearby = _position nearObjects ["building",_radius];
_nearbyCount = count _nearby;
if (_nearbyCount < 1) exitwith
if (_nearbyCount < 1) exitwith
{
if ((dayz_spawnZombies < _maxWildZombies) and !_inVehicle) then {
[_position] call wild_spawnZombies;
@@ -102,7 +102,7 @@ if (_nearbyCount < 1) exitwith
_config = missionConfigFile >> "CfgBuildingLoot" >> _type;
};
_canLoot = isClass (_config);
if(_canLoot) then {
_dis = _x distance player;
@@ -124,8 +124,7 @@ if (_nearbyCount < 1) exitwith
//Register
_x setVariable ["looted",_dateNow,true];
//cleanup
_handle = [_x] spawn building_spawnLoot;
waitUntil{scriptDone _handle};
_x call building_spawnLoot;
};
};

View File

@@ -1,28 +1,28 @@
private ["_radius","_position","_inVehicle","_dateNow","_age","_locationstypes","_nearestCity","_type","_looted","_cleared","_nearByObj","_handle","_x"];//_radius, _position, _inVehicle, _dateNow, _age, _locationstypes, _nearestCity, _nearbyBuildings
_radius = _this select 0;
_position = _this select 1;
_inVehicle = _this select 2;
_dateNow = _this select 3;
_age = _this select 4;
_locationstypes = _this select 5;
_nearestCity = _this select 6;
_looted = (_x getVariable ["looted",-0.1]);
_cleared = (_x getVariable ["cleared",true]);
_dateNow = (DateToNumber date);
_age = (_dateNow - _looted) * 525948;
//diag_log ("SPAWN LOOT: " + _type + " Building is " + str(_age) + " old" );
if ((_age > 10) and (!_cleared)) 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)) then {
//Register
_x setVariable ["looted",_dateNow,true];
//cleanup
_handle = [_x] spawn building_spawnLoot;
waitUntil{scriptDone _handle};
};
// private["_radius","_position","_inVehicle","_dateNow","_age","_locationstypes","_nearestCity","_nearbyBuildings","_nearby","_type","_config","_canZombie","_canLoot","_dis","_keepAwayDist","_isNoone","_looted","_cleared"];//_radius, _position, _inVehicle, _dateNow, _age, _locationstypes, _nearestCity, _nearbyBuildings
//
// _radius = _this select 0;
// _position = _this select 1;
// _inVehicle = _this select 2;
// _dateNow = _this select 3;
// _age = _this select 4;
// _locationstypes = _this select 5;
// _nearestCity = _this select 6;
//
// _looted = (_x getVariable ["looted",-0.1]);
// _cleared = (_x getVariable ["cleared",true]);
// _dateNow = (DateToNumber date);
// _age = (_dateNow - _looted) * 525948;
// //diag_log ("SPAWN LOOT: " + _type + " Building is " + str(_age) + " old" );
// if ((_age > 10) and (!_cleared)) then {
// _nearByObj = nearestObjects [(getPosATL _x), ["WeaponHolder","WeaponHolderBase"],((sizeOf _type)+5)];
// {deleteVehicle _x} forEach _nearByObj;
// _x setVariable ["cleared",true];
// _x setVariable ["looted",_dateNow,true];
// };
// if ((_age > 10) and (_cleared)) then {
// //Register
// _x setVariable ["looted",_dateNow,true];
// //cleanup
// _handle = [_x] spawn building_spawnLoot;
// waitUntil{scriptDone _handle};
// };

View File

@@ -1,150 +1,102 @@
private ["_iItem","_iClass","_iPos","_radius","_item","_itemTypes","_index","_weights","_cntWeights","_qty","_max","_tQty","_canType","_mags","_dateNow"];
private ["_item","_itemTypes","_qty","_tQty","_uniq"];
_iItem = _this select 0;
_iClass = _this select 1;
//diag_log format["DEBUG spawn loot class: %1", _iClass];
_iPos = _this select 2;
_radius = _this select 3;
_iItem = _this select 0;
_iClass = _this select 1;
_iPos = _this select 2;
_radius = _this select 3;
switch (_iClass) do
{
default
{
//_uniq = ["ItemWaterbottle", "ItemWaterbottleUnfilled"];
_uniq = [];
//_permaLoot = false;
_iPosZ = _iPos select 2;
if((isNil "_iPosZ") OR {( _iPosZ < 0)}) then { _iPos = [_iPos select 0,_iPos select 1,0]; };
//if(_iClass == "Unknown") exitwith {};
switch (_iClass) do {
default {
//Item is food, add random quantity of cans along with an item (if exists)
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_itemTypes = [];
if (DZE_MissionLootTable) then {
_itemTypes = ((getArray (missionConfigFile >> "cfgLoot" >> _iClass)) select 0);
} else {
_itemTypes = ((getArray (configFile >> "cfgLoot" >> _iClass)) select 0);
};
_index = dayz_CLBase find _iClass;
_weights = dayz_CLChances select _index;
_cntWeights = count _weights;
{
_itemTypes set [count _itemTypes, _x select 0]
} foreach getArray (configFile >> "cfgLoot" >> _iClass);
_qty = 0;
_max = 1 + round(random 2);
while {_qty < _max} do
{
_tQty = 1 + round(random 1);
_index = floor(random _cntWeights);
_index = _weights select _index;
_canType = _itemTypes select _index;
_item addMagazineCargoGlobal [_canType,_tQty];
_qty = _qty + _tQty;
_max = ceil(random 2) + 1;
while {_qty < _max} do {
_index = dayz_CLBase find _iClass;
_weights = dayz_CLChances select _index;
_cntWeights = count _weights;
_index = floor(random _cntWeights);
_index = _weights select _index;
_canType = _itemTypes select _index;
//_itemarray = dayz_CLItemNames select _index;
//_canType = _itemarray call BIS_fnc_selectRandom;
//diag_log ("CanType: "+str(_canType));
_tQty = round(random 1) + 1;
if (_canType in _uniq) then {
if (({_x in _uniq} count magazines _item) == 0) then { _tQty = 1; } else { _tQty = 0;};
if (_tQty == 0) then {diag_log(format["%1 Prevent any duplicate member %2 from family %3",__FILE__, _canType, _uniq]);};
//diag_log(format["%1 %2 DUP? type:%3 mag:%4 _this:%5",__FILE__, __LINE__, _canType, magazines _item, _this]);
};
if (_tQty > 0) then {
if (!(_canType in _uniq)) then {
_item addMagazineCargoGlobal [_canType,1];
_uniq set [count _uniq, _canType];
//diag_log ("uniq: "+str(_uniq));
_qty = _qty + 1;
};
};
};
if (_iItem != "") then
{
if (_iItem != "") then {
_item addWeaponCargoGlobal [_iItem,1];
//diag_log ("Unknown");
};
};
case "single":
{
//Item is sigle, add 1 item from cfgloot
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_itemTypes = [];
if (DZE_MissionLootTable) then {
_itemTypes = ((getArray (missionConfigFile >> "cfgLoot" >> _iItem)) select 0);
} else {
_itemTypes = ((getArray (configFile >> "cfgLoot" >> _iItem)) select 0);
};
_index = dayz_CLBase find _iItem;
_weights = dayz_CLChances select _index;
_cntWeights = count _weights;
_index = floor(random _cntWeights);
_index = _weights select _index;
_canType = _itemTypes select _index;
_item addMagazineCargoGlobal [_canType,1];
};
case "backpack":
{
//Item is single backpack
if (DZE_MissionLootTable) then {
_itemTypes = ((getArray (missionConfigFile >> "cfgLoot" >> _iItem)) select 0);
} else {
_itemTypes = ((getArray (configFile >> "cfgLoot" >> _iItem)) select 0);
};
_index = dayz_CLBase find _iItem;
_weights = dayz_CLChances select _index;
_cntWeights = count _weights;
_index = floor(random _cntWeights);
_index = _weights select _index;
_iItem = _itemTypes select _index;
_item = createVehicle [_iItem, _iPos, [], _radius, "CAN_COLLIDE"];
};
case "cfglootweapon":
{
if (DZE_MissionLootTable) then {
_itemTypes = ((getArray (missionConfigFile >> "cfgLoot" >> _iItem)) select 0);
} else {
_itemTypes = ((getArray (configFile >> "cfgLoot" >> _iItem)) select 0);
};
_index = dayz_CLBase find _iItem;
_weights = dayz_CLChances select _index;
_cntWeights = count _weights;
_index = floor(random _cntWeights);
_index = _weights select _index;
_iItem = _itemTypes select _index;
if (_iItem == "Chainsaw") then {
_iItem = ["ChainSaw","ChainSawB","ChainSawG","ChainSawP","ChainSawR"] call BIS_fnc_selectRandom;
};
case "weapon": {
//Item is a weapon, add it and a random quantity of magazines
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_item addWeaponCargoGlobal [_iItem,1];
_mags = [] + getArray (configFile >> "cfgWeapons" >> _iItem >> "magazines");
if ((count _mags) > 0) then
{
if (_mags select 0 == "Quiver") then { _mags set [0, "WoodenArrow"] }; // Prevent spawning a Quiver
if ((count _mags) > 0) then {
// if (_mags select 0 == "Quiver") then { _mags set [0, "WoodenArrow"] }; // Prevent spawning a Quiver
if (_mags select 0 == "20Rnd_556x45_Stanag") then { _mags set [0, "30Rnd_556x45_Stanag"] };
if (_mags select 0 == "30Rnd_556x45_G36") then { _mags set [0, "30Rnd_556x45_Stanag"] };
if (_mags select 0 == "30Rnd_556x45_G36SD") then { _mags set [0, "30Rnd_556x45_StanagSD"] };
_item addMagazineCargoGlobal [(_mags select 0), (round(random 2))];
};
};
case "weapon":
{
//Item is a weapon, add it and a random quantity of magazines
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_item addWeaponCargoGlobal [_iItem,1];
_mags = [] + getArray (configFile >> "cfgWeapons" >> _iItem >> "magazines");
if ((count _mags) > 0) then
{
if (_mags select 0 == "Quiver") then { _mags set [0, "WoodenArrow"] }; // Prevent spawning a Quiver
if (_mags select 0 == "20Rnd_556x45_Stanag") then { _mags set [0, "30Rnd_556x45_Stanag"] };
if (_mags select 0 == "30Rnd_556x45_G36") then { _mags set [0, "30Rnd_556x45_Stanag"] };
if (_mags select 0 == "30Rnd_556x45_G36SD") then { _mags set [0, "30Rnd_556x45_StanagSD"] };
_item addMagazineCargoGlobal [(_mags select 0), (round(random 2))];
if (!(_iItem in MeleeWeapons)) then {
_magQty = round(random 10);
if (_magQty > 3) then {
_item addMagazineCargoGlobal [(_mags select 0), (round(random 1) + 1)];
};
};
};
};
case "weaponnomags":
{
//Item is a weapon, and spawns no mags
/*
case "tools": {
//Item is one tool
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_item addWeaponCargoGlobal [_iItem,1];
_item addMagazineCargoGlobal [_iItem,1];
};
case "magazine":
{
*/
case "magazine": {
//Item is one magazine
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_item addMagazineCargoGlobal [_iItem,1];
};
case "object":
{
case "object": {
//Item is one magazine
_item = createVehicle [_iItem, _iPos, [], _radius, "CAN_COLLIDE"];
};
};
// timestamp for later clearing
_dateNow = (DateToNumber date);
_item setVariable ["looted",_dateNow,true];
if ((count _iPos) > 2) then
{
if ((count _iPos) > 2) then {
_item setPosATL _iPos;
};
//if (_permaLoot == true) then { _item setVariable ["permaLoot",true]; };
_item // used in server_spawnCrashSite

View File

@@ -1,108 +0,0 @@
private ["_iItem","_iClass","_iPos","_radius","_item","_itemTypes","_index","_weights","_cntWeights","_canType","_dateNow"];
_iItem = _this select 0;
_iClass = _this select 1;
//diag_log format["DEBUG spawn loot class: %1", _iClass];
_iPos = _this select 2;
_radius = _this select 3;
switch (_iClass) do
{
default
{
//Item is sigle, add 1 item from CfgLootSmall
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_itemTypes = [];
if (DZE_MissionLootTable) then {
_itemTypes = ((getArray (missionConfigFile >> "CfgLootSmall" >> _iClass)) select 0);
} else {
_itemTypes = ((getArray (configFile >> "CfgLootSmall" >> _iClass)) select 0);
};
_index = dayzE_CLSBase find _iClass;
_weights = dayzE_CLSChances select _index;
_cntWeights = count _weights;
_index = floor(random _cntWeights);
_index = _weights select _index;
_canType = _itemTypes select _index;
_item addMagazineCargoGlobal [_canType,1];
};
case "single":
{
//Item is sigle, add 1 item from CfgLootSmall
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_itemTypes = [];
if (DZE_MissionLootTable) then {
_itemTypes = ((getArray (missionConfigFile >> "CfgLootSmall" >> _iItem)) select 0);
} else {
_itemTypes = ((getArray (configFile >> "CfgLootSmall" >> _iItem)) select 0);
};
_index = dayzE_CLSBase find _iItem;
_weights = dayzE_CLSChances select _index;
_cntWeights = count _weights;
_index = floor(random _cntWeights);
_index = _weights select _index;
_canType = _itemTypes select _index;
_item addMagazineCargoGlobal [_canType,1];
};
case "cfglootweapon":
{
//Item is sigle, add 1 item from cfgloot
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_itemTypes = [];
if (DZE_MissionLootTable) then {
_itemTypes = ((getArray (missionConfigFile >> "CfgLootSmall" >> _iItem)) select 0);
} else {
_itemTypes = ((getArray (configFile >> "CfgLootSmall" >> _iItem)) select 0);
};
_index = dayz_CLBase find _iItem;
_weights = dayz_CLChances select _index;
_cntWeights = count _weights;
_index = floor(random _cntWeights);
_index = _weights select _index;
_iItem = _itemTypes select _index;
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_item addWeaponCargoGlobal [_iItem,1];
};
case "weapon":
{
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_item addWeaponCargoGlobal [_iItem,1];
};
case "magazine":
{
//Item is one magazine
_item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
_item addMagazineCargoGlobal [_iItem,1];
};
case "weaponnomags":
{
//do nothing for now
};
case "backpack":
{
//do nothing for now
};
case "object":
{
//do nothing for now
};
};
// timestamp for later clearing
_dateNow = (DateToNumber date);
_item setVariable ["looted",_dateNow,true];
if ((count _iPos) > 2) then
{
_item setPosATL _iPos;
};

View File

@@ -1,120 +1,157 @@
private ["_position","_doLoiter","_unitTypes","_isNoone","_loot","_array","_agent","_type","_radius","_method","_nearByPlayer","_myDest","_newDest","_lootType","_isAlive","_rnd","_id"];
_position = _this select 0;
_doLoiter = _this select 1;
_unitTypes = _this select 2;
private ["_position","_unitTypes","_radius","_method","_agent"];
if (dayz_maxCurrentZeds > dayz_maxZeds) exitwith {};
if (dayz_CurrentZombies > dayz_maxGlobalZombies) exitwith {};
if (dayz_spawnZombies > dayz_maxLocalZombies) exitwith {};
_position = _this select 0;
_doLoiter = _this select 1; // wander around
_unitTypes = _this select 2; // class of wanted models
_maxControlledZombies = round(dayz_maxLocalZombies);
_isNoone = {isPlayer _x} count (_position nearEntities [["AllVehicles","CAManBase"],30]) == 0;
_loot = "";
_array = [];
_agent = objNull;
_cantSee = {
private ["_isok"];
//Exit if a player is nearby
if (!_isNoone) exitWith {};
if (count _unitTypes == 0) then {
if (DZE_MissionLootTable) then {
_unitTypes = []+ getArray (missionConfigFile >> "CfgBuildingLoot" >> "Default" >> "zombieClass");
} else {
_unitTypes = []+ getArray (configFile >> "CfgBuildingLoot" >> "Default" >> "zombieClass");
_isok = true;
_zPos = +(_this select 0);
if (count _zPos < 3) exitWith {
diag_log format["%1::_cantSee illegal pos %2", __FILE__, _zPos];
false
};
};
_type = _unitTypes call BIS_fnc_selectRandom;
//Create the Group and populate it
//diag_log ("Spawned: " + _type);
_radius = 0;
_method = "CAN_COLLIDE";
if (_doLoiter) then {
_radius = 40;
_method = "NONE";
};
//diag_log ("Spawned: " + str([_type, _position, [], _radius, _method]));
_agent = createAgent [_type, _position, [], _radius, _method];
PVDZE_zed_Spawn = [_agent];
publicVariableServer "PVDZE_zed_Spawn";
if (_doLoiter) then {
_agent setDir round(random 180);
_agent setPosATL _position;
_agent setvelocity [0, 0, 1];
//_agent setVariable ["doLoiter",true,true];
} else {
_agent setVariable ["doLoiter",false,true];
};
dayz_spawnZombies = dayz_spawnZombies + 1;
//diag_log ("CREATE INFECTED: " + str(_this));
_position = getPosATL _agent;
_nearByPlayer = ({isPlayer _x} count (_position nearEntities [["AllVehicles","CAManBase"],30]) > 0);
if (random 1 > 0.7) then {
_agent setUnitPos "Middle";
};
//diag_log ("CREATED: " + str(_agent));
if (_nearByPlayer) then {
deleteVehicle _agent;
};
/*
//_agent setVariable["host",player,true];
if (!_doLoiter) then {
_agent setPosATL _position;
_agent setDir round(random 180);
if (_nearByPlayer) then {
deleteVehicle _agent;
};
} else {
if (_nearByPlayer) then {
_attempt = 0;
while {_nearByPlayer} do {
_position = [_position,0,20,10,0,20,0] call BIS_fnc_findSafePos;
_agent setPos _position;
_nearByPlayer = ({isPlayer _x} count (_position nearEntities ["CAManBase",30]) > 0);
_attempt = _attempt + 1;
if (_attempt > 10) exitWith {};
};
_agent setPos _position;
};
};
*/
if (isNull _agent) exitWith {
dayz_spawnZombies = dayz_spawnZombies - 1;
};
_isAlive = alive _agent;
_myDest = getPosATL _agent;
_newDest = getPosATL _agent;
_agent setVariable ["myDest",_myDest];
_agent setVariable ["newDest",_newDest];
//Add some loot
_rnd = random 1;
if (_rnd > 0.3) then {
_lootType = configFile >> "CfgVehicles" >> _type >> "zombieLoot";
if (isText _lootType) then {
_array = [];
if (DZE_MissionLootTable) then {
_array = getArray (missionConfigFile >> "cfgLoot" >> getText(_lootType));
} else {
_array = getArray (configFile >> "cfgLoot" >> getText(_lootType));
};
if (count _array > 0) then {
_loot = _array call BIS_fnc_selectRandomWeighted;
if(!isNil "_array") then {
_agent addMagazine _loot;
_zPos = ATLtoASL _zPos;
_fov = _this select 1; // players half field of view
_safeDistance = _this select 2; // minimum distance. closer is wrong
_farDistance = _this select 3; // distance further we won't check
_zPos set [2, (_zPos select 2) + 1.7];
{
_xasl = getPosASL _x;
if (_xasl distance _zPos < _farDistance) then {
if (_xasl distance _zPos < _safeDistance) then {
_isok = false;
}
else {
_eye = eyePos _x; // ASL
_ed = eyeDirection _x;
_ed = (_ed select 0) atan2 (_ed select 1);
_deg = [_xasl, _zPos] call BIS_fnc_dirTo;
_deg = (_deg - _ed + 720) % 360;
if (_deg > 180) then { _deg = _deg - 360; };
if ((abs(_deg) < _fov) AND {( // in right angle sector?
(!(terrainIntersectASL [_zPos, _eye]) // no terrain between?
AND {(!(lineIntersects [_zPos, _eye]))}) // and no object between?
)}) then {
_isok = false;
};
};
};
};
if (!_isok) exitWith {false};
} forEach playableUnits;
_isok
};
//Start behavior
_id = [_position,_agent] execFSM "\z\AddOns\dayz_code\system\zombie_agent.fsm";
if ((dayz_spawnZombies < _maxControlledZombies) and (dayz_CurrentNearByZombies < dayz_maxNearByZombies) and (dayz_currentGlobalZombies < dayz_maxGlobalZeds)) then {
if ([_position, dayz_cantseefov, 10, dayz_cantseeDist] call _cantSee) then {
//Check if anyone close
_tooClose = {isPlayer _x} count (_position nearEntities ["CAManBase",30]) > 0;
if (_tooClose) exitwith {
diag_log ("Zombie_Generate: was too close to player.");
};
//Add zeds if unitTypes equals 0
if (count _unitTypes == 0) then {
if (DZE_MissionLootTable) then {
_unitTypes = []+ getArray (missionConfigFile >> "CfgBuildingLoot" >> "Default" >> "zombieClass");
} else {
_unitTypes = []+ getArray (configFile >> "CfgBuildingLoot" >> "Default" >> "zombieClass");
};
};
// lets create an agent
_type = _unitTypes call BIS_fnc_selectRandom;
_radius = 5;
_method = "NONE";
if (_doLoiter) then {
_radius = 40;
_method = "CAN_COLLIDE";
};
//Check if point is in water
if (surfaceIsWater _position) exitwith { Diag_log ("Location is in Water Abort"); };
_agent = createAgent [_type, _position, [], _radius, _method];
sleep 0.001;
//add to global counter
dayz_spawnZombies = dayz_spawnZombies + 1;
//Add some loot
_loot = "";
_array = [];
_rnd = random 1;
if (_rnd < 0.2) then {
_lootType = configFile >> "CfgVehicles" >> _type >> "zombieLoot";
if (isText _lootType) then {
_array = [];
{
_array set [count _array, _x select 0]
} foreach getArray (configFile >> "cfgLoot" >> getText(_lootType));
if (count _array > 0) then {
_index = dayz_CLBase find getText(_lootType);
_weights = dayz_CLChances select _index;
_loot = _array select (_weights select (floor(random (count _weights))));
if(!isNil "_array") then {
_loot_count = getNumber(configFile >> "CfgMagazines" >> _loot >> "count");
if(_loot_count>1) then {
_agent addMagazine [_loot, ceil(random _loot_count)];
} else {
_agent addMagazine _loot;
};
};
};
};
};
_agent setVariable["agentObject",_agent];
if (!isNull _agent) then {
// sometime Z can be seen flying in very high speed while tp. Its altitude is set underground to hide that.
/*
_agtPos = getPosASL _agent;
_agtPos set [2, -3];
_agent setPosASL _agtPos;
sleep 0.001;
_agtPos = +(_position);
_agtPos set [2, -3];
_agent setPosASL _agtPos;
sleep 0.001;
*/
_agent setDir random 360;
//_agent setPosATL _position;
sleep 0.001;
_position = getPosATL _agent;
_favStance = (
switch ceil(random(3^0.5)^2) do {
//case 3: {"DOWN"}; // prone
case 2: {"Middle"}; // Kneel
default {"UP"} // stand-up
}
);
_agent setUnitPos _favStance;
_agent setVariable ["stance", _favStance];
_agent setVariable ["BaseLocation", _position];
_agent setVariable ["doLoiter", true]; // true: Z will be wandering, false: stay still
_agent setVariable ["myDest", _position];
_agent setVariable ["newDest", _position];
[_agent, _position] call zombie_loiter;
};
//add to monitor
//dayz_zedMonitor set [count dayz_zedMonitor, _agent];
//Disable simulation
PVDZ_Server_Simulation = [_agent, false];
publicVariableServer "PVDZ_Server_Simulation";
//Start behavior
_id = [_position,_agent] execFSM "\z\AddOns\dayz_code\system\zombie_agent.fsm";
};
};