Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include "\a3\editor_f\Data\Scripts\dikCodes.h"
- if (isDedicated) exitwith {};
- lib_debug = false;
- lib_isStabbing = false;
- LIB_isSwitchingtoBayonet = false;
- lib_bayonetPerFrame =
- {
- /* private _muzzleAttachment = primaryWeaponItems player select 0;
- 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
- {
- systemchat "Switching to bayonet";
- LIB_isSwitchingtoBayonet = true;
- player forceWeaponFire ["lib_weap_bayonet","lib_weap_bayonet"];
- [] spawn {sleep 1; LIB_isSwitchingtoBayonet = false}; //Need a delay otherwise it will fire constantly
- }; */
- if ((isNull (uinamespace getvariable ["BIS_fnc_arsenal_cam",objnull])) && inputaction "defaultaction" > 0 && {(weaponstate player select 1) == "lib_weap_bayonet"}) then
- {
- [] spawn lib_bayonetAction;
- };
- };
- lib_fnc_drawVectors = {
- private _posStart = param[0, [], [[]]];
- private _posEnd = param[1, [], [[]]];
- private _color = param[2, [1,1,1,1], [[]]];
- private _label = param[3, "", [""]];
- drawIcon3D ["\A3\ui_f\data\map\vehicleicons\iconObject_ca.paa", [1,1,1,1], _posStart, 0.3, 0.3, 0, "", 1, 0.05, "PuristaLight"];
- drawIcon3D ["\A3\ui_f\data\map\vehicleicons\iconObject_ca.paa", [1,1,1,1], _posEnd, 0.3, 0.3, 0, "", 1, 0.05, "PuristaLight"];
- drawIcon3D ["", [1,1,1,1], (_posStart vectorAdd _posEnd) vectorMultiply 0.5, 0.3, 0.3, 0, _label, 1, 0.05, "PuristaLight"];
- drawLine3D [_posStart, _posEnd, _color];
- };
- lib_fnc_offsetSelection = {
- private _selection = param[0, "", [""]];
- private _offset = param[1, [0,0,0], [[]]];
- private _selectionPos = player selectionPosition _selection;
- private _origin = player modelToWorld [0,0,0];
- private _X = [1,0,0];
- private _Y = player worldToModel (_origin vectorAdd (player weaponDirection (primaryWeapon player)));
- private _Z = _X vectorCrossProduct _Y;
- {
- _selectionPos = _selectionPos vectorAdd (_x vectorMultiply (_offset select _forEachIndex)/100);
- } forEach [_X, _Y, _Z];
- player modeltoWorld _selectionPos
- };
- /*
- if (!isNil "cl_id") then {
- removeMissionEventHandler ["EachFrame", cl_id]
- };
- cl_id = addMissionEventHandler ["EachFrame", {
- private _selection = "proxy:\a3\characters_f\proxies\binoculars.001";
- private _pos = [_selection, lib_testBayonetoffset] call lib_fnc_offsetSelection;
- private _wepDir = player weaponDirection (primaryWeapon player);
- private _extension = 1;
- private _finalPos = _pos vectorAdd (_wepDir vectorMultiply _extension);
- [_pos, _finalPos] call lib_fnc_drawVectors;
- }]; */
- lib_bayonetAction =
- {
- private _unit = player;
- if (lib_isStabbing || (weaponLowered _unit)) exitwith {};
- private _muzzleAttachment = primaryWeaponItems _unit select 0;
- private _builtInBayonet = [(configFile >> "cfgWeapons" >> primaryweapon _unit),"lib_hasBayonet",0] call BIS_fnc_returnConfigEntry;
- _hasBayonet = if ((_muzzleAttachment isKindOf ["LIB_ACC_M44_Bayo",configFile >> "cfgWeapons"]) || _builtInBayonet == 1) then {true} else {false};
- if (!_hasBayonet) exitWith {};
- lib_isStabbing = true;
- //Spawn the projectile early so it can be assigned to the unit. There's some delay with SetShotParents let alone network lag
- private _offset = [(configFile >> "cfgWeapons" >> primaryweapon _unit >> "lib_weap_bayonet"),"lib_bayonetOffset",[0,0,0]] call BIS_fnc_returnConfigEntry;
- private _offsetEnd = [(configFile >> "cfgWeapons" >> primaryweapon _unit >> "lib_weap_bayonet"),"lib_bayonetOffsetEnd",[0,0,0]] call BIS_fnc_returnConfigEntry;
- private _selection = "proxy:\a3\characters_f\proxies\binoculars.001";
- private _wepDir = _unit weaponDirection (primaryWeapon _unit);
- private _unitDir = getdir _unit;
- private _unitVelocity = velocityModelSpace _unit;
- _unitvelocity set [1,((_unitvelocity select 1)+1.8)];
- private _projectiles = [];
- private _extension = 1;
- private _pos = [_selection, _offsetEnd] call lib_fnc_offsetSelection;
- private _finalPos = _pos vectorAdd (_wepDir vectorMultiply _extension);
- _finalPos set [2, 6000];
- private _projectile = createvehicle ["lib_ammo_bayonet", _finalPos, [], 0, "CAN_COLLIDE"];
- _projectile setdir _unitDir;
- _projectile setVelocityModelSpace _unitvelocity;
- [_projectile,_unit, _unit] remoteExecCall ["lib_system_fnc_remoteSetShotParents", 2];
- if (lib_debug) then {systemchat str(_unitVelocity);};
- //Play the stabby gesture
- _unit playAction "LIB_GestureBayonetStrike";
- enableCamShake true;
- addCamShake [1, 1, 5];
- sleep 0.33; //Wait until the animation reachs a suitable point to cause damage...
- //Fire the bayonet weapon
- [_projectile,_offset,_offsetEnd] call lib_bayonet_firedEH;
- addCamShake [9, 1.9, 2];
- sleep 1.85; //TODO the time of the bayonet strike
- if (!isNil "lib_attachProjectile") then {
- [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
- lib_attachProjectile = nil;
- };
- lib_isStabbing = false;
- };
- lib_bayonet_firedEH =
- {
- private _projectile = _this select 0;
- private _offset = _this select 1;
- private _offsetEnd = _this select 2;
- lib_melee_hitStart = time;
- lib_attachProjectile = [{
- private _arg = _this select 0;
- private _projectile = _arg select 0;
- private _offset = _arg select 1;
- private _offsetEnd = _arg select 2;
- private _selection = "proxy:\a3\characters_f\proxies\binoculars.001";
- private _wepDir = player weaponDirection (primaryWeapon player);
- if (!alive _projectile) exitwith {
- [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
- lib_attachProjectile = nil;
- }; //Bullets timed out, kill the check
- private _pos = [_selection, _offsetEnd] call lib_fnc_offsetSelection;
- private _beginPos = _pos vectorAdd (_wepDir vectorMultiply 1);
- _pos = [_selection, _offset] call lib_fnc_offsetSelection;
- private _endPos = _pos vectorAdd (_wepDir vectorMultiply 1);
- private _intersects = lineIntersectsSurfaces [(AGLToASL _beginPos), (AGLToASL _endPos), objNull, objNull, true, 32]; //Much better than setposing each frame...
- [_beginPos,_endPos] call lib_fnc_drawVectors;
- if (count _intersects > 0) then
- {
- private _impactPosASL = (_intersects select 0) select 0;
- [_projectile, _impactPosASL, time] call lib_bayonet_dealDamage;
- };
- },0,[_projectile,_offset,_offsetEnd]] call LIB_Core_fnc_addPerFrameHandler
- };
- lib_bayonet_dealDamage = {
- [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
- lib_attachProjectile = nil;
- private _projectile = param [0, objNull, [objNull]];
- private _impactPos = param [1, [], [[]]];
- private _impactTime = param [2, 0, [0]];
- if (isNull _projectile || {count _impactPos == 0} || {_impactTime == 0}) exitWith {
- hintSilent "Aborted deal damage";
- };
- private _timeElapsed = _impactTime - lib_melee_hitStart;
- private _damage = 1/(10*_timeElapsed + 1);
- _projectile setPosASL _impactPos;
- hint format ["Time elapsed: %1,\nDamage: %2", _timeElapsed, _damage];
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement