Skip to content

Commit

Permalink
fix(vehicle_create): handle creation server-side so cleanup can be done
Browse files Browse the repository at this point in the history
  • Loading branch information
pridit committed Jan 13, 2023
1 parent c603727 commit 18eec0b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
47 changes: 28 additions & 19 deletions vehicle_create/functions/fn_spawn.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define THIS_MODULE vehicle_create
#include "x_macros.sqf"
private ["_vehicle", "_type", "_offset", "_occupied", "_deployer", "_position", "_atv"];
private ["_vehicle", "_type", "_offset", "_occupied", "_deployer"];

PARAMS_2(_vehicle, _type);

Expand All @@ -16,33 +16,42 @@ if (count _occupied > 0) then {
};

if (count _occupied > 0) exitWith {
hint "Deploy point is already occupied by a vehicle";
if (hasInterface) then {
hint "Creation point is already occupied by a vehicle";
};

false
};

_position = _vehicle modelToWorld _offset;
if (hasInterface) then {
if !(isServer) then {
[gameLogic, "execVM", [_this, __function(spawn)]] call FUNC(network,mp);
};
};

_atv = createVehicle [_type, [_position select 0, _position select 1, 0], [], 0, "NONE"];
_atv setDir (if (_atv isKindOf "LandVehicle") then {direction _vehicle} else {direction _vehicle - 180});
_atv setVectorUp (vectorUp _vehicle);
_atv setPos [_position select 0, _position select 1, 0];
if (isServer) then {
private ["_position", "_new"];

if (!isNil QMODULE(vehicle_abandon)) then {
_atv setVariable [QGVAR(abandon), true, true];
};
_position = _vehicle modelToWorld _offset;

if (!isNil QMODULE(vehicle_respawn)) then {
_atv setVariable [QGVAR(respawnable), false, true];
};
_new = createVehicle [_type, [_position select 0, _position select 1, 0], [], 0, "NONE"];
_new setDir (if (_new isKindOf "LandVehicle") then {direction _vehicle} else {direction _vehicle - 180});
_new setVectorUp (vectorUp _vehicle);
_new setPos [_position select 0, _position select 1, 0];
_new engineOn true;

player reveal _atv;
if (!isNil QMODULE(vehicle_abandon)) then {
_new setVariable [QGVAR(abandon), true, true];
};

__addDead(_atv);
if (!isNil QMODULE(vehicle_respawn)) then {
_new setVariable [QGVAR(respawnable), false, true];
};

[true, "say3D", [_atv, QGVAR(sound_build), 20]] call FUNC(network,mp);
[true, "execVM", [[_atv], FUNCTION(vehicle,handle)]] call FUNC(network,mp);
[true, "say3D", [_new, QGVAR(sound_build), 20]] call FUNC(network,mp);
[true, "execVM", [[_new], FUNCTION(vehicle,handle)]] call FUNC(network,mp);

closeDialog 0;
__addDead(_new);

true
[true, "reveal", _new] call FUNC(network,mp);
};
2 changes: 2 additions & 0 deletions vehicle_menu/functions/fn_action.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ _refresh = (switch (if (typeName _lbData == "ARRAY") then {_lbData select 0} els
true
};

closeDialog 0;

false
};
};
Expand Down

0 comments on commit 18eec0b

Please sign in to comment.