ACE3/addons/vehicles/functions/fnc_startEngine.sqf
Serg Vergun fa6da1ae7c
Vehicles - Add configurable engine startup delay (#8327)
* Add configurable engine startup delay

* add suggested change

Add space char

Co-authored-by: Dystopian <sddex@ya.ru>

* Squashed commit of the following:

commit 14f5483d8fa49d36effa8b18a3df392ed39b19da
Author: Serg Vergun <1197314+severgun@users.noreply.github.com>
Date:   Fri Jul 23 20:23:52 2021 +0300

    Add 0 cap and update docs

commit e3ce7f273882b3f4e2cba916c39b506f857b20db
Author: severgun <sewergun@gmail.com>
Date:   Fri Jul 23 12:42:42 2021 +0300

    add parentheses

commit b36eedc61b5e6bb868c37901bd4191767fbdaff8
Author: severgun <sewergun@gmail.com>
Date:   Fri Jul 23 12:34:30 2021 +0300

    Add ability to set engine startup delay per vehicle by script

* Change function name

* add suggested exitWith condition

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* Update docs/wiki/framework/vehicles-framework.md

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

Co-authored-by: Dystopian <sddex@ya.ru>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
2021-07-27 12:47:07 -05:00

36 lines
977 B
Plaintext

#include "script_component.hpp"
/*
* Author: commy2
* Delays engine start of vehicle.
*
* Arguments:
* 0: Vehicle <OBJECT>
* 1: Is Engine on <BOOL>
*
* Return Value:
* None
*
* Example:
* [vehicle player, false] call ace_vehicles_fnc_startEngine
*
* Public: No
*/
params ["_vehicle", "_isEngineOn"];
if (!_isEngineOn || {floor abs speed _vehicle > 0 || {!isNull isVehicleCargo _vehicle}}) exitWith {};
private _startupDelay = _vehicle getVariable [QGVAR(engineStartDelay), getNumber (configOf _vehicle >> QGVAR(engineStartDelay))];
if (_startupDelay <= 0) exitWith {};
[{
params ["_args", "_idPFH"];
_args params ["_vehicle", "_time", "_direction"];
if (CBA_missionTime > _time) exitWith { [_idPFH] call CBA_fnc_removePerFrameHandler; };
_vehicle setVelocity [0, 0, 0];
_vehicle setVectorDirAndUp _direction;
} , 0, [_vehicle, CBA_missionTime + _startupDelay, [vectorDir _vehicle, vectorUp _vehicle]]] call CBA_fnc_addPerFrameHandler;