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 =
- {
- 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
- };
- 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;
- private _hasBayonet = if ((_muzzleAttachment isKindOf ["LIB_ACC_M44_Bayo",configFile >> "cfgWeapons"]) || _builtInBayonet == 1) then {true} else {false};
- if (!_hasBayonet) exitWith {};
- lib_isStabbing = true;
- private _unitDir = getdir _unit;
- private _unitVelocity = velocityModelSpace _unit;
- _unitvelocity set [1,((_unitvelocity select 1)+1.8)];
- //Spawn the projectile early so it can be assigned to the unit. There's some delay with SetShotParents let alone network lag
- private _bulletPos = (getPos _unit) vectorAdd [0,0,worldSize];
- private _projectile = createvehicle ["lib_ammo_bayonet", _bulletPos, [], 0, "CAN_COLLIDE"];
- _projectile setdir _unitDir;
- _projectile setVelocityModelSpace _unitvelocity;
- [_projectile,_unit, _unit] remoteExecCall ["lib_system_fnc_remoteSetShotParents", 2];
- //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, _unit] call lib_bayonet_firedEH;
- addCamShake [9, 1.9, 2];
- sleep 1.85; //TODO the time of the bayonet strike
- lib_isStabbing = false;
- };
- lib_bayonet_firedEH =
- {
- private _projectile = _this select 0;
- private _unit = _this select 1;
- 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;
- lib_projectile = _projectile;
- 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;}; //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...
- //systemchat str(_intersects);
- [_beginPos,_endPos] call lib_fnc_drawVectors;
- if (count _intersects > 0) then
- {
- _projectile setposasl ((_intersects select 0) select 0);
- [lib_attachProjectile] call LIB_Core_fnc_removePerFrameHandler;
- };
- },0,[_projectile,_offset,_offsetEnd]] call LIB_Core_fnc_addPerFrameHandler;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement