2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2020-01-10 21:12:34 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
2020-01-11 18:29:33 +00:00
|
|
|
* Makes the unit throw their currently selected weapon.
|
|
|
|
* Unit must be local and not inside a vehicle or attached to another object.
|
2020-01-10 21:12:34 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2020-01-11 01:58:40 +00:00
|
|
|
* 0: Unit <OBJECT>
|
2020-01-10 21:12:34 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Weapon Holder
|
|
|
|
*
|
|
|
|
* Example:
|
2023-09-09 06:17:24 +00:00
|
|
|
* player call ace_common_fnc_throwWeapon
|
2020-01-10 21:12:34 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2020-02-13 22:47:59 +00:00
|
|
|
#define OFFSET_LATERAL 0.59
|
2020-02-13 23:27:01 +00:00
|
|
|
#define THROW_ANGLE 63.43
|
2020-01-10 21:12:34 +00:00
|
|
|
#define THROW_VELOCITY 1.5
|
|
|
|
#define THROW_TORQUE 0.2
|
|
|
|
|
|
|
|
params ["_unit"];
|
2020-01-11 02:01:33 +00:00
|
|
|
|
2020-01-10 21:12:34 +00:00
|
|
|
private _weapon = currentWeapon _unit;
|
2020-01-11 18:29:33 +00:00
|
|
|
if (!isNull objectParent _unit || _weapon isEqualTo "") exitWith {objNull};
|
2020-01-10 21:12:34 +00:00
|
|
|
|
|
|
|
private _data = weaponsItems _unit select {_x select 0 == _weapon} select 0;
|
|
|
|
|
2020-02-13 22:15:41 +00:00
|
|
|
private _holder = createVehicle ["WeaponHolderSimulated", [0, 0, 0], [], 0, "CAN_COLLIDE"];
|
2020-01-10 21:12:34 +00:00
|
|
|
_holder addWeaponWithAttachmentsCargoGlobal [_data, 1];
|
|
|
|
|
|
|
|
private _vDir = _unit weaponDirection _weapon;
|
2020-02-13 22:15:28 +00:00
|
|
|
private _vLat = vectorNormalized (_vDir vectorCrossProduct [0, 0, 1]);
|
2020-01-10 21:12:34 +00:00
|
|
|
private _vUp = _vLat vectorCrossProduct _vDir;
|
|
|
|
|
2020-02-13 22:47:59 +00:00
|
|
|
private _position = _unit modelToWorldWorld (_unit selectionPosition "RightHand") vectorAdd (_vLat vectorMultiply OFFSET_LATERAL);
|
2020-02-13 23:27:01 +00:00
|
|
|
private _velocity = vectorNormalized (_vDir vectorAdd (_vUp vectorMultiply tan THROW_ANGLE)) vectorMultiply THROW_VELOCITY vectorAdd velocity _unit;
|
2020-01-10 21:12:34 +00:00
|
|
|
|
|
|
|
_unit removeWeapon _weapon;
|
|
|
|
_holder setPosWorld _position;
|
|
|
|
_holder setVectorDirAndUp [_vUp, _vLat];
|
|
|
|
_holder setVelocity _velocity;
|
|
|
|
_holder addTorque (call CBA_fnc_randomVector3D vectorMultiply THROW_TORQUE);
|
2020-01-18 17:12:01 +00:00
|
|
|
|
|
|
|
["ACE_weaponThrown", [_unit, _holder, _data]] call CBA_fnc_localEvent;
|
|
|
|
|
2020-01-10 21:12:34 +00:00
|
|
|
_holder // return
|