Advertisement
Guest User

Untitled

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