Skip to content

Commit 0f265df

Browse files
authored
API - Fix Rack functions when called from 3DEN init box (#1378)
1 parent 507f6ca commit 0f265df

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

addons/api/fnc_initVehicleRacks.sqf

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,30 @@ if ([_vehicle] call FUNC(areVehicleRacksInitialized)) exitWith {
3838
false
3939
};
4040

41-
// A player must do the action of initialising a rack
42-
private _player = objNull;
43-
44-
private _vehiclePresetName = [_vehicle] call FUNC(getVehicleRacksPreset);
45-
if (_condition isEqualTo {} && {_vehiclePresetName isNotEqualTo ""}) then {
46-
_player = ([] call CBA_fnc_players) select 0;
47-
} else {
48-
private _players = [] call CBA_fnc_players;
49-
private _index = _players findIf {[_x] call _condition};
50-
51-
if (_index == -1) then {
52-
WARNING_1("No unit found for condition %1 - defaulting to first player",_condition);
53-
_index = 0;
41+
// Exec the rest on the next frame, to prevent issues if the function is called in a 3DEN init box
42+
[{
43+
params ["_vehicle", "_condition"];
44+
45+
// A player must do the action of initialising a rack
46+
private _player = objNull;
47+
48+
private _vehiclePresetName = [_vehicle] call FUNC(getVehicleRacksPreset);
49+
if (_condition isEqualTo {} && {_vehiclePresetName isNotEqualTo ""}) then {
50+
_player = ([] call CBA_fnc_players) select 0;
51+
} else {
52+
private _players = [] call CBA_fnc_players;
53+
private _index = _players findIf {[_x] call _condition};
54+
55+
if (_index == -1) then {
56+
WARNING_1("No unit found for condition %1 - defaulting to first player",_condition);
57+
_index = 0;
58+
};
59+
_player = _players select _index;
5460
};
55-
_player = _players select _index;
56-
};
5761

58-
_vehicle setVariable [QEGVAR(sys_rack,initPlayer), _player, true];
62+
_vehicle setVariable [QEGVAR(sys_rack,initPlayer), _player, true];
5963

60-
[QEGVAR(sys_rack,initVehicleRacks), [_vehicle], _player] call CBA_fnc_targetEvent;
64+
[QEGVAR(sys_rack,initVehicleRacks), [_vehicle], _player] call CBA_fnc_targetEvent;
65+
}, [_vehicle, _condition]] call CBA_fnc_execNextFrame;
6166

6267
true

addons/api/fnc_removeAllRacksFromVehicle.sqf

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,26 @@ if (!_success) exitWith {
4040
WARNING_1("Vehicle %1 failed to initialise",_vehicle);
4141
};
4242

43-
// A player must do the action of removing a rack
44-
private _player = objNull;
45-
46-
if (isDedicated) then {
47-
// Pick the first player
48-
_player = (allPlayers - entities "HeadlessClient_F") select 0;
49-
} else {
50-
_player = acre_player;
51-
};
52-
5343
[{
54-
params ["_vehicle", "_player"];
44+
params ["_vehicle"];
5545
[_vehicle] call FUNC(areVehicleRacksInitialized)
5646
}, {
57-
params ["_vehicle", "_player"];
47+
params ["_vehicle"];
48+
49+
// A player must do the action of removing a rack
50+
private _player = objNull;
51+
52+
if (isDedicated) then {
53+
// Pick the first player
54+
_player = (allPlayers - entities "HeadlessClient_F") select 0;
55+
} else {
56+
_player = acre_player;
57+
};
5858

5959
private _racks = [_vehicle] call FUNC(getVehicleRacks);
6060
for "_i" from (count _racks) - 1 to 0 step -1 do {
6161
[QEGVAR(sys_rack,removeVehicleRacks), [_vehicle, _racks select _i], _player] call CBA_fnc_targetEvent;
6262
};
63-
}, [_vehicle, _player]] call CBA_fnc_waitUntilAndExecute;
63+
}, [_vehicle]] call CBA_fnc_waitUntilAndExecute;
6464

6565
true

0 commit comments

Comments
 (0)