mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
resting: changed spawn for PFH, reorganized code
This commit is contained in:
parent
f9de90c6f9
commit
cded65d9a9
@ -1,4 +1,7 @@
|
||||
#include "script_component.hpp"
|
||||
|
||||
PREP(getIntersection);
|
||||
PREP(hasBipod);
|
||||
PREP(pfhCheckRest);
|
||||
PREP(restWeapon);
|
||||
PREP(unRestWeapon);
|
||||
|
@ -6,7 +6,7 @@ class CfgPatches {
|
||||
weapons[] = {};
|
||||
requiredVersion = REQUIRED_VERSION;
|
||||
requiredAddons[] = {"ace_common"};
|
||||
author[] = {"KoffeinFlummi", "TaoSensai"};
|
||||
author[] = {"KoffeinFlummi", "TaoSensai", "CAA-Picard"};
|
||||
authorUrl = "https://github.com/KoffeinFlummi/";
|
||||
VERSION_CONFIG;
|
||||
};
|
||||
|
70
addons/resting/functions/fnc_getIntersection.sqf
Normal file
70
addons/resting/functions/fnc_getIntersection.sqf
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Author: KoffeinFlummi, edited by commy2 and CAA-Picard
|
||||
*
|
||||
* Prepares intersects
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit
|
||||
* 1: vehicle
|
||||
* 2: weapon
|
||||
*
|
||||
* Return Values:
|
||||
* [_intersectsMiddle, _intersectsLeft, _intersectsRight, _intersectsDown]
|
||||
*
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
EXPLODE_3_PVT(_this,_unit,_vehicle,_weapon);
|
||||
|
||||
private ["_weaponPos", "_weaponDir", "_weaponPosDown"];
|
||||
|
||||
_weaponPos = ATLtoASL (_unit modelToWorld (_unit selectionPosition "RightHand"));
|
||||
_weaponDir = _unit weaponDirection _weapon;
|
||||
_weaponPosDown = _weaponPos vectorAdd [0,0,-MAXHEIGHT];
|
||||
|
||||
private ["_checkPosMiddle", "_checkPosLeft", "_checkPosRight", "_checkPosDown"];
|
||||
|
||||
_checkPosMiddle = [
|
||||
(_weaponPos select 0) + MAXDISTANCE * (_weaponDir select 0),
|
||||
(_weaponPos select 1) + MAXDISTANCE * (_weaponDir select 1),
|
||||
(_weaponPos select 2) + MAXDISTANCE * (_weaponDir select 2)
|
||||
];
|
||||
_checkPosLeft = [
|
||||
(_weaponPos select 0) + MAXDISTANCE * sin (((_weaponDir select 0) atan2 (_weaponDir select 1)) + 360 - MAXANGLE),
|
||||
(_weaponPos select 1) + MAXDISTANCE * cos (((_weaponDir select 0) atan2 (_weaponDir select 1)) + 360 - MAXANGLE),
|
||||
(_weaponPos select 2) + MAXDISTANCE * (_weaponDir select 2)
|
||||
];
|
||||
_checkPosRight = [
|
||||
(_weaponPos select 0) + MAXDISTANCE * sin (((_weaponDir select 0) atan2 (_weaponDir select 1)) + MAXANGLE),
|
||||
(_weaponPos select 1) + MAXDISTANCE * cos (((_weaponDir select 0) atan2 (_weaponDir select 1)) + MAXANGLE),
|
||||
(_weaponPos select 2) + MAXDISTANCE * (_weaponDir select 2)
|
||||
];
|
||||
_checkPosDown = [
|
||||
(_weaponPos select 0) + MAXDISTANCE * (_weaponDir select 0),
|
||||
(_weaponPos select 1) + MAXDISTANCE * (_weaponDir select 1),
|
||||
(_weaponPos select 2) + MAXDISTANCE * (_weaponDir select 2) - MAXHEIGHT
|
||||
];
|
||||
|
||||
/* UNCOMMENT THIS FOR DEBUGGING
|
||||
weaponPos = ASLtoATL _weaponPos;
|
||||
weaponPosDown = ASLtoATL _weaponPosDown;
|
||||
checkPosMiddle = ASLtoATL _checkPosMiddle;
|
||||
checkPosLeft = ASLtoATL _checkPosLeft;
|
||||
checkPosRight = ASLtoATL _checkPosRight;
|
||||
checkPosDown = ASLtoATL _checkPosDown;
|
||||
|
||||
onEachFrame {
|
||||
drawLine3D [weaponPos, checkPosMiddle, [1,0,0,1]];
|
||||
drawLine3D [weaponPos, checkPosLeft, [1,0,0,1]];
|
||||
drawLine3D [weaponPos, checkPosRight, [1,0,0,1]];
|
||||
drawLine3D [weaponPosDown, checkPosDown, [1,0,0,1]];
|
||||
};*/
|
||||
|
||||
private ["_intersectsMiddle", "_intersectsLeft", "_intersectsRight", "_intersectsDown"];
|
||||
|
||||
_intersectsMiddle = lineIntersects [_weaponPos, _checkPosMiddle];
|
||||
_intersectsLeft = lineIntersects [_weaponPos, _checkPosLeft];
|
||||
_intersectsRight = lineIntersects [_weaponPos, _checkPosRight];
|
||||
_intersectsDown = lineIntersects [_weaponPos, _checkPosDown] || {terrainIntersectASL [_weaponPosDown, _checkPosDown]};
|
||||
|
||||
[_intersectsMiddle, _intersectsLeft, _intersectsRight, _intersectsDown]
|
@ -1,10 +1,20 @@
|
||||
// by commy2
|
||||
/*
|
||||
* Author: Commy2
|
||||
*
|
||||
* Check if the weapon has a bipod
|
||||
*
|
||||
* Arguments:
|
||||
* 0: weapon
|
||||
*
|
||||
* Return Values:
|
||||
* Boolean
|
||||
*
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private ["_weapon", "_config"];
|
||||
|
||||
_weapon = _this select 0;
|
||||
EXPLODE_1_PVT(_this,_weapon);
|
||||
|
||||
private ["_config"];
|
||||
_config = configFile >> "CfgWeapons" >> _weapon;
|
||||
|
||||
getNumber (_config >> "ACE_Bipod") == 1 ||
|
||||
|
41
addons/resting/functions/fnc_pfhCheckRest.sqf
Normal file
41
addons/resting/functions/fnc_pfhCheckRest.sqf
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Author: KoffeinFlummi, edited by commy2 and CAA-Picard
|
||||
*
|
||||
* PFH that check for player moving away, changing weapon, etc
|
||||
* and unrests the weapon if necessary
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit
|
||||
* 1: vehicle
|
||||
* 2: weapon
|
||||
* 3: rested position
|
||||
*
|
||||
* Return Values:
|
||||
* None
|
||||
*
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
EXPLODE_2_PVT(_this,_params,_pfhId);
|
||||
EXPLODE_4_PVT(_params,_unit,_vehicle,_weapon,_restedPosition);
|
||||
|
||||
if !(_unit getVariable ["ACE_weaponRested", false]) exitWith {
|
||||
[_pfhId] call cba_fnc_removePerFrameHandler;
|
||||
};
|
||||
|
||||
private ["_intersects"];
|
||||
_intersects = _params call FUNC(getIntersection);
|
||||
|
||||
if (
|
||||
_unit != ACE_player
|
||||
|| {_vehicle != vehicle _unit}
|
||||
|| {inputAction "reloadMagazine" != 0}
|
||||
|| {weaponLowered _unit}
|
||||
|| {speed _unit > 1}
|
||||
|| {currentWeapon _unit != _weapon}
|
||||
|| {getPosASL _unit distanceSqr _restedPosition > 1}
|
||||
|| {!(true in _intersects)}
|
||||
) exitWith {
|
||||
[_pfhId] call cba_fnc_removePerFrameHandler;
|
||||
[_unit, _vehicle, _weapon] call FUNC(unRestWeapon)
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Author: KoffeinFlummi, edited by commy2
|
||||
* Author: KoffeinFlummi, edited by commy2 and CAA-Picard
|
||||
*
|
||||
* Rests the player's weapon if possible.
|
||||
*
|
||||
@ -12,124 +12,18 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
#define RESTEDRECOIL 0.6
|
||||
#define BIPODRECOIL 0.3
|
||||
#define MAXDISTANCE 1
|
||||
#define MAXANGLE 15
|
||||
#define MAXHEIGHT 0.45
|
||||
#define CAMSHAKE [1,0.5,5]
|
||||
|
||||
private ["_unit", "_vehicle", "_weapon"];
|
||||
|
||||
_unit = _this select 0;
|
||||
_vehicle = _this select 1;
|
||||
_weapon = _this select 2;
|
||||
EXPLODE_3_PVT(_this,_unit,_vehicle,_weapon);
|
||||
|
||||
if (_weapon != primaryWeapon _unit) exitWith {};
|
||||
|
||||
// UNREST THE WEAPON
|
||||
private "_fnc_unRestWeapon";
|
||||
|
||||
_fnc_unRestWeapon = {
|
||||
addCamShake CAMSHAKE;
|
||||
|
||||
private "_animation";
|
||||
_animation = animationState _unit;
|
||||
|
||||
if (_unit getVariable ["ACE_bipodDeployed", false]) then {
|
||||
_unit setUnitRecoilCoefficient (unitRecoilCoefficient _unit / BIPODRECOIL);
|
||||
if (_animation find "_ace_deploy" != -1) then {
|
||||
//[_unit, [_animation, "_ace_deploy", ""] call CBA_fnc_replace, 2] call EFUNC(common,doAnimation);
|
||||
_unit switchMove ([_animation, "_ace_deploy", ""] call CBA_fnc_replace);
|
||||
};
|
||||
|
||||
private "_picture";
|
||||
_picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
|
||||
[localize "STR_ACE_Resting_BipodUndeployed", _picture] call EFUNC(common,displayTextPicture);
|
||||
|
||||
} else {
|
||||
_unit setUnitRecoilCoefficient (unitRecoilCoefficient _unit / RESTEDRECOIL);
|
||||
if (_animation find "_ace_rested" != -1) then {
|
||||
//[_unit, [_animation, "_ace_rested", ""] call CBA_fnc_replace, 2] call EFUNC(common,doAnimation);
|
||||
_unit switchMove ([_animation, "_ace_rested", ""] call CBA_fnc_replace);
|
||||
};
|
||||
|
||||
private "_picture";
|
||||
_picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
|
||||
[localize "STR_ACE_Resting_WeaponLifted", _picture] call EFUNC(common,displayTextPicture);
|
||||
};
|
||||
|
||||
_unit setVariable ["ACE_weaponRested", false];
|
||||
_unit setVariable ["ACE_bipodDeployed", false];
|
||||
};
|
||||
|
||||
if (_unit getVariable ["ACE_weaponRested", false]) exitWith {call _fnc_unRestWeapon};
|
||||
if (_unit getVariable ["ACE_weaponRested", false]) exitWith {_this call FUNC(unRestWeapon)};
|
||||
|
||||
// exit if this is not an available animation
|
||||
if (!isClass (configFile >> "CfgMovesMaleSdr" >> "States" >> format ["%1_ace_deploy", animationState _unit])) exitWith {};
|
||||
|
||||
// PREPARE INTERSECTS
|
||||
private "_fnc_getIntersection";
|
||||
|
||||
_fnc_getIntersection = {
|
||||
private ["_weaponPos", "_weaponDir", "_weaponPosDown"];
|
||||
|
||||
_weaponPos = ATLtoASL (_unit modelToWorld (_unit selectionPosition "RightHand"));
|
||||
_weaponDir = _unit weaponDirection _weapon;
|
||||
_weaponPosDown = _weaponPos vectorAdd [0,0,-MAXHEIGHT];
|
||||
|
||||
private ["_checkPosMiddle", "_checkPosLeft", "_checkPosRight", "_checkPosDown"];
|
||||
|
||||
_checkPosMiddle = [
|
||||
(_weaponPos select 0) + MAXDISTANCE * (_weaponDir select 0),
|
||||
(_weaponPos select 1) + MAXDISTANCE * (_weaponDir select 1),
|
||||
(_weaponPos select 2) + MAXDISTANCE * (_weaponDir select 2)
|
||||
];
|
||||
_checkPosLeft = [
|
||||
(_weaponPos select 0) + MAXDISTANCE * sin (((_weaponDir select 0) atan2 (_weaponDir select 1)) + 360 - MAXANGLE),
|
||||
(_weaponPos select 1) + MAXDISTANCE * cos (((_weaponDir select 0) atan2 (_weaponDir select 1)) + 360 - MAXANGLE),
|
||||
(_weaponPos select 2) + MAXDISTANCE * (_weaponDir select 2)
|
||||
];
|
||||
_checkPosRight = [
|
||||
(_weaponPos select 0) + MAXDISTANCE * sin (((_weaponDir select 0) atan2 (_weaponDir select 1)) + MAXANGLE),
|
||||
(_weaponPos select 1) + MAXDISTANCE * cos (((_weaponDir select 0) atan2 (_weaponDir select 1)) + MAXANGLE),
|
||||
(_weaponPos select 2) + MAXDISTANCE * (_weaponDir select 2)
|
||||
];
|
||||
_checkPosDown = [
|
||||
(_weaponPos select 0) + MAXDISTANCE * (_weaponDir select 0),
|
||||
(_weaponPos select 1) + MAXDISTANCE * (_weaponDir select 1),
|
||||
(_weaponPos select 2) + MAXDISTANCE * (_weaponDir select 2) - MAXHEIGHT
|
||||
];
|
||||
|
||||
/* UNCOMMENT THIS FOR DEBUGGING
|
||||
weaponPos = ASLtoATL _weaponPos;
|
||||
weaponPosDown = ASLtoATL _weaponPosDown;
|
||||
checkPosMiddle = ASLtoATL _checkPosMiddle;
|
||||
checkPosLeft = ASLtoATL _checkPosLeft;
|
||||
checkPosRight = ASLtoATL _checkPosRight;
|
||||
checkPosDown = ASLtoATL _checkPosDown;
|
||||
|
||||
onEachFrame {
|
||||
drawLine3D [weaponPos, checkPosMiddle, [1,0,0,1]];
|
||||
drawLine3D [weaponPos, checkPosLeft, [1,0,0,1]];
|
||||
drawLine3D [weaponPos, checkPosRight, [1,0,0,1]];
|
||||
drawLine3D [weaponPosDown, checkPosDown, [1,0,0,1]];
|
||||
};*/
|
||||
|
||||
private ["_intersectsMiddle", "_intersectsLeft", "_intersectsRight", "_intersectsDown"];
|
||||
|
||||
_intersectsMiddle = lineIntersects [_weaponPos, _checkPosMiddle];
|
||||
_intersectsLeft = lineIntersects [_weaponPos, _checkPosLeft];
|
||||
_intersectsRight = lineIntersects [_weaponPos, _checkPosRight];
|
||||
_intersectsDown = lineIntersects [_weaponPos, _checkPosDown] || {terrainIntersectASL [_weaponPosDown, _checkPosDown]};
|
||||
|
||||
[_intersectsMiddle, _intersectsLeft, _intersectsRight, _intersectsDown]
|
||||
};
|
||||
|
||||
// CHECK FOR APPROPRIATE SURFACE
|
||||
private "_intersects";
|
||||
|
||||
_intersects = call _fnc_getIntersection;
|
||||
_intersects = _this call FUNC(getIntersection);
|
||||
|
||||
if (true in _intersects) then {
|
||||
_unit setVariable ["ACE_weaponRested", true];
|
||||
@ -163,30 +57,6 @@ if (true in _intersects) then {
|
||||
[localize "STR_ACE_Resting_WeaponRested", _picture] call EFUNC(common,displayTextPicture);
|
||||
};
|
||||
|
||||
// CHECK FOR PLAYER MOVING AWAY, CHANGING WEAPONS ETC
|
||||
[_unit, _vehicle, _weapon, _fnc_unRestWeapon, _fnc_getIntersection, _restedPosition] spawn {
|
||||
_unit = _this select 0;
|
||||
_vehicle = _this select 1;
|
||||
_weapon = _this select 2;
|
||||
_fnc_unRestWeapon = _this select 3;
|
||||
_fnc_getIntersection = _this select 4;
|
||||
_restedPosition = _this select 5;
|
||||
|
||||
while {_unit getVariable ["ACE_weaponRested", false]} do {
|
||||
_intersects = call _fnc_getIntersection;
|
||||
|
||||
if (
|
||||
_unit != ACE_player
|
||||
|| {_vehicle != vehicle _unit}
|
||||
|| {inputAction "reloadMagazine" != 0}
|
||||
|| {weaponLowered _unit}
|
||||
|| {speed _unit > 1}
|
||||
|| {currentWeapon _unit != _weapon}
|
||||
|| {getPosASL _unit distanceSqr _restedPosition > 1}
|
||||
|| {!(true in _intersects)}
|
||||
) exitWith {call _fnc_unRestWeapon};
|
||||
|
||||
sleep 0.3;
|
||||
};
|
||||
};
|
||||
// Launch a PFH to check for player moving away, changing weapon, etc
|
||||
[FUNC(pfhCheckRest), 0.2, [_unit, _vehicle, _weapon, _restedPosition] ] call CBA_fnc_addPerFrameHandler;
|
||||
};
|
||||
|
48
addons/resting/functions/fnc_unRestWeapon.sqf
Normal file
48
addons/resting/functions/fnc_unRestWeapon.sqf
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Author: KoffeinFlummi, edited by commy2 and CAA-Picard
|
||||
*
|
||||
* Un Rests the player's weapon
|
||||
*
|
||||
* Arguments:
|
||||
* 0: unit
|
||||
* 1: vehicle
|
||||
* 2: weapon
|
||||
*
|
||||
* Return Values:
|
||||
* None
|
||||
*
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
EXPLODE_3_PVT(_this,_unit,_vehicle,_weapon);
|
||||
|
||||
addCamShake CAMSHAKE;
|
||||
|
||||
private "_animation";
|
||||
_animation = animationState _unit;
|
||||
|
||||
if (_unit getVariable ["ACE_bipodDeployed", false]) then {
|
||||
_unit setUnitRecoilCoefficient (unitRecoilCoefficient _unit / BIPODRECOIL);
|
||||
if (_animation find "_ace_deploy" != -1) then {
|
||||
//[_unit, [_animation, "_ace_deploy", ""] call CBA_fnc_replace, 2] call EFUNC(common,doAnimation);
|
||||
_unit switchMove ([_animation, "_ace_deploy", ""] call CBA_fnc_replace);
|
||||
};
|
||||
|
||||
private "_picture";
|
||||
_picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
|
||||
[localize "STR_ACE_Resting_BipodUndeployed", _picture] call EFUNC(common,displayTextPicture);
|
||||
|
||||
} else {
|
||||
_unit setUnitRecoilCoefficient (unitRecoilCoefficient _unit / RESTEDRECOIL);
|
||||
if (_animation find "_ace_rested" != -1) then {
|
||||
//[_unit, [_animation, "_ace_rested", ""] call CBA_fnc_replace, 2] call EFUNC(common,doAnimation);
|
||||
_unit switchMove ([_animation, "_ace_rested", ""] call CBA_fnc_replace);
|
||||
};
|
||||
|
||||
private "_picture";
|
||||
_picture = getText (configFile >> "CfgWeapons" >> _weapon >> "picture");
|
||||
[localize "STR_ACE_Resting_WeaponLifted", _picture] call EFUNC(common,displayTextPicture);
|
||||
};
|
||||
|
||||
_unit setVariable ["ACE_weaponRested", false];
|
||||
_unit setVariable ["ACE_bipodDeployed", false];
|
@ -10,3 +10,10 @@
|
||||
#endif
|
||||
|
||||
#include "\z\ace\Addons\main\script_macros.hpp"
|
||||
|
||||
#define RESTEDRECOIL 0.6
|
||||
#define BIPODRECOIL 0.3
|
||||
#define MAXDISTANCE 1
|
||||
#define MAXANGLE 15
|
||||
#define MAXHEIGHT 0.45
|
||||
#define CAMSHAKE [1,0.5,5]
|
||||
|
Loading…
Reference in New Issue
Block a user