From ea3f400fc1143c69e064954a1d7c0bc78d700bee Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 10 Jan 2020 22:12:34 +0100 Subject: [PATCH 01/11] add function to throw current weapon --- addons/hitreactions/XEH_PREP.hpp | 1 + .../functions/fnc_throwWeapon.sqf | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 addons/hitreactions/functions/fnc_throwWeapon.sqf diff --git a/addons/hitreactions/XEH_PREP.hpp b/addons/hitreactions/XEH_PREP.hpp index 7701b8ef19..7d037789ca 100644 --- a/addons/hitreactions/XEH_PREP.hpp +++ b/addons/hitreactions/XEH_PREP.hpp @@ -1,3 +1,4 @@ +PREP(throwWeapon); PREP(fallDown); PREP(getRandomAnimation); diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf new file mode 100644 index 0000000000..0ea8b84811 --- /dev/null +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -0,0 +1,42 @@ +#include "script_component.hpp" +/* + * Author: commy2 + * Makes the unit throw their currently selected weapon. + * + * Arguments: + * 0: unit + * + * Return Value: + * Weapon Holder + * + * Example: + * player call ACE_hitreactions_fnc_throwWeapon + * + * Public: No + */ + +#define THROW_VELOCITY 1.5 +#define THROW_TORQUE 0.2 + +params ["_unit"]; +private _weapon = currentWeapon _unit; +if (_weapon isEqualTo "") exitWith {objNull}; + +private _data = weaponsItems _unit select {_x select 0 == _weapon} select 0; + +private _holder = createVehicle ["WeaponHolderSimulated", [0,0,0], [], 0, "CAN_COLLIDE"]; +_holder addWeaponWithAttachmentsCargoGlobal [_data, 1]; + +private _vDir = _unit weaponDirection _weapon; +private _vLat = vectorNormalized (_vDir vectorCrossProduct [0,0,1]); +private _vUp = _vLat vectorCrossProduct _vDir; + +private _position = _unit modelToWorldWorld (_unit selectionPosition "RightHand") vectorAdd (_vLat vectorMultiply 0.59); +private _velocity = vectorNormalized (_vDir vectorAdd (_vUp vectorMultiply 2)) vectorMultiply THROW_VELOCITY vectorAdd velocity _unit; + +_unit removeWeapon _weapon; +_holder setPosWorld _position; +_holder setVectorDirAndUp [_vUp, _vLat]; +_holder setVelocity _velocity; +_holder addTorque (call CBA_fnc_randomVector3D vectorMultiply THROW_TORQUE); +_holder // return From b736928259a69ec368fad9ea81765c07decc754a Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 10 Jan 2020 22:12:59 +0100 Subject: [PATCH 02/11] add function to throw current weapon --- addons/hitreactions/functions/fnc_throwWeapon.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf index 0ea8b84811..aacc1c7591 100644 --- a/addons/hitreactions/functions/fnc_throwWeapon.sqf +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: commy2 - * Makes the unit throw their currently selected weapon. + * Makes the unit throw their currently selected weapon. Unit must be local. * * Arguments: * 0: unit From c97bd2fb013ecc812bda9fcb25e348816251d116 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 11 Jan 2020 02:58:40 +0100 Subject: [PATCH 03/11] Update addons/hitreactions/functions/fnc_throwWeapon.sqf Co-Authored-By: jonpas --- addons/hitreactions/functions/fnc_throwWeapon.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf index aacc1c7591..484be0a04a 100644 --- a/addons/hitreactions/functions/fnc_throwWeapon.sqf +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -4,7 +4,7 @@ * Makes the unit throw their currently selected weapon. Unit must be local. * * Arguments: - * 0: unit + * 0: Unit * * Return Value: * Weapon Holder From bd2dc7367bb465b1a7b7008db5756a6227825a8c Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 11 Jan 2020 02:58:51 +0100 Subject: [PATCH 04/11] Update addons/hitreactions/functions/fnc_throwWeapon.sqf Co-Authored-By: jonpas --- addons/hitreactions/functions/fnc_throwWeapon.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf index 484be0a04a..65e86f12cb 100644 --- a/addons/hitreactions/functions/fnc_throwWeapon.sqf +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -10,7 +10,7 @@ * Weapon Holder * * Example: - * player call ACE_hitreactions_fnc_throwWeapon + * player call ace_hitreactions_fnc_throwWeapon * * Public: No */ From 518006e864110ecc6ff46969fe241fe73028f1d7 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 11 Jan 2020 03:01:33 +0100 Subject: [PATCH 05/11] Update addons/hitreactions/functions/fnc_throwWeapon.sqf Co-Authored-By: jonpas --- addons/hitreactions/functions/fnc_throwWeapon.sqf | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf index 65e86f12cb..0eddf9d582 100644 --- a/addons/hitreactions/functions/fnc_throwWeapon.sqf +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -19,6 +19,7 @@ #define THROW_TORQUE 0.2 params ["_unit"]; + private _weapon = currentWeapon _unit; if (_weapon isEqualTo "") exitWith {objNull}; From 353feb6400d7f122857046335a8ede1ec023b324 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 11 Jan 2020 19:29:33 +0100 Subject: [PATCH 06/11] don't drop if inside a vehicle --- addons/hitreactions/XEH_PREP.hpp | 2 +- addons/hitreactions/functions/fnc_throwWeapon.sqf | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/hitreactions/XEH_PREP.hpp b/addons/hitreactions/XEH_PREP.hpp index 7d037789ca..53f2d60eb6 100644 --- a/addons/hitreactions/XEH_PREP.hpp +++ b/addons/hitreactions/XEH_PREP.hpp @@ -1,4 +1,4 @@ -PREP(throwWeapon); PREP(fallDown); PREP(getRandomAnimation); +PREP(throwWeapon); diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf index aacc1c7591..5a2938ed07 100644 --- a/addons/hitreactions/functions/fnc_throwWeapon.sqf +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -1,7 +1,8 @@ #include "script_component.hpp" /* * Author: commy2 - * Makes the unit throw their currently selected weapon. Unit must be local. + * Makes the unit throw their currently selected weapon. + * Unit must be local and not inside a vehicle or attached to another object. * * Arguments: * 0: unit @@ -20,7 +21,7 @@ params ["_unit"]; private _weapon = currentWeapon _unit; -if (_weapon isEqualTo "") exitWith {objNull}; +if (!isNull objectParent _unit || _weapon isEqualTo "") exitWith {objNull}; private _data = weaponsItems _unit select {_x select 0 == _weapon} select 0; From 8a16c9da1b946989ebfb60026b8f2febfb633c53 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 18 Jan 2020 18:12:01 +0100 Subject: [PATCH 07/11] ACE_weaponThrown event --- addons/hitreactions/functions/fnc_throwWeapon.sqf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf index 77d380ec10..ae77db9c02 100644 --- a/addons/hitreactions/functions/fnc_throwWeapon.sqf +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -41,4 +41,7 @@ _holder setPosWorld _position; _holder setVectorDirAndUp [_vUp, _vLat]; _holder setVelocity _velocity; _holder addTorque (call CBA_fnc_randomVector3D vectorMultiply THROW_TORQUE); + +["ACE_weaponThrown", [_unit, _holder, _data]] call CBA_fnc_localEvent; + _holder // return From 0fc3cb02011af8ac38a216c2024150a1502f096e Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 13 Feb 2020 23:15:28 +0100 Subject: [PATCH 08/11] Update addons/hitreactions/functions/fnc_throwWeapon.sqf Co-Authored-By: jonpas --- addons/hitreactions/functions/fnc_throwWeapon.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf index ae77db9c02..e0d78536ca 100644 --- a/addons/hitreactions/functions/fnc_throwWeapon.sqf +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -30,7 +30,7 @@ private _holder = createVehicle ["WeaponHolderSimulated", [0,0,0], [], 0, "CAN_C _holder addWeaponWithAttachmentsCargoGlobal [_data, 1]; private _vDir = _unit weaponDirection _weapon; -private _vLat = vectorNormalized (_vDir vectorCrossProduct [0,0,1]); +private _vLat = vectorNormalized (_vDir vectorCrossProduct [0, 0, 1]); private _vUp = _vLat vectorCrossProduct _vDir; private _position = _unit modelToWorldWorld (_unit selectionPosition "RightHand") vectorAdd (_vLat vectorMultiply 0.59); From 0572ead9ca427b2cb720ea1e7311ea20f8c7e63f Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 13 Feb 2020 23:15:41 +0100 Subject: [PATCH 09/11] Update addons/hitreactions/functions/fnc_throwWeapon.sqf Co-Authored-By: jonpas --- addons/hitreactions/functions/fnc_throwWeapon.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf index e0d78536ca..4ad0ea81c7 100644 --- a/addons/hitreactions/functions/fnc_throwWeapon.sqf +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -26,7 +26,7 @@ if (!isNull objectParent _unit || _weapon isEqualTo "") exitWith {objNull}; private _data = weaponsItems _unit select {_x select 0 == _weapon} select 0; -private _holder = createVehicle ["WeaponHolderSimulated", [0,0,0], [], 0, "CAN_COLLIDE"]; +private _holder = createVehicle ["WeaponHolderSimulated", [0, 0, 0], [], 0, "CAN_COLLIDE"]; _holder addWeaponWithAttachmentsCargoGlobal [_data, 1]; private _vDir = _unit weaponDirection _weapon; From 2d071f459fbec89e1249082ed0e483d8903f60ac Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 13 Feb 2020 23:47:59 +0100 Subject: [PATCH 10/11] macro for lateral offset --- addons/hitreactions/functions/fnc_throwWeapon.sqf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf index 4ad0ea81c7..e3d28df36a 100644 --- a/addons/hitreactions/functions/fnc_throwWeapon.sqf +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -16,6 +16,7 @@ * Public: No */ +#define OFFSET_LATERAL 0.59 #define THROW_VELOCITY 1.5 #define THROW_TORQUE 0.2 @@ -33,7 +34,7 @@ private _vDir = _unit weaponDirection _weapon; private _vLat = vectorNormalized (_vDir vectorCrossProduct [0, 0, 1]); private _vUp = _vLat vectorCrossProduct _vDir; -private _position = _unit modelToWorldWorld (_unit selectionPosition "RightHand") vectorAdd (_vLat vectorMultiply 0.59); +private _position = _unit modelToWorldWorld (_unit selectionPosition "RightHand") vectorAdd (_vLat vectorMultiply OFFSET_LATERAL); private _velocity = vectorNormalized (_vDir vectorAdd (_vUp vectorMultiply 2)) vectorMultiply THROW_VELOCITY vectorAdd velocity _unit; _unit removeWeapon _weapon; From d6c26eb89dd0f2c49d9bacdb0030fdee7e4a991f Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 14 Feb 2020 00:27:01 +0100 Subject: [PATCH 11/11] macro for throw angle --- addons/hitreactions/functions/fnc_throwWeapon.sqf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/hitreactions/functions/fnc_throwWeapon.sqf b/addons/hitreactions/functions/fnc_throwWeapon.sqf index e3d28df36a..bc2936e101 100644 --- a/addons/hitreactions/functions/fnc_throwWeapon.sqf +++ b/addons/hitreactions/functions/fnc_throwWeapon.sqf @@ -17,6 +17,7 @@ */ #define OFFSET_LATERAL 0.59 +#define THROW_ANGLE 63.43 #define THROW_VELOCITY 1.5 #define THROW_TORQUE 0.2 @@ -35,7 +36,7 @@ private _vLat = vectorNormalized (_vDir vectorCrossProduct [0, 0, 1]); private _vUp = _vLat vectorCrossProduct _vDir; private _position = _unit modelToWorldWorld (_unit selectionPosition "RightHand") vectorAdd (_vLat vectorMultiply OFFSET_LATERAL); -private _velocity = vectorNormalized (_vDir vectorAdd (_vUp vectorMultiply 2)) vectorMultiply THROW_VELOCITY vectorAdd velocity _unit; +private _velocity = vectorNormalized (_vDir vectorAdd (_vUp vectorMultiply tan THROW_ANGLE)) vectorMultiply THROW_VELOCITY vectorAdd velocity _unit; _unit removeWeapon _weapon; _holder setPosWorld _position;