ACE3/addons/csw/functions/fnc_assemble_pickupTripod.sqf
johnb432 cd66f495ad
CSW - Improve tripod and weapon disassembly (#9915)
* Add disassembly for tripods when players have occupied launcher slots

* Update fnc_assemble_canDeployWeapon.sqf

* Update fnc_assemble_canPickupWeapon.sqf

* Revert file renaming (see #9777)

* Correct headers

* Update fnc_canPickupTripod.sqf

* Fixed checks and eject dead bodies

* Invert checks
2024-06-22 19:39:36 +02:00

75 lines
2.5 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: tcvm
* Picks up the tripod and adds it to the player launcher slot
*
* Arguments:
* 0: Tripod <OBJECT>
* 1: Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [cursorObject, player] call ace_csw_fnc_assemble_pickupTripod
*
* Public: No
*/
[{
params ["_tripod", "_player"];
TRACE_2("assemble_pickupTripod",_tripod,_player);
private _tripodClassname = getText (configOf _tripod >> QUOTE(ADDON) >> "disassembleTo");
private _pickupTime = getNumber (configFile >> "CfgWeapons" >> _tripodClassname >> QUOTE(ADDON) >> "pickupTime");
private _onFinish = {
params ["_args"];
_args params ["_tripod", "_player", "_tripodClassname"];
TRACE_3("assemble_pickupTripod finish",_tripod,_player,_tripodClassname);
// Save tripod position before it's deleted
private _tripodPos = getPosATL _tripod;
// Eject dead units (all crew are dead at this point, otherwise condition would have failed), but ignore UAV units
{
if (unitIsUAV _x) then {
_tripod deleteVehicleCrew _x;
} else {
moveOut _x;
};
} forEach (crew _tripod);
deleteVehicle _tripod;
[_player, "PutDown"] call EFUNC(common,doGesture);
// If the player has space, give it to him
if ((alive _player) && {(secondaryWeapon _player) == ""}) exitWith {
[_player, _tripodClassname] call CBA_fnc_addWeaponWithoutItems;
};
// Try to find existing weapon holders
private _weaponHolder = nearestObject [_tripodPos, "WeaponHolder"];
// If there are none or too far away, make a new one
if (isNull _weaponHolder || {_tripodPos distance _weaponHolder > 2}) then {
_weaponHolder = createVehicle ["GroundWeaponHolder", [0, 0, 0], [], 0, "CAN_COLLIDE"];
_weaponHolder setDir random [0, 180, 360];
_weaponHolder setVehiclePosition [_tripodPos, [], 0, "CAN_COLLIDE"]; // places object on surface below
};
_weaponHolder addWeaponCargoGlobal [_tripodClassname, 1];
};
private _condition = {
params ["_args"];
_args params ["_tripod"];
_tripod call FUNC(canPickupTripod)
};
TRACE_3("",_pickupTime,typeOf _tripod,_tripodClassname);
[TIME_PROGRESSBAR(_pickupTime), [_tripod, _player, _tripodClassname], _onFinish, {}, LLSTRING(PickupTripod_progressBar), _condition] call EFUNC(common,progressBar);
}, _this] call CBA_fnc_execNextFrame;