Jump to content
Sign in to follow this  
fn_Quiksilver

[Release] Grappling Hook script

Recommended Posts

Hi lads,

 

Created a little "proof of concept" grappling hook script a few weeks ago using vanilla assets, thought I'd share.

 

/*
	Dumb little grappling hook mod
	
	by Quiksilver
	
	How to use:
	
		- HOLD left mouse button to use grappling hook
		- RELEASE left mouse button to release grappling hook

*/


QS_mx = 50;				// adjustable velocity multiplier
QS_downVel = -0.1;		// adjustable downward velocity for bullet drop
QS_vehicle = objNull;
QS_rope = objNull;
QS_EH_3 = -1;
removeAllUserActionEventHandlers ['defaultAction','activate'];
removeAllUserActionEventHandlers ['defaultAction','deactivate'];
addUserActionEventHandler [
	'defaultAction',
	'activate',
	{
		if ((toLowerANSI (currentWeapon cameraOn)) isNotEqualTo 'hgun_esd_01_antenna_01_f') exitWith {};
		if (!alive QS_vehicle) then {
			QS_helper_1 = createVehicle [QS_helperType,[0,0,0]];
			QS_helper_1 hideObject FALSE;
			QS_helper_1 allowDamage FALSE;
			QS_helper_1 attachTo [player,[0.2,-2,1]];
			QS_helper_2 = createVehicle [QS_helperType,[0,0,0]];
			QS_helper_2 hideObject TRUE;
			QS_helper_2 allowDamage FALSE;
			QS_helper2_EH = addMissionEventHandler [
				'EachFrame',
				{
					if (isNull QS_helper_2) exitWith {
						removeMissionEventHandler [_thisEvent,_thisEventHandler];
					};
					if (isNull (attachedTo QS_helper_2)) then {
						QS_helper_2 setPosWorld (getPosWorld QS_helper_2);
					};
				}
			];
			_weaponVectorDir = player weaponDirection (currentWeapon player);
			QS_vehicle = createVehicle ['Land_Balloon_01_water_F',[0,0,0]];
			QS_vehicle setObjectTexture [0,"#(rgb,8,8,3)color(0,0,0,1)"];
			QS_vehicle setPosASL (player modelToWorldWorld [0.2,2,1]);
			QS_helper_2 attachTo [QS_vehicle,[0,0,0]];
			QS_vehicle setVelocity (_weaponVectorDir vectorMultiply QS_mx);
			QS_vehicle addEventHandler [
				'Killed',
				{
					(_this # 0) removeEventHandler [_thisEvent,_thisEventHandler];
					(_this # 0) removeAllEventHandlers 'EpeContact';
					QS_pos2 = getPosWorld (_this # 0);
					detach QS_helper_2;
					QS_helper_2 setPosWorld (getPosWorld (_this # 0));
					ropeUnwind [QS_rope, 20, 1];
					removeMissionEventHandler ['Draw3D',QS_EH_3];
					QS_EH_3 = addMissionEventHandler [
						'Draw3D',
						{
							player setPosWorld ((getPosWorld QS_helper_1) vectorAdd [0,0,3]);
						}
					];
				
				}
			];
			QS_vehicle addEventHandler [
				'EpeContact',
				{
					(_this # 0) removeEventHandler [_thisEvent,_thisEventHandler];
					(_this # 0) removeAllEventHandlers 'Killed';
					QS_pos2 = getPosWorld (_this # 0);
					detach QS_helper_2;
					QS_helper_2 setPosWorld (getPosWorld (_this # 0));
					ropeUnwind [QS_rope, 20, 1];
					removeMissionEventHandler ['Draw3D',QS_EH_3];
					QS_EH_3 = addMissionEventHandler [
						'Draw3D',
						{
							player setPosWorld ((getPosWorld QS_helper_1) vectorAdd [0,0,2]);
						}
					];
				}
			];
			addMissionEventHandler [
				'EachFrame',
				{
					if (!alive QS_vehicle) exitWith {
						removeMissionEventHandler [_thisEvent,_thisEventHandler];
					};
					QS_vehicle setVelocity ((velocity QS_vehicle) vectorAdd [0,0,QS_downVel]);
				}
			];
			detach QS_helper_1;
			QS_rope = ropeCreate [QS_helper_2,[0,1,0],QS_helper_1,[0,1,0],30];
			systemChat str QS_rope;
		};
	}
];
addUserActionEventHandler [
	'defaultAction',
	'deactivate',
	{
		if ((toLowerANSI (currentWeapon cameraOn)) isNotEqualTo 'hgun_esd_01_antenna_01_f') exitWith {};
		deleteVehicle QS_vehicle;
		if (!isNull QS_rope) then {deleteVehicle QS_rope};
		if (!isNull QS_helper_1) then {
			detach QS_helper_1;
			deleteVehicle QS_helper_1;
		};
		if (!isNull QS_helper_2) then {
			detach QS_helper_2;
			deleteVehicle QS_helper_2;
		};
		removeMissionEventHandler ['Draw3D',QS_EH_3];
		player setVelocity [0,0,0];
	}
];
// Run the below stuff only once
player addWeapon "hgun_esd_01_antenna_01_F";
player selectWeapon (handgunWeapon player);
player allowDamage FALSE;
QS_helperType = 'B_static_AA_F';							// what other physx object can we use for rope attach?. Hiding this doesnt work (disables physx).
QS_helper_1 = objNull;
QS_helper_2 = objNull;

 

  • Like 2
  • Haha 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×