ACE3/addons/dragging/functions/fnc_createClone.sqf

81 lines
2.3 KiB
Plaintext
Raw Normal View History

2023-10-03 06:46:27 +00:00
#include "..\script_component.hpp"
/*
2023-07-20 17:42:35 +00:00
* Author: BaerMitUmlaut, johnb43
* Creates a draggable / carryable clone of a dead unit.
*
* Arguments:
* 0: Dead unit <OBJECT>
*
* Return Value:
2023-07-20 17:42:35 +00:00
* Cloned unit <OBJECT>
*
* Example:
* [player] call ace_dragging_fnc_createClone;
*
* Public: No
*/
2024-01-07 17:02:12 +00:00
2023-07-20 17:42:35 +00:00
params ["_target"];
2023-07-21 17:24:25 +00:00
// Get current position of unit, -10 m below surface
private _posATL = getPosATL _target;
_posATL set [2, -10];
private _clone = createVehicle [QGVAR(clone), _posATL];
2023-07-20 17:42:35 +00:00
// Clone loadout
2023-07-21 17:24:25 +00:00
[_clone, _target call CBA_fnc_getLoadout] call CBA_fnc_setLoadout;
2023-07-20 17:42:35 +00:00
2024-01-09 18:37:24 +00:00
// Hide unit until it can be moved below terrain
2023-07-21 17:24:25 +00:00
private _isObjectHidden = isObjectHidden _target;
2024-01-07 15:48:40 +00:00
if (!_isObjectHidden) then {
2023-07-21 17:24:25 +00:00
[QEGVAR(common,hideObjectGlobal), [_target, true]] call CBA_fnc_serverEvent;
};
2024-01-09 18:37:24 +00:00
private _simulationEnabled = simulationEnabled _target;
if (_simulationEnabled) then {
[QEGVAR(common,enableSimulationGlobal), [_target, false]] call CBA_fnc_serverEvent;
};
2023-07-21 17:24:25 +00:00
private _isInRemainsCollector = isInRemainsCollector _target;
// Make sure corpse isn't deleted by engine's garbage collector
if (_isInRemainsCollector) then {
removeFromRemainsCollector [_target];
};
2024-01-08 07:40:28 +00:00
// Make sure clone has the same wound textures as the corpse
private _targetDamage = damage _target;
if (_targetDamage != 0) then {
_clone setDamage (_targetDamage min 0.99); // Don't kill the clone
};
private _relevantHitpoints = ["HitHead", "HitBody", "HitHands", "HitLegs"];
{
private _hitpointDamage = _target getHitPointDamage _x;
_clone setHitPointDamage [_x, _hitpointDamage min 0.99];
} forEach _relevantHitpoints;
2023-07-20 17:42:35 +00:00
// Disable all damage
_clone allowDamage false;
2024-01-09 18:37:24 +00:00
_clone setVariable [QGVAR(original), [_target, _isInRemainsCollector, _isObjectHidden, _simulationEnabled], true];
// Turn on PhysX so that the corpse doesn't desync when moved
[QEGVAR(common,awake), [_target, true]] call CBA_fnc_globalEvent;
[{
params ["_target", "_posATL"];
// Make sure PhysX is on
[QEGVAR(common,awake), [_target, true]] call CBA_fnc_globalEvent;
// Move unit below terrain in order to hide it and remove its inventory access
_target setPosATL _posATL;
}, [_target, _posATL], 0.1] call CBA_fnc_waitAndExecute;
2023-07-20 17:42:35 +00:00
// Sets the facial expression
[[QGVAR(cloneCreated), [_target, _clone]] call CBA_fnc_globalEventJIP, _clone] call CBA_fnc_removeGlobalEventJIP;
_clone