diff --git a/SQF/dayz_code/compile/building_spawnLoot.sqf b/SQF/dayz_code/compile/building_spawnLoot.sqf index 49416020a..900177ad9 100644 --- a/SQF/dayz_code/compile/building_spawnLoot.sqf +++ b/SQF/dayz_code/compile/building_spawnLoot.sqf @@ -1,9 +1,14 @@ /* Spawns loot at the given building. -Single parameter: - object building to spawn loot at - +Parameters: + obj - building to spawn loot at + type - classname of building + config - building configs (type, loot chance, loot positions. loot refresh timer) + +Usage: + [building,classname,_config] call building_spawnLoot; + Author: Foxy */ @@ -11,37 +16,23 @@ Author: #include "\z\addons\dayz_code\util\Vector.hpp" #include "\z\addons\dayz_code\loot\Loot.hpp" -private -[ - "_vectorUp", - "_type", - "_config", - "_lootChance", - "_lootPos", - "_lootGroup", - "_worldPos", - "_existingPile", - "_loot" -]; +private ["_vectorUp","_type","_config","_lootChance","_lootPos","_lootGroup","_worldPos","_existingPile","_loot","_obj"]; -_vectorUp = vectorUp _this; +_obj = _this select 0; +_type = _this select 1; +_config = _this select 2; +_vectorUp = vectorUp _obj; if (Vector_Angle(Vector_UP,_vectorUp) > 20) exitWith { 0 }; - -_type = typeOf _this; -_config = missionConfigFile >> "CfgLoot" >> "Buildings" >> _type; - -if (!isClass _config) exitWith {}; - _lootChance = getNumber (_config >> "lootChance"); -if (_lootChance <= 0 or ([_this] call DZE_SafeZonePosCheck)) exitWith {}; +if (_lootChance <= 0 or ([_obj] call DZE_SafeZonePosCheck)) exitWith {}; _lootPos = getArray (_config >> "lootPos"); _lootGroup = Loot_GetGroup(getText(_config >> "lootGroup")); { //Get the world position of the spawn position - _worldPos = _this modelToWorld _x; + _worldPos = _obj modelToWorld _x; _worldPos set [2, 0 max (_worldPos select 2)]; //Delete existing lootpiles within 1m of spawn location @@ -68,7 +59,7 @@ if (isArray (_config >> "lootPosSmall")) then { if (_lootGroup >= 1) then { { //Get the world position of the spawn position - _worldPos = _this modelToWorld _x; + _worldPos = _obj modelToWorld _x; _worldPos set [2, 0 max (_worldPos select 2)]; //Delete existing lootpiles within 1m of spawn location { @@ -84,4 +75,4 @@ if (isArray (_config >> "lootPosSmall")) then { } else { diag_log format["Loot group small: %1 does not exist", ((getText(_config >> "lootGroup")) + "Small")]; }; -}; \ No newline at end of file +}; diff --git a/SQF/dayz_code/compile/building_spawnZombies.sqf b/SQF/dayz_code/compile/building_spawnZombies.sqf index af681210f..74918a3b6 100644 --- a/SQF/dayz_code/compile/building_spawnZombies.sqf +++ b/SQF/dayz_code/compile/building_spawnZombies.sqf @@ -2,28 +2,17 @@ Created exclusively for ArmA2:OA - DayZMod. Please request permission to use/alter/distribute from project leader (R4Z0R49) */ -private ["_wreck","_maxlocalspawned","_maxControlledZombies","_iPos","_nearByZed","_nearByPlayer","_rnd","_positions","_zombieChance","_unitTypes","_min","_max","_num","_clean","_obj","_type","_config","_canLoot","_originalPos","_fastRun","_enabled","_i","_Pos"]; -_obj = _this select 0; +private ["_wreck","_iPos","_nearByZed","_nearByPlayer","_rnd","_positions","_zombieChance","_unitTypes","_min","_max","_num","_clean","_obj","_type","_config","_canLoot","_originalPos","_fastRun","_enabled","_i","_Pos"]; +_obj = _this select 0; +_type = _this select 1; +_config = _this select 2; _wreck = false; -if (count _this > 1) then { - _wreck = _this select 1; +if (count _this > 3) then { + _wreck = _this select 3; }; - -_type = typeOf _obj; -_config = missionConfigFile >> "CfgLoot" >> "Buildings" >> _type; -_canLoot = isClass (_config); _originalPos = getPosATL _obj; -_maxlocalspawned = round(dayz_spawnZombies); -//Lets check if we need to divide the amount of zeds -if (r_player_divideinvehicle > 0) then { - _maxlocalspawned = round(dayz_spawnZombies / r_player_divideinvehicle); -}; - -_maxControlledZombies = round(dayz_maxLocalZombies); -_enabled = false; - -if (_canLoot && !([_originalPos] call DZE_SafeZonePosCheck)) then { +if (!([_originalPos] call DZE_SafeZonePosCheck)) then { //Get zombie class _unitTypes = getArray (_config >> "zombieClass"); _min = getNumber (_config >> "minRoaming"); @@ -37,7 +26,7 @@ if (_canLoot && !([_originalPos] call DZE_SafeZonePosCheck)) then { for "_i" from 0 to _num do { //_iPos = _obj modelToWorld _originalPos; - if ((_maxlocalspawned < _maxControlledZombies) and (dayz_CurrentNearByZombies < dayz_maxNearByZombies) and (dayz_currentGlobalZombies < dayz_maxGlobalZeds)) then { + if ((dayz_spawnZombies < dayz_maxControlledZombies) && {dayz_CurrentNearByZombies < dayz_maxNearByZombies} && {dayz_currentGlobalZombies < dayz_maxGlobalZeds}) then { [_originalPos,true,_unitTypes,_wreck] call zombie_generate; }; }; @@ -56,8 +45,8 @@ if (_canLoot && !([_originalPos] call DZE_SafeZonePosCheck)) then { _nearByZed = {alive _x} count (_iPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]) > 0; _nearByPlayer = ({isPlayer _x} count (_iPos nearEntities ["CAManBase",30])) > 0; //diag_log ("BUILDING: " + _type + " / " + str(_nearByZed) + " / " + str(_nearByPlayer)); - if ((_maxlocalspawned < _maxControlledZombies) and (dayz_CurrentNearByZombies < dayz_maxNearByZombies) and (dayz_currentGlobalZombies < dayz_maxGlobalZeds)) then { - if (!_nearByPlayer and !_nearByZed) then { + if ((dayz_spawnZombies < dayz_maxControlledZombies) && {dayz_CurrentNearByZombies < dayz_maxNearByZombies} && {dayz_currentGlobalZombies < dayz_maxGlobalZeds}) then { + if (!_nearByPlayer and {!_nearByZed}) then { [_iPos,false,_unitTypes,false] call zombie_generate; }; }; diff --git a/SQF/dayz_code/compile/player_spawnCheck.sqf b/SQF/dayz_code/compile/player_spawnCheck.sqf index 7dd986a97..d23ed5372 100644 --- a/SQF/dayz_code/compile/player_spawnCheck.sqf +++ b/SQF/dayz_code/compile/player_spawnCheck.sqf @@ -1,6 +1,5 @@ -private ["_isWreck","_maxControlledZombies","_looted","_zombied","_doNothing","_spawnZedRadius","_serverTime","_age","_nearbyBuildings","_position","_speed","_radius","_maxlocalspawned","_maxWeaponHolders","_currentWeaponHolders","_maxtoCreate","_inVehicle","_isAir","_isLand","_isSea","_Controlledzeddivided","_totalcrew","_nearby","_type","_config","_canSpawn","_dis","_checkLoot","_islocal","_bPos","_zombiesNum"]; +private ["_zeds","_isWreck","_looted","_zombied","_doNothing","_spawnZedRadius","_serverTime","_age","_position","_speed","_radius","_maxtoCreate","_inVehicle","_isAir","_isLand","_isSea","_Controlledzeddivided","_totalcrew","_nearby","_type","_config","_canSpawn","_dis","_checkLoot","_islocal","_bPos","_zombiesNum"]; _age = -1; -//_nearbyBuildings = []; _position = [player] call fnc_getPos; _speed = speed (vehicle player); _radius = 200; //150*0.707; Pointless Processing (106.5) @@ -12,11 +11,23 @@ PVDZ_getTickTime = player; publicVariableServer "PVDZ_getTickTime"; */ -//Total Counts -_maxlocalspawned = round(dayz_spawnZombies); -_maxControlledZombies = round(dayz_maxLocalZombies); -_maxWeaponHolders = round(dayz_maxMaxWeaponHolders); -_currentWeaponHolders = round(dayz_currentWeaponHolders); +// Current zombies +_zeds = entities "zZombie_Base"; +dayz_currentGlobalZombies = count _zeds; +dayz_spawnZombies = 0; +dayz_CurrentNearByZombies = 0; +dayz_maxControlledZombies = dayz_maxLocalZombies; // This variable is also used in building_spawnZombies +{ + if ((_x distance _position) < 200 && {alive _x}) then { + if (local _x) then { + dayz_spawnZombies = dayz_spawnZombies + 1; + }; + dayz_CurrentNearByZombies = dayz_CurrentNearByZombies + 1; + }; +} count _zeds; + +// Current loot spawns +dayz_currentWeaponHolders = count (_position nearObjects ["ReammoBox",200]); //Limits (Land,Sea,Air) _inVehicle = (vehicle player != player); @@ -47,8 +58,7 @@ if (_inVehicle) then { }; if (_Controlledzeddivided > 0) then { - _maxControlledZombies = round(_maxControlledZombies / _Controlledzeddivided); - r_player_divideinvehicle = _Controlledzeddivided; + dayz_maxControlledZombies = round(dayz_maxControlledZombies / _Controlledzeddivided); }; }; @@ -95,15 +105,15 @@ if (_doNothing) exitwith {}; //Logging diag_log (format["%1 Local.Agents: %2/%3, NearBy.Agents: %8/%9, Global.Agents: %6/%7, W.holders: %10/%11, (radius:%4m %5fps).","SpawnCheck", - _maxlocalspawned, _maxControlledZombies, _radius, round diag_fpsmin,dayz_currentGlobalZombies, - dayz_maxGlobalZeds, dayz_CurrentNearByZombies, dayz_maxNearByZombies, _currentWeaponHolders,_maxWeaponHolders]); + dayz_spawnZombies, dayz_maxControlledZombies, _radius, round diag_fpsmin,dayz_currentGlobalZombies, + dayz_maxGlobalZeds, dayz_CurrentNearByZombies, dayz_maxNearByZombies, dayz_currentWeaponHolders,dayz_maxMaxWeaponHolders]); };*/ // nearObjects is faster than nearestObjects when sorting by distance isn't needed // "Building" includes House and all of its child classes (Crashsite, IC_Fireplace1, IC_Tent, etc.) _nearby = _position nearObjects ["Building",_radius]; -_maxlocalspawned = _maxlocalspawned max floor(_maxControlledZombies*.8); -if (_maxlocalspawned > 0) then { _spawnZedRadius = _spawnZedRadius * 3; }; +dayz_spawnZombies = dayz_spawnZombies max floor(dayz_maxControlledZombies*.8); +if (dayz_spawnZombies > 0) then { _spawnZedRadius = _spawnZedRadius * 3; }; //Spawn Zeds & loot in buildings { @@ -121,7 +131,7 @@ if (_maxlocalspawned > 0) then { _spawnZedRadius = _spawnZedRadius * 3; }; //Loot if (getNumber(_config >> "lootChance") > 0) then { - if (_currentWeaponHolders < _maxWeaponHolders) then { + if (dayz_currentWeaponHolders < dayz_maxMaxWeaponHolders) then { //Basic loot check if ((_dis < 125) and (_dis > 30) and !_inVehicle and _checkLoot) then { _serverTime = serverTime; @@ -130,7 +140,7 @@ if (_maxlocalspawned > 0) then { _spawnZedRadius = _spawnZedRadius * 3; }; //Building refresh rate if (_age == 0 or (_age > getNumber(_config >> "lootRefreshTimer"))) then { _x setVariable ["looted",_serverTime,!_islocal]; - _x call building_spawnLoot; + [_x,_type,_config] call building_spawnLoot; if (!(_x in dayz_buildingBubbleMonitor)) then { dayz_buildingBubbleMonitor set [count dayz_buildingBubbleMonitor, _x]; }; @@ -151,7 +161,7 @@ if (_maxlocalspawned > 0) then { _spawnZedRadius = _spawnZedRadius * 3; }; _age = _serverTime - _zombied; if ((_age == 0) or (_age > 300)) then { if (!_isWreck) then { - if ((dayz_spawnZombies < _maxControlledZombies) and (dayz_CurrentNearByZombies < dayz_maxNearByZombies) and (dayz_currentGlobalZombies < dayz_maxGlobalZeds)) then { + if ((dayz_spawnZombies < dayz_maxControlledZombies) && {dayz_CurrentNearByZombies < dayz_maxNearByZombies} && {dayz_currentGlobalZombies < dayz_maxGlobalZeds}) then { _bPos = getPosATL _x; _zombiesNum = count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]); @@ -164,7 +174,7 @@ if (_maxlocalspawned > 0) then { _spawnZedRadius = _spawnZedRadius * 3; }; }; //start spawn - [_x] call building_spawnZombies; + [_x,_type,_config] call building_spawnZombies; }; //diag_log (format["%1 building. %2", __FILE__, _x]); }; @@ -172,10 +182,10 @@ if (_maxlocalspawned > 0) then { _spawnZedRadius = _spawnZedRadius * 3; }; _bPos = getPosATL _x; _zombiesNum = count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 30)]); //Should be a wreck - if (_zombiesNum == 0) then { [_x,_isWreck] call building_spawnZombies; }; + if (_zombiesNum == 0) then { [_x,_type,_config,_isWreck] call building_spawnZombies; }; }; }; }; }; }; -} forEach _nearby; \ No newline at end of file +} forEach _nearby; diff --git a/SQF/dayz_code/compile/zombie_generate.sqf b/SQF/dayz_code/compile/zombie_generate.sqf index fa495bbb7..06ab5f60d 100644 --- a/SQF/dayz_code/compile/zombie_generate.sqf +++ b/SQF/dayz_code/compile/zombie_generate.sqf @@ -1,7 +1,7 @@ #include "\z\addons\dayz_code\loot\Loot.hpp" private ["_bypass","_position","_unitTypes","_radius","_method","_agent","_maxlocalspawned","_doLoiter","_wildspawns","_maxControlledZombies", -"_cantSee","_isOk","_zPos","__FILE__","_fov","_safeDistance","_farDistance","_xasl","_eye","_ed","_deg","_skipFOV","_wildSpawns","_tooClose", +"_cantSee","_isOk","_zPos","__FILE__","_fov","_safeDistance","_farDistance","_xasl","_eye","_ed","_deg","_skipFOV","_tooClose", "_type","_loot","_array","_rnd","_lootType","_index","_weights","_loot_count","_favStance","_lootGroup"]; _position = _this select 0; @@ -10,14 +10,6 @@ _unitTypes = _this select 2; // class of wanted models //_wildspawns = _this select 3; _bypass = _this select 3; -_maxlocalspawned = round(dayz_spawnZombies); -//Lets check if we need to divide the amount of zeds -if (r_player_divideinvehicle > 0) then { - _maxlocalspawned = round(dayz_spawnZombies / r_player_divideinvehicle); -}; - -_maxControlledZombies = round(dayz_maxLocalZombies); - _cantSee = { private "_isOk"; @@ -61,63 +53,61 @@ _cantSee = { _skipFOV = false; -if ((_maxlocalspawned < _maxControlledZombies) && (dayz_CurrentNearByZombies < dayz_maxNearByZombies) && (dayz_currentGlobalZombies < dayz_maxGlobalZeds)) then { - if (_bypass) then { - _skipFOV = true; - _position = [_position,3,20,1] call fn_selectRandomLocation; +if (_bypass) then { + _skipFOV = true; + _position = [_position,3,20,1] call fn_selectRandomLocation; +}; + +if (surfaceIsWater _position) exitWith { diag_log "Location is in Water Abort"; }; + +if ((_skipFOV) or {([_position, 15, 10, 70] call _cantSee)}) then { + _tooClose = {isPlayer _x} count (_position nearEntities ["CAManBase",30]) > 0; + if (_tooClose) exitwith { diag_log "Zombie_Generate: was too close to player."; }; + + if (count _unitTypes == 0) then { + _unitTypes = getArray (missionConfigFile >> "CfgLoot" >> "Buildings" >> "Default" >> "zombieClass"); }; - - if (surfaceIsWater _position) exitWith { diag_log "Location is in Water Abort"; }; - - if ((_skipFOV) or {([_position, 15, 10, 70] call _cantSee)}) then { - _tooClose = {isPlayer _x} count (_position nearEntities ["CAManBase",30]) > 0; - if (_tooClose) exitwith { diag_log "Zombie_Generate: was too close to player."; }; - if (count _unitTypes == 0) then { - _unitTypes = getArray (missionConfigFile >> "CfgLoot" >> "Buildings" >> "Default" >> "zombieClass"); + // lets create an agent + _type = _unitTypes call BIS_fnc_selectRandom; + _radius = 5; + //_method = if (_doLoiter) then {"CAN_COLLIDE"} else {"NONE"}; + _agent = createAgent [_type, _position, [], _radius, "CAN_COLLIDE"]; + uiSleep 0.03; + + //add to global counter + dayz_spawnZombies = dayz_spawnZombies + 1; + dayz_CurrentNearByZombies = dayz_CurrentNearByZombies + 1; + dayz_currentGlobalZombies = dayz_currentGlobalZombies + 1; + + //Add some loot + if (0.3 > random 1) then { + _lootGroup = configFile >> "CfgVehicles" >> _type >> "zombieLoot"; + if (isText _lootGroup) then { + //_lootGroup = dayz_lootGroups find getText (_lootGroup); + _lootGroup = Loot_GetGroup(getText _lootGroup); + //[_agent, _lootGroup, 1] call loot_insert; + Loot_Insert(_agent, _lootGroup, 1); }; + }; - // lets create an agent - _type = _unitTypes call BIS_fnc_selectRandom; - _radius = 5; - //_method = if (_doLoiter) then {"CAN_COLLIDE"} else {"NONE"}; - _agent = createAgent [_type, _position, [], _radius, "CAN_COLLIDE"]; + _agent setVariable["agentObject",_agent]; + + if (!isNull _agent) then { + _agent setDir random 360; uiSleep 0.03; - - //add to global counter - dayz_spawnZombies = dayz_spawnZombies + 1; - dayz_CurrentNearByZombies = dayz_CurrentNearByZombies + 1; - dayz_currentGlobalZombies = dayz_currentGlobalZombies + 1; - - //Add some loot - if (0.3 > random 1) then { - _lootGroup = configFile >> "CfgVehicles" >> _type >> "zombieLoot"; - if (isText _lootGroup) then { - //_lootGroup = dayz_lootGroups find getText (_lootGroup); - _lootGroup = Loot_GetGroup(getText _lootGroup); - //[_agent, _lootGroup, 1] call loot_insert; - Loot_Insert(_agent, _lootGroup, 1); - }; - }; - - _agent setVariable["agentObject",_agent]; + _position = getPosATL _agent; - if (!isNull _agent) then { - _agent setDir random 360; - uiSleep 0.03; - _position = getPosATL _agent; - - _favStance = ( - switch ceil(random(3^0.5)^2) do { - //case 3: {"DOWN"}; // prone - case 2: {"middle"}; // Kneel "middle" - default {"Up"}; // stand-up - } - ); - _agent setUnitPos _favStance; - _agent setVariable ["stance", _favStance]; - _agent setVariable ["BaseLocation", _position]; - _agent setVariable ["doLoiter", _doLoiter]; // true: Z will be wandering, false: stay still - }; + _favStance = ( + switch ceil(random(3^0.5)^2) do { + //case 3: {"DOWN"}; // prone + case 2: {"middle"}; // Kneel "middle" + default {"Up"}; // stand-up + } + ); + _agent setUnitPos _favStance; + _agent setVariable ["stance", _favStance]; + _agent setVariable ["BaseLocation", _position]; + _agent setVariable ["doLoiter", _doLoiter]; // true: Z will be wandering, false: stay still }; }; diff --git a/SQF/dayz_code/init/variables.sqf b/SQF/dayz_code/init/variables.sqf index 4f441fe03..663a3c2bd 100644 --- a/SQF/dayz_code/init/variables.sqf +++ b/SQF/dayz_code/init/variables.sqf @@ -330,8 +330,7 @@ if (!isDedicated) then { inTraderCity = "Unknown Trader"; canPickup = false; pickupInit = false; - mouseOverCarry = false; //for carry slot since determining mouse pos doesn't work right - r_player_divideinvehicle = 0; + mouseOverCarry = false; //for carry slot since determining mouse pos doesn't work right dayz_currentWeaponHolders = 0; dayz_unsaved = false; dayz_scaleLight = 0; diff --git a/SQF/dayz_code/system/player_spawn_2.sqf b/SQF/dayz_code/system/player_spawn_2.sqf index 0f373434b..326dc3db0 100644 --- a/SQF/dayz_code/system/player_spawn_2.sqf +++ b/SQF/dayz_code/system/player_spawn_2.sqf @@ -7,7 +7,6 @@ _isPZombie = player isKindOf "PZombie_VB"; _radTimer = 0; _timer = diag_tickTime; -_timer1 = diag_tickTime; _timer30 = diag_Ticktime; _timer150 = diag_ticktime; _timerMonitor = diag_ticktime; @@ -346,46 +345,6 @@ while {1 == 1} do { }; }; - if ((diag_tickTime - _timer1) > 10) then { - _position = getPosATL player; - //Other Counters - dayz_currentGlobalZombies = count entities "zZombie_Base"; - _zeds = _position nearEntities ["zZombie_Base",200]; - dayz_spawnZombies = 0; - dayz_CurrentNearByZombies = 0; - //Current amounts - { - if (alive _x) then { - if (local _x) then { - dayz_spawnZombies = dayz_spawnZombies + 1; - }; - dayz_CurrentNearByZombies = dayz_CurrentNearByZombies + 1; - }; - } count _zeds; - - //dayz_spawnZombies = {alive _x AND local _x} count (_position nearEntities ["zZombie_Base",400]); - //dayz_CurrentNearByZombies = {alive _x} count (_position nearEntities ["zZombie_Base",400]); - dayz_currentWeaponHolders = count (_position nearObjects ["ReammoBox",200]); - - //Remove empty cardborad box's << this needs to be changed moved (action menu or close button) - { - //get contents - _weapons = getWeaponCargo _x; - _magazines = getMagazineCargo _x; - _backpacks = getBackpackCargo _x; - - if ((count (_weapons select 0) < 1) and (count (_magazines select 0) < 1) and (count (_backpacks select 0) < 1)) then { - //remove vehicle, Need to ask server to remove. - diag_log format["Deleting empty nearby box: %1",_x]; - PVDZ_obj_Delete = [_x,player]; - publicVariableServer "PVDZ_obj_Delete"; - }; - - } count (_position nearObjects ["CardboardBox",10]); - - _timer1 = diag_tickTime; - }; - //Two primary guns pickup exploit fix if ((DZE_TwoPrimaries < 2) && (primaryWeapon player != "") && (!(primaryWeapon player in MeleeWeapons)) && (dayz_onBack != "") && (!(dayz_onBack in MeleeWeapons)) && (isNull (findDisplay 106)) && (animationState player != "amovpknlmstpslowwrfldnon_amovpknlmstpsraswrfldnon" OR animationState player != "amovpercmstpslowwrfldnon_amovpercmstpsraswrfldnon" OR animationState player != "amovpercmstpslowwrfldnon_amovpercmstpsraswrfldnon")) then {