Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 7.02 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.     /* private _muzzleAttachment = primaryWeaponItems player select 0;
  11.     if (!LIB_isSwitchingtoBayonet && (isNull (uinamespace getvariable ["BIS_fnc_arsenal_cam",objnull])) && (inputaction "nextWeapon" > 0 || inputaction "SwitchPrimary" > 0) && {!((weaponstate player select 1) == "lib_weap_bayonet") && (_muzzleAttachment isKindOf ["LIB_ACC_M44_Bayo",configFile >> "cfgWeapons"])}) then
  12.     {
  13.         systemchat "Switching to bayonet";
  14.         LIB_isSwitchingtoBayonet = true;
  15.         player forceWeaponFire  ["lib_weap_bayonet","lib_weap_bayonet"];
  16.         [] spawn {sleep 1; LIB_isSwitchingtoBayonet = false}; //Need a delay otherwise it will fire constantly
  17.     }; */
  18.     if ((isNull (uinamespace getvariable ["BIS_fnc_arsenal_cam",objnull])) && inputaction "defaultaction" > 0 && {(weaponstate player select 1) == "lib_weap_bayonet"}) then
  19.     {
  20.         [] spawn lib_bayonetAction;
  21.     };
  22. };
  23.  
  24. lib_fnc_drawVectors = {
  25.   private _posStart = param[0, [], [[]]];
  26.   private _posEnd = param[1, [], [[]]];
  27.   private _color = param[2, [1,1,1,1], [[]]];
  28.   private _label = param[3, "", [""]];
  29.   drawIcon3D ["\A3\ui_f\data\map\vehicleicons\iconObject_ca.paa", [1,1,1,1], _posStart, 0.3, 0.3, 0, "", 1, 0.05, "PuristaLight"];
  30.   drawIcon3D ["\A3\ui_f\data\map\vehicleicons\iconObject_ca.paa", [1,1,1,1], _posEnd, 0.3, 0.3, 0, "", 1, 0.05, "PuristaLight"];
  31.   drawIcon3D ["", [1,1,1,1], (_posStart vectorAdd _posEnd) vectorMultiply 0.5, 0.3, 0.3, 0, _label, 1, 0.05, "PuristaLight"];
  32.   drawLine3D [_posStart, _posEnd, _color];
  33. };
  34.  
  35. lib_fnc_offsetSelection = {
  36.   private _selection = param[0, "", [""]];
  37.   private _offset = param[1, [0,0,0], [[]]];
  38.   private _selectionPos = player selectionPosition _selection;
  39.  
  40.   private _origin = player modelToWorld [0,0,0];
  41.   private _X = [1,0,0];
  42.   private _Y = player worldToModel (_origin vectorAdd (player weaponDirection (primaryWeapon player)));
  43.   private _Z = _X vectorCrossProduct _Y;
  44.  
  45.   {
  46.       _selectionPos = _selectionPos vectorAdd (_x vectorMultiply (_offset select _forEachIndex)/100);
  47.   } forEach [_X, _Y, _Z];
  48.  
  49.     player modeltoWorld _selectionPos
  50. };
  51.  
  52. /*
  53. if (!isNil "cl_id") then {
  54.   removeMissionEventHandler ["EachFrame", cl_id]
  55. };
  56.  
  57. cl_id = addMissionEventHandler ["EachFrame", {
  58.   private _selection = "proxy:\a3\characters_f\proxies\binoculars.001";
  59.   private _pos = [_selection, lib_testBayonetoffset] call lib_fnc_offsetSelection;
  60.   private _wepDir = player weaponDirection (primaryWeapon player);
  61.   private _extension = 1;
  62.  
  63.   private _finalPos = _pos vectorAdd (_wepDir vectorMultiply _extension);
  64.  
  65.   [_pos, _finalPos] call lib_fnc_drawVectors;
  66. }]; */
  67.  
  68. lib_bayonetAction =
  69. {
  70.     private _unit = player;
  71.     if (lib_isStabbing || (weaponLowered _unit)) exitwith {};
  72.     private _muzzleAttachment = primaryWeaponItems _unit select 0;
  73.     private _builtInBayonet = [(configFile >> "cfgWeapons" >> primaryweapon _unit),"lib_hasBayonet",0] call BIS_fnc_returnConfigEntry;
  74.     _hasBayonet = if ((_muzzleAttachment isKindOf ["LIB_ACC_M44_Bayo",configFile >> "cfgWeapons"]) || _builtInBayonet == 1) then {true} else {false};
  75.  
  76.     if (!_hasBayonet) exitWith {};
  77.     lib_isStabbing = true;
  78.  
  79.     //Spawn the projectile early so it can be assigned to the unit. There's some delay with SetShotParents let alone network lag
  80.     private _offset = [(configFile >> "cfgWeapons" >> primaryweapon _unit >> "lib_weap_bayonet"),"lib_bayonetOffset",[0,0,0]] call BIS_fnc_returnConfigEntry;
  81.     private _offsetEnd = [(configFile >> "cfgWeapons" >> primaryweapon _unit >> "lib_weap_bayonet"),"lib_bayonetOffsetEnd",[0,0,0]] call BIS_fnc_returnConfigEntry;
  82.     private _selection = "proxy:\a3\characters_f\proxies\binoculars.001";
  83.   private _wepDir = _unit weaponDirection (primaryWeapon _unit);
  84.     private _unitDir = getdir _unit;
  85.     private _unitVelocity = velocityModelSpace _unit;
  86.     _unitvelocity set [1,((_unitvelocity select 1)+1.8)];
  87.  
  88.     private _projectiles = [];
  89.     private _extension = 1;
  90.  
  91.     private _pos = [_selection, _offsetEnd] call lib_fnc_offsetSelection;
  92.     private _finalPos = _pos vectorAdd (_wepDir vectorMultiply _extension);
  93.     _finalPos set [2, 6000];
  94.  
  95.     private _projectile = createvehicle ["lib_ammo_bayonet", _finalPos, [], 0, "CAN_COLLIDE"];
  96.     _projectile setdir _unitDir;
  97.     _projectile setVelocityModelSpace _unitvelocity;
  98.  
  99.     [_projectile,_unit, _unit] remoteExecCall ["lib_system_fnc_remoteSetShotParents", 2];
  100.  
  101.  
  102.  
  103.     if (lib_debug) then {systemchat str(_unitVelocity);};
  104.  
  105.     //Play the stabby gesture
  106.     _unit playAction "LIB_GestureBayonetStrike";
  107.     enableCamShake true;
  108.     addCamShake [1, 1, 5];
  109.     sleep 0.33; //Wait until the animation reachs a suitable point to cause damage...
  110.  
  111.     //Fire the bayonet weapon
  112.     [_projectile,_offset,_offsetEnd] call lib_bayonet_firedEH;
  113.     addCamShake [9, 1.9, 2];
  114.     sleep 1.85; //TODO the time of the bayonet strike
  115.     if (!isNil "lib_attachProjectile") then {
  116.         [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
  117.         lib_attachProjectile = nil;
  118.     };
  119.     lib_isStabbing = false;
  120. };
  121.  
  122. lib_bayonet_firedEH =
  123. {
  124.     private _projectile = _this select 0;
  125.     private _offset = _this select 1;
  126.     private _offsetEnd = _this select 2;
  127.     lib_melee_hitStart = time;
  128.     lib_attachProjectile = [{
  129.         private _arg = _this select 0;
  130.         private _projectile = _arg select 0;
  131.         private _offset = _arg select 1;
  132.         private _offsetEnd = _arg select 2;
  133.         private _selection = "proxy:\a3\characters_f\proxies\binoculars.001";
  134.         private _wepDir = player weaponDirection (primaryWeapon player);
  135.  
  136.         if (!alive _projectile) exitwith {
  137.             [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
  138.             lib_attachProjectile = nil;
  139.         }; //Bullets timed out, kill the check
  140.  
  141.         private _pos = [_selection, _offsetEnd] call lib_fnc_offsetSelection;
  142.         private _beginPos =  _pos vectorAdd (_wepDir vectorMultiply 1);
  143.         _pos = [_selection, _offset] call lib_fnc_offsetSelection;
  144.         private _endPos =  _pos vectorAdd (_wepDir vectorMultiply 1);
  145.  
  146.         private _intersects = lineIntersectsSurfaces  [(AGLToASL _beginPos), (AGLToASL _endPos), objNull, objNull, true, 32]; //Much better than setposing each frame...
  147.         [_beginPos,_endPos] call lib_fnc_drawVectors;
  148.         if (count _intersects > 0) then
  149.         {
  150.             private _impactPosASL = (_intersects select 0) select 0;
  151.             [_projectile, _impactPosASL, time] call lib_bayonet_dealDamage;
  152.         };
  153.     },0,[_projectile,_offset,_offsetEnd]] call LIB_Core_fnc_addPerFrameHandler
  154. };
  155.  
  156. lib_bayonet_dealDamage = {
  157.     [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
  158.     lib_attachProjectile = nil;
  159.     private _projectile = param [0, objNull, [objNull]];
  160.     private _impactPos = param [1, [], [[]]];
  161.     private _impactTime = param [2, 0, [0]];
  162.     if (isNull _projectile || {count _impactPos == 0} || {_impactTime == 0}) exitWith {
  163.         hintSilent "Aborted deal damage";
  164.     };
  165.     private _timeElapsed = _impactTime - lib_melee_hitStart;
  166.     private _damage = 1/(10*_timeElapsed + 1);
  167.     _projectile setPosASL _impactPos;
  168.     hint format ["Time elapsed: %1,\nDamage: %2", _timeElapsed, _damage];
  169. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement