Browse Source

add custom impulse script

thefloff 4 years ago
parent
commit
9e7a14a1ca

+ 5 - 0
addons - Copy/RD501_Main/XEH_preInit.sqf

@@ -143,4 +143,9 @@ macro_prep_xeh(jammer\fnc_addJammerLocal.sqf,addJammerLocal)
 macro_prep_xeh(jammer\fnc_jammersPFH.sqf,jammersPFH)
 macro_prep_xeh(jammer\fnc_jammersServerPFH.sqf,jammersServerPFH)
 
+// Impulse
+macro_prep_xeh(impulse\fnc_impulseApply.sqf,impulseApply)
+macro_prep_xeh(impulse\fnc_impulseIncrease.sqf,impulseIncrease)
+macro_prep_xeh(impulse\fnc_impulseDecrease.sqf,impulseDecrease)
+
 diag_log "RD501 PREP Complete";

+ 90 - 0
addons - Copy/RD501_Main/functions/impulse/fnc_impulseApply.sqf

@@ -0,0 +1,90 @@
+_vehicle = _this;
+
+systemChat "apply";
+
+private _impulse_state = _vehicle getvariable ["impulsorStatus", 0];
+
+private _target_speed = 0;
+private _max_change = 0;
+private _accelerate = True;
+private _decelerate = True;
+private _stage_message = "";
+
+switch (_impulse_state) do
+{
+	case -1:
+	{
+		_target_speed = 100;
+		_max_change = 10;
+		_accelerate = False;
+		_stage_message = format["%1 kph", _target_speed];
+	};
+	case 0:
+	{
+		_target_speed = 0;
+		_max_change = 0;
+		_accelerate = False;
+		_decelerate = False;
+		_stage_message = "neutral";
+	};
+	case 1:
+	{
+		_target_speed = 400;
+		_max_change = 10;
+		_decelerate = False;
+		_stage_message = format["%1 kph", _target_speed];
+	};
+	case 2:
+	{
+		_target_speed = 600;
+		_max_change = 30;
+		_stage_message = format["%1 kph", _target_speed];
+	};
+	default
+	{
+		hint "ERROR";
+	};
+};
+
+_titlehintimpulsor  = "<t color='#E57300' size='2' shadow='1' shadowColor='#000000' align='center'>IMPULSOR</t>";
+_texthintimpulsor   = format ["<br /><t color='#00ff00' size='1.4' shadow='1' shadowColor='#000000' align='center'>Stage %1 - %2</t>", _impulse_state, _stage_message];
+hint parseText (_titlehintimpulsor+_texthintimpulsor);
+
+if (!_accelerate && !_decelerate) exitWith{};
+while {_vehicle getVariable ['impulsorStatus', 0] isEqualTo _impulse_state && alive _vehicle} do
+{
+	private _movement = velocity _vehicle;
+	private _velocity = sqrt ((_movement select 0) * (_movement select 0) + (_movement select 1) * (_movement select 1));
+	_velocity = _velocity * 3.6; // m/s -> kp/h
+	private _diff = _target_speed - _velocity;
+	private _change = 0;
+	
+	if (abs _diff < _max_change) then {
+		_change = _diff;
+	} else {
+		if (_diff < 0) then {
+			_change = -_max_change;
+		} else {
+			_change = _max_change;
+		};
+	};
+
+	if (_change > 0 && !_accelerate) then {
+		_change = 0;
+	};
+	if (_change < 0 && !_decelerate) then {
+		_change = 0;
+	};
+
+	systemChat format ["%1 - %2 - %3 - %4 - %5", str _velocity, str _target_speed, str _diff, str _max_change, str _change];
+
+	if (_change != 0) then {
+		_direction = direction _vehicle;
+		_vehicle setVelocity [
+			(_movement select 0) + (sin _direction * _change), 
+			(_movement select 1) + (cos _direction * _change), 
+			(_movement select 2)
+			];
+	};
+	sleep 0.5;
+};

+ 13 - 0
addons - Copy/RD501_Main/functions/impulse/fnc_impulseDecrease.sqf

@@ -0,0 +1,13 @@
+_vehicle = _this;
+
+systemChat "decrease";
+
+private _impulse_state = _vehicle getvariable ["impulsorStatus", 0];
+_impulse_state = _impulse_state - 1;
+if (_impulse_state < -1) then
+{
+	_impulse_state = -1;
+};
+_vehicle setvariable ["impulsorStatus", _impulse_state, true];
+
+_this call rd501_fnc_impulseApply;

+ 13 - 0
addons - Copy/RD501_Main/functions/impulse/fnc_impulseIncrease.sqf

@@ -0,0 +1,13 @@
+_vehicle = _this;
+
+systemChat "increase";
+
+private _impulse_state = _vehicle getvariable ["impulsorStatus", 0];
+_impulse_state = _impulse_state + 1;
+if (_impulse_state > 2) then
+{
+	_impulse_state = 2;
+};
+_vehicle setvariable ["impulsorStatus", _impulse_state, true];
+
+_this call rd501_fnc_impulseApply;

+ 6 - 6
addons - Copy/RD501_Vehicles/air/LAAT/user_action.hpp

@@ -8,8 +8,8 @@
 		radius = 20;
 		priority = 21;
 		onlyForPlayer = 1;
-		condition = "(!(this getvariable [""impulsorStatus"",false]) AND (player == driver this) AND (alive this) AND (speed this >10) )";
-		statement = "this execVM ""\RD501_Vehicles\air\LAAT\initTE.sqf""";
+		condition = "((player == driver this) AND (alive this) AND (speed this >10) )";
+		statement = "this execVM ""\RD501_Main\functions\impulse\fnc_impulseIncrease.sqf""";
 	};
 
 	class ThrusterDisngage: ThrusterEngage
@@ -18,8 +18,8 @@
 		displayName = "<t color='#FF9933'>[RepulsorBrake On]</t>";
 		displayNameDefault = "<t color='#FF9933'>[RepulsorBrake On]</t>";
 		textToolTip = "<t color='#FF9933'>[RepulsorBrake On]</t>";
-		condition = "((this getvariable [""impulsorStatus"",false]) AND (player == driver this) AND (alive this))";
-		statement = "this execVM ""\RD501_Vehicles\air\LAAT\initTD.sqf""";
+		condition = "((player == driver this) AND (alive this))";
+		statement = "this execVM ""\RD501_Main\functions\impulse\fnc_impulseDecrease.sqf""";
 	};
 
 	class ThrusterEngage_spam: ThrusterEngage
@@ -32,7 +32,7 @@
 		priority = 0;
 		onlyForPlayer = 1;
 		condition = "((player == driver this) AND (alive this) AND (speed this >10) )";
-		statement = "this execVM ""\RD501_Vehicles\air\LAAT\initTE.sqf""";
+		statement = "this execVM ""\RD501_Main\functions\impulse\fnc_impulseIncrease.sqf""";
 		shortcut="User19"
 	};
 
@@ -44,7 +44,7 @@
 		displayNameDefault = "";
 		textToolTip = "";
 		condition = "((player == driver this) AND (alive this))";
-		statement = "this execVM ""\RD501_Vehicles\air\LAAT\initTD.sqf""";
+		statement = "this execVM ""\RD501_Main\functions\impulse\fnc_impulseDecrease.sqf""";
 		shortcut="User20"
 	};