Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent civilians from getting in police vehicles #73

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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;