Skip to content

Commit

Permalink
Prevent civilians from getting in police vehicles (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
3Mydlo3 authored Mar 7, 2024
1 parent 08382f6 commit fbd7a7f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 5 additions & 2 deletions addons/civilian/functions/fnc_getNearestVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*
* Arguments:
* 0: Position <POSITION/OBJECT>
* 1: Search radius <NUMBER> (Optional)
* 2: Filter function returning true for valid vehicles <FUNC> (Optional)
*
* Return Value:
* None
Expand All @@ -15,13 +17,14 @@
* Public: No
*/

params ["_pos", ["_radius", 500]];
params ["_pos", ["_radius", 500], ["_filterFunction", {true}]];

if (_pos isEqualType objNull) then {
_pos = getPos _pos;
};

private _nearbyVehicles = _pos nearEntities [["Air", "Car", "Motorcycle", "Tank"], _radius];
private _nearbyVehicles = _pos nearEntities [["Air", "Car", "Motorcycle", "Tank"], _radius]
select {[_x] call _filterFunction};

private _nearestVehicle = [_nearbyVehicles, _pos] call BIS_fnc_nearestPosition;

Expand Down
13 changes: 12 additions & 1 deletion addons/civilian_statemachine/functions/fnc_getNearestVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
* Public: No
*/

#define DEFAULT_SEARCH_RADIUS 500

params ["_group"];

[position leader _group] call EFUNC(civilian,getNearestVehicle);
private _filterFunction = {
params ["_vehicle"];

if (_vehicle getVariable [QEGVAR(police,isPoliceVehicle), false]) exitWith { false };
// TODO: Optionally filter for blacklisted areas

true
};

[position leader _group, DEFAULT_SEARCH_RADIUS, _filterFunction] call EFUNC(civilian,getNearestVehicle);
5 changes: 4 additions & 1 deletion addons/police/functions/fnc_spawnVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ if (_position isEqualTo []) exitWith {

// Spawn vehicle
INFO_2("Creating vehicle %1 at position %2",_vehicleClassname,str _position);
[EFUNC(vehicles,createVehicle), [_vehicleClassname, _position, _direction, true, false, true]] call CBA_fnc_execNextFrame;
[{
private _vehicle = _this call EFUNC(vehicles,createVehicle);
_vehicle setVariable [QGVAR(isPoliceVehicle), true, true];
}, [_vehicleClassname, _position, _direction, true, false, true]] call CBA_fnc_execNextFrame;

0 comments on commit fbd7a7f

Please sign in to comment.