Skip to content

Commit

Permalink
Use CBA_fnc_waitAndExecute instead of scheduled sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
mrschick committed Sep 9, 2023
1 parent c4a8e4c commit 9cd507b
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions addons/sys_rack/fnc_rackChildrenActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -129,40 +129,37 @@ if (_mountedRadio == "") then { // Empty
localize LSTRING(useRadio),
"",
{
[_this] spawn {
params ["_this"];

// Find the work knob position that corresponds to the mounted radio
private _mountedRadio = _this select 2;
private _newWorkPos = 0;
private _wiredRacks = [vehicle acre_player, acre_player, EGVAR(sys_intercom,activeIntercom), "wiredRacks"] call EFUNC(sys_intercom,getStationConfiguration);
{
private _rack = _x select 0;
private _radio = [_rack] call FUNC(getMountedRadio);
if (_radio isEqualTo _mountedRadio) exitWith {
_newWorkPos = _forEachIndex + 1;
};
} forEach _wiredRacks;
// Find the work knob position that corresponds to the mounted radio
private _mountedRadio = _this select 2;
private _newWorkPos = 0;
private _wiredRacks = [vehicle acre_player, acre_player, EGVAR(sys_intercom,activeIntercom), "wiredRacks"] call EFUNC(sys_intercom,getStationConfiguration);
{
private _rack = _x select 0;
private _radio = [_rack] call FUNC(getMountedRadio);
if (_radio isEqualTo _mountedRadio) exitWith {
_newWorkPos = _forEachIndex + 1;
};
} forEach _wiredRacks;

// Open FFCS GUI
[] call EFUNC(sys_intercom,openGui);
sleep 0.5;
// Open FFCS GUI
[] call EFUNC(sys_intercom,openGui);

// Find current knob position and the direction to move it to the desired position
private _curWorkPos = [vehicle acre_player, acre_player, EGVAR(sys_intercom,activeIntercom), "workKnob"] call EFUNC(sys_intercom,getStationConfiguration);
private _direction = 0;
if (_newWorkPos < _curWorkPos) then {
_direction = 1;
};
// Find current knob position and the direction to move it to the desired position
private _curWorkPos = [vehicle acre_player, acre_player, EGVAR(sys_intercom,activeIntercom), "workKnob"] call EFUNC(sys_intercom,getStationConfiguration);
private _direction = 0;
if (_newWorkPos < _curWorkPos) then {
_direction = 1;
};

// Turn the work knob N times towards the desired position
// After a delay, turn the work knob N times towards the desired position
[{
params ["_direction", "_curWorkPos", "_newWorkPos"];
private _i = 0;
while {_i < abs (_curWorkPos - _newWorkPos)} do {
[0, _direction] call EFUNC(sys_intercom,vic3ffcsOnWorkKnobPress);
_i = _i + 1;
sleep 0.2;
};
};
}, [_direction, _curWorkPos, _newWorkPos], 0.5] call CBA_fnc_waitAndExecute;
},
{true},
{},
Expand Down

0 comments on commit 9cd507b

Please sign in to comment.