From 35f5628accd1b403b91b6009f0a23876feff4342 Mon Sep 17 00:00:00 2001 From: McDiod Date: Sun, 24 Feb 2019 16:41:38 +0100 Subject: [PATCH] add staticVehicles param to fn_populateArea --- README.md | 16 ++++++++------- functions/common/fn_populateArea.sqf | 20 +++++++++++-------- functions/spawn/fn_createSideRoadVehicles.sqf | 4 ++-- package.json | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 8461c35a..a8d5b786 100644 --- a/README.md +++ b/README.md @@ -189,12 +189,14 @@ headgear | Array - All classnames of clothes that civilians may wear. Manually populates an area with civilians. These civilians count towards the maximum amount. ### Syntax -`[area,amount,excludeFromCleanup] call grad_civs_fnc_populateArea` - -Parameter | Explanation -----------|------------------------------------------------------------------------------------------------------------------------------------------------- -area | Array / Object - Area array in format `[a, b, angle, isRectangle]` or array of area arrays or gamelogic synchronzed to one or multiple triggers. -amount | Number - Amount of civilians to spawn. -excludeFromCleanup (optional) | Bool - Sets if these civilians will be excluded from cleanup when no players are near. (default: true) +`[area,amount,excludeFromCleanup,staticVehicles,staticVehiclesMax] call grad_civs_fnc_populateArea` + +Parameter | Explanation +------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------- +area | Array / Object - Area array in format `[a, b, angle, isRectangle]` or array of area arrays or gamelogic synchronzed to one or multiple triggers. +amount | Number - Amount of civilians to spawn. +excludeFromCleanup (optional) | Bool - Sets if these civilians will be excluded from cleanup when no players are near. (default: true) +staticVehicles (optional) | Bool - Sets if static vehicles will be created in the area. (default: false) +staticVehiclesMax (optional) | Number - Maximum amount of static vehicles to create. Actual amount is based on number of roads and houses in area. ![](http://i.imgur.com/Cimaz4c.jpg) diff --git a/functions/common/fn_populateArea.sqf b/functions/common/fn_populateArea.sqf index 4d751209..3dfa6445 100644 --- a/functions/common/fn_populateArea.sqf +++ b/functions/common/fn_populateArea.sqf @@ -4,7 +4,7 @@ if (!isServer) exitWith {}; if (!canSuspend) exitWith {_this spawn grad_civs_fnc_populateArea}; if (isNil "GRAD_CIVS_ONFOOTUNITS") exitWith {ERROR("grad-civs has not been initialized.")}; -params ["_area",["_amount",20],["_excludeFromCleanup",true]]; +params ["_area",["_amount",20],["_excludeFromCleanup",true],["_staticCars",false],["_staticCarsMax",20]]; private _areas = if (_area isEqualType objNull) then {synchronizedObjects _area} else {[_area]}; private _maxLoops = _amount * 5; @@ -16,7 +16,7 @@ private _maxLoops = _amount * 5; if (count _spawnPos > 0) then { _civ = [_spawnPos] call grad_civs_fnc_spawnCivilian; if (_excludeFromCleanup) then { - _civ setVariable ["grad_civs_excludeFromCleanup",true]; + _civ setVariable ["grad_civs_excludeFromCleanup",true]; }; GRAD_CIVS_ONFOOTUNITS pushBack _civ; GRAD_CIVS_ONFOOTCOUNT = GRAD_CIVS_ONFOOTCOUNT + 1; @@ -28,14 +28,18 @@ private _maxLoops = _amount * 5; if (_i > _maxLoops) exitWith {}; }; - _vehAmount = if (_x isEqualType objNull) then { - (triggerArea _x) params [["_a",0],["_b",0]]; - [getPos _x,_a max _b,1,30,15] call grad_civs_fnc_createSideRoadVehicles - } else { - _x params ["_center",["_a",0],["_b",0]]; - [_center,_a max _b,1,1,15] call grad_civs_fnc_createSideRoadVehicles + private _vehAmount = 0; + if (_staticCars) then { + _vehAmount = if (_x isEqualType objNull) then { + (triggerArea _x) params [["_a",0],["_b",0]]; + [getPos _x,_a max _b,5,5,15,_staticCarsMax] call grad_civs_fnc_createSideRoadVehicles + } else { + _x params ["_center",["_a",0],["_b",0]]; + [_center,_a max _b,5,5,15,_staticCarsMax] call grad_civs_fnc_createSideRoadVehicles + }; }; + INFO_2("Populated area with %1 civilians and %2 static cars.",_amountSpawned,_vehAmount); false diff --git a/functions/spawn/fn_createSideRoadVehicles.sqf b/functions/spawn/fn_createSideRoadVehicles.sqf index e0560b77..9328f6fc 100644 --- a/functions/spawn/fn_createSideRoadVehicles.sqf +++ b/functions/spawn/fn_createSideRoadVehicles.sqf @@ -1,6 +1,6 @@ #include "..\..\component.hpp" -params ["_locationPosition","_locationRadius","_amountFactor","_houseFactor","_minDistance"]; +params ["_locationPosition","_locationRadius","_amountFactor","_houseFactor","_minDistance","_maxAmount"]; if (count GRAD_CIVS_VEHICLES == 0) exitWith {}; private _vehiclePositions = []; @@ -24,7 +24,7 @@ private _fnc_isSafe = { private _thesePositions = []; private _roads = _locationPosition nearRoads _locationRadius; private _vehiclesToCreate = (round ((count _roads) * 0.07 * _amountFactor)); -_vehiclesToCreate = round (2 max (_vehiclesToCreate + ((random (_vehiclesToCreate * 0.4)) - _vehiclesToCreate * 0.2))); +_vehiclesToCreate = round ((2 max (_vehiclesToCreate + ((random (_vehiclesToCreate * 0.4)) - _vehiclesToCreate * 0.2))) min _maxAmount); while {count _roads > 0 && count _thesePositions < _vehiclesToCreate} do { private ["_vehPos","_canCreate","_chosenDirection","_offRoadFound"]; diff --git a/package.json b/package.json index ca138d27..7475ab26 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grad-civs", "description": "ambient civilians", - "version": "0.4.1", + "version": "0.4.2", "contributors": [ { "name": "nomisum"