Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 6.82 KB | None | 0 0
  1. if (isDedicated) exitwith {};
  2.  
  3. lib_debug = false;
  4. lib_isStabbing = false;
  5. LIB_isSwitchingtoBayonet = false;
  6.  
  7. lib_bayonetPerFrame =
  8. {
  9.     if ((isNull (uinamespace getvariable ["BIS_fnc_arsenal_cam",objnull])) && inputaction "defaultaction" > 0 && {(weaponstate player select 1) == "lib_weap_bayonet"}) then
  10.     {
  11.         [] spawn lib_bayonetAction;
  12.     };
  13. };
  14.  
  15. lib_fnc_drawVectors = {
  16.   private _posStart = param[0, [], [[]]];
  17.   private _posEnd = param[1, [], [[]]];
  18.   private _color = param[2, [1,1,1,1], [[]]];
  19.   private _label = param[3, "", [""]];
  20.   drawIcon3D ["\A3\ui_f\data\map\vehicleicons\iconObject_ca.paa", [1,1,1,1], _posStart, 0.3, 0.3, 0, "", 1, 0.05, "PuristaLight"];
  21.   drawIcon3D ["\A3\ui_f\data\map\vehicleicons\iconObject_ca.paa", [1,1,1,1], _posEnd, 0.3, 0.3, 0, "", 1, 0.05, "PuristaLight"];
  22.   drawIcon3D ["", [1,1,1,1], (_posStart vectorAdd _posEnd) vectorMultiply 0.5, 0.3, 0.3, 0, _label, 1, 0.05, "PuristaLight"];
  23.   drawLine3D [_posStart, _posEnd, _color];
  24. };
  25.  
  26. lib_fnc_offsetSelection = {
  27.   private _selection = param[0, "", [""]];
  28.   private _offset = param[1, [0,0,0], [[]]];
  29.   private _selectionPos = player selectionPosition _selection;
  30.  
  31.   private _origin = player modelToWorld [0,0,0];
  32.   private _X = [1,0,0];
  33.   private _Y = player worldToModel (_origin vectorAdd (player weaponDirection (primaryWeapon player)));
  34.   private _Z = _X vectorCrossProduct _Y;
  35.  
  36.   {
  37.       _selectionPos = _selectionPos vectorAdd (_x vectorMultiply (_offset select _forEachIndex)/100);
  38.   } forEach [_X, _Y, _Z];
  39.  
  40.     player modeltoWorld _selectionPos
  41. };
  42.  
  43. lib_bayonetAction =
  44. {
  45.     private _unit = player;
  46.     if (lib_isStabbing || (weaponLowered _unit)) exitwith {};
  47.     private _muzzleAttachment = primaryWeaponItems _unit select 0;
  48.     private _builtInBayonet = [(configFile >> "cfgWeapons" >> primaryweapon _unit),"lib_hasBayonet",0] call BIS_fnc_returnConfigEntry;
  49.     _hasBayonet = if ((_muzzleAttachment isKindOf ["LIB_ACC_M44_Bayo",configFile >> "cfgWeapons"]) || _builtInBayonet == 1) then {true} else {false};
  50.  
  51.     if (!_hasBayonet) exitWith {};
  52.     lib_isStabbing = true;
  53.  
  54.     private _offset = [(configFile >> "cfgWeapons" >> primaryweapon _unit >> "lib_weap_bayonet"),"lib_bayonetOffset",[0,0,0]] call BIS_fnc_returnConfigEntry;
  55.     private _offsetEnd = [(configFile >> "cfgWeapons" >> primaryweapon _unit >> "lib_weap_bayonet"),"lib_bayonetOffsetEnd",[0,0,0]] call BIS_fnc_returnConfigEntry;
  56.     private _selection = "proxy:\a3\characters_f\proxies\binoculars.001";
  57.     private _wepDir = _unit weaponDirection (primaryWeapon _unit);
  58.     private _unitDir = getdir _unit;
  59.     private _projectiles = [];
  60.     private _extension = 1;
  61.  
  62.     private _pos = [_selection, _offsetEnd] call lib_fnc_offsetSelection;
  63.     private _finalPos = _pos vectorAdd (_wepDir vectorMultiply _extension);
  64.     _finalPos set [2, 6000];
  65.  
  66.     private _projectile = createvehicle ["lib_ammo_bayonet", _finalPos, [], 0, "CAN_COLLIDE"];
  67.     _projectile setdir _unitDir;
  68.  
  69.  
  70.     [_projectile,_unit, _unit] remoteExecCall ["lib_system_fnc_remoteSetShotParents", 2];
  71.  
  72.  
  73.  
  74.     if (lib_debug) then {systemchat str(_unitVelocity);};
  75.  
  76.     _unit playAction "LIB_GestureBayonetStrike";
  77.     enableCamShake true;
  78.     addCamShake [1, 1, 5];
  79.     sleep 0.33;
  80.  
  81.     [_projectile,_offset,_offsetEnd] call lib_bayonet_firedEH;
  82.     addCamShake [9, 1.9, 2];
  83.     sleep 1.85;
  84.     if (!isNil "lib_attachProjectile") then {
  85.         [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
  86.         lib_attachProjectile = nil;
  87.     };
  88.     lib_isStabbing = false;
  89. };
  90.  
  91. lib_bayonet_firedEH =
  92. {
  93.     private _projectile = _this select 0;
  94.     private _offset = _this select 1;
  95.     private _offsetEnd = _this select 2;
  96.     lib_melee_hitStart = time;
  97.     lib_attachProjectile = [{
  98.         private _arg = _this select 0;
  99.         private _projectile = _arg select 0;
  100.         private _offset = _arg select 1;
  101.         private _offsetEnd = _arg select 2;
  102.         private _selection = "proxy:\a3\characters_f\proxies\binoculars.001";
  103.         private _wepDir = player weaponDirection (primaryWeapon player);
  104.  
  105.     if (!alive _projectile) exitwith {
  106.             [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
  107.             lib_attachProjectile = nil;
  108.         };
  109.  
  110.         private _pos = [_selection, _offsetEnd] call lib_fnc_offsetSelection;
  111.         private _beginPos =  _pos vectorAdd (_wepDir vectorMultiply 1);
  112.         _pos = [_selection, _offset] call lib_fnc_offsetSelection;
  113.         private _endPos =  _pos vectorAdd (_wepDir vectorMultiply 1);
  114.  
  115.         private _intersects = lineIntersectsSurfaces  [(AGLToASL _beginPos), (AGLToASL _endPos), objNull, objNull, true, 32]; //Much better than setposing each frame...
  116.         [_beginPos,_endPos] call lib_fnc_drawVectors;
  117.         if (count _intersects > 0) then
  118.         {
  119.             private _impactPosASL = (_intersects select 0) select 0;
  120.             private _normalToImpact = ((_intersects select 0) select 1) vectorMultiply -1;
  121.             private _target = (_intersects select 0) select 3;
  122.             [_projectile, _impactPosASL, time, _normalToImpact, _target] call lib_bayonet_dealDamage;
  123.         };
  124.     },0,[_projectile,_offset,_offsetEnd]] call LIB_Core_fnc_addPerFrameHandler
  125. };
  126.  
  127. lib_bayonet_dealDamage = {
  128.     [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
  129.     lib_attachProjectile = nil;
  130.     private _projectile = param [0, objNull, [objNull]];
  131.     private _impactPos = param [1, [], [[]]];
  132.     private _impactTime = param [2, 0, [0]];
  133.     private _normal = param [3, [], [[]]];
  134.     private _target = param [4, objNull, [objNull]];
  135.     if (isNull _projectile || {count _impactPos == 0} || {_impactTime == 0}) exitWith {
  136.         hintSilent "Aborted deal damage";
  137.     };
  138.     private _timeElapsed = _impactTime - lib_melee_hitStart;
  139.     private _damage = (1/(10*(_timeElapsed - 0.1) + 1)) min 1;
  140.     private _unitVelocity = velocity player;
  141.     private _targetVelocity = [0,0,0];
  142.     if (!isNull _target) then {
  143.       _targetVelocity = velocity _target;
  144.     };
  145.     private _antiNormal = [(_normal select 0), -(_normal select 2), (_normal select 1)];
  146.     private _orthogonal = _antiNormal vectorCrossProduct _normal;
  147.     _projectile setVectorDir _normal;
  148.     if ((abs (_antiNormal select 2)) > (abs (_orthogonal select 2))) then {
  149.         _orthogonal = _antiNormal;
  150.     };
  151.     _projectile setVectorUp _orthogonal;
  152.     private _speed = vectorMagnitude (_unitVelocity vectorDiff _targetVelocity);
  153.     _projectile setVelocityModelSpace [0, (_speed+1.389) * _damage, 0];
  154.     systemchat format ["%1 expected damage, vector %2, impactPos %3",(2 * ((3.6 * (velocityModelSpace _projectile select 1)) / 5)),_orthogonal,_impactPos];
  155.     _projectile setPosASL _impactPos;
  156.     hint format ["Time elapsed: %1,\nDamage: %2,\nRelative Speed: %3\nTarget: %4", _timeElapsed, _damage, _speed, _target];
  157. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement