Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 4.74 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.     private _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 _unitDir = getdir _unit;
  56.     private _unitVelocity = velocityModelSpace _unit;
  57.     _unitvelocity set [1,((_unitvelocity select 1)+1.8)];
  58.  
  59.     //Spawn the projectile early so it can be assigned to the unit. There's some delay with SetShotParents let alone network lag
  60.     private _bulletPos = (getPos _unit) vectorAdd [0,0,worldSize];
  61.     private _projectile = createvehicle ["lib_ammo_bayonet", _bulletPos, [], 0, "CAN_COLLIDE"];
  62.     _projectile setdir _unitDir;
  63.     _projectile setVelocityModelSpace _unitvelocity;
  64.  
  65.     [_projectile,_unit, _unit] remoteExecCall ["lib_system_fnc_remoteSetShotParents", 2];
  66.  
  67.     //Play the stabby gesture
  68.     _unit playAction "LIB_GestureBayonetStrike";
  69.     enableCamShake true;
  70.     addCamShake [1, 1, 5];
  71.     sleep 0.33; //Wait until the animation reachs a suitable point to cause damage...
  72.  
  73.     //Fire the bayonet weapon
  74.     [_projectile, _unit] call lib_bayonet_firedEH;
  75.     addCamShake [9, 1.9, 2];
  76.     sleep 1.85; //TODO the time of the bayonet strike
  77.  
  78.     lib_isStabbing = false;
  79.  
  80. };
  81.  
  82. lib_bayonet_firedEH =
  83. {
  84.     private _projectile = _this select 0;
  85.     private _unit = _this select 1;
  86.     private _offset = [(configFile >> "cfgWeapons" >> primaryweapon _unit >> "lib_weap_bayonet"),"lib_bayonetOffset",[0,0,0]] call BIS_fnc_returnConfigEntry;
  87.     private _offsetEnd = [(configFile >> "cfgWeapons" >> primaryweapon _unit >> "lib_weap_bayonet"),"lib_bayonetOffsetEnd",[0,0,0]] call BIS_fnc_returnConfigEntry;
  88.     lib_projectile = _projectile;
  89.     lib_attachProjectile =
  90.     [{
  91.         private _arg = _this select 0;
  92.         private _projectile = _arg select 0;
  93.         private _offset = _arg select 1;
  94.         private _offsetEnd = _arg select 2;
  95.         private _selection = "proxy:\a3\characters_f\proxies\binoculars.001";
  96.         private _wepDir = player weaponDirection (primaryWeapon player);
  97.  
  98.         if (!alive _projectile) exitwith {[lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;}; //Bullets timed out, kill the check
  99.  
  100.         private _pos = [_selection, _offsetEnd] call lib_fnc_offsetSelection;
  101.         private _beginPos =  _pos vectorAdd (_wepDir vectorMultiply 1);
  102.         _pos = [_selection, _offset] call lib_fnc_offsetSelection;
  103.         private _endPos =  _pos vectorAdd (_wepDir vectorMultiply 1);
  104.  
  105.         private _intersects = lineIntersectsSurfaces  [(AGLToASL _beginPos), (AGLToASL _endPos), objNull, objNull, true, 32]; //Much better than setposing each frame...
  106.         //systemchat str(_intersects);
  107.         [_beginPos,_endPos] call lib_fnc_drawVectors;
  108.         if (count _intersects > 0) then
  109.         {
  110.             _projectile setposasl ((_intersects select 0) select 0);
  111.  
  112.             [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
  113.         };
  114.     },0,[_projectile,_offset,_offsetEnd]] call LIB_Core_fnc_addPerFrameHandler;
  115. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement