Jump to content

Recommended Posts

The latest version of the Simple Radar Warning System,

Functions,

Spoiler

//Load These Funtions

MMF_fnc_warningSwitch=
{
	_toggleSys=missionNameSpace getVariable ["warnSys",0];
	warnHINT= ["Online", "Offline"] select _toggleSys;
	systemChat format ["Warning System %1", warnHINT];

		if (missionNameSpace getVariable ["warnSys",0]==1) then {
			missionNamespace setVariable ["warnSys", 0];
			playSound ["click", true];
		} else {
			missionNamespace setVariable ["warnSys", 1];
			playSound ["click", true];
	};

};



MMF_fnc_warningSystem=
{ 	params [["_speedLOW", 300], ["_speedHIGH", 1200], ["_altLOW", 100]];

[_speedHIGH]spawn{	while {true} do {
		if(speed vehicle player > _this select 0 && missionNameSpace getVariable ["warnSys",0]==1 && vehicle player isKindOf "plane") then {
				titleText ["WARNING", "Plain", 0.1];
				playSound ["vtolalarm", true];
			sleep 1.2;
				titleText ["SPEED DOWN", "Plain", 0.1];
			sleep 2.5;
			};
		sleep 0.5
		};
	};


[_speedLOW]spawn{	while {true} do {
		if(speed vehicle player < _this select 0 && missionNameSpace getVariable ["warnSys",0]==1 && vehicle player isKindOf "plane") then {
				titleText ["WARNING", "Plain", 0.1];
				playSound ["vtolalarm", true];
			sleep 1.2;
				titleText ["SPEED UP", "Plain", 0.1];
			sleep 2.5;
			};
		sleep 0.5
		};
	};

[_altLOW]spawn{	while {true} do {
		if((getPos (vehicle player)) select 2 < (_this) select 0 && missionNameSpace getVariable ["warnSys",0]==1 && vehicle player isKindOf "plane") then {
				titleText ["WARNING", "Plain", 0.1];
				playSound ["vtolalarm", true];
			sleep 1.2;
				titleText ["ALTITUDE", "Plain", 0.1];
			sleep 2.5;
			};
		sleep 0.5
		};
	};
};

 

Vehicle init (for automatic system arm),

Spoiler

//vehicle init for arm system on gear up
this addEventHandler ["Gear", { 
	params ["_vehicle", "_gearState"]; 

	if (!_gearState) then {toggleSys=1} else {toggleSys=0}; 
	missionNameSpace setVariable ["warnSys", toggleSys]; 
 	warnHINT= ["Offline", "Online"] select toggleSys; 
 	systemChat format ["Warning System %1", warnHINT]; 
}];

 

Player manual system switch,

Spoiler

//player manual switch
warnSwitch= player addAction ["WARN", {[]call MMF_fnc_warningSwitch},[],9,true,true,"","vehicle player isKindOf ""plane"""];

 

Configurable function call,

Spoiler

//call-- use this to configure flight envelope -- params [low speed, high speed, low alt]
[300, 1200, 100]spawn MMF_fnc_warningSystem;

 


Fly safely and...
Have fun!

File Download (Drive)

 

*Original Post*

Spoiler

 

The warning system in FTA has gone through at least 3 iterations as I've learned more here on the forum. The system started out as a bunch of if / then statements, then if / exitWith, the waitUntils and finally while Trues. While trues was a mistake for sure (performance) so we're back to waitUntil. Every iteration has worked, pretty well actually, but after going around this a few times I'm curious, what would you do?

The warning system chirps if too slow, too fast, too low. Each a separate process. It only engages when player is in flight and is complicated only by the addition of a player action to toggle the system on / off.

This is how it works with while true,

Toggle switch,


warnSWITCH=player addAction ["WARN", "[]spawn FTA_fnc_warningSwitch",{}, 11];

Switch function,

Spoiler


FTA_fnc_warningSwitch=
{
warnHINT= ["Online", "Offline"] select ALTwarn;

if (ALTwarn == 0) exitWith {
    ALTwarn=1;
    playSound ["click", true];
    hintSilent format ["Warning System %1", warnHINT];
sleep 2;
    hint "";
    };

if (ALTwarn == 1) exitWith {
    ALTwarn=0;
    playSound ["click", true];
    hintSilent format ["Warning System %1", warnHINT];
sleep 2;
    hint "";
    };

};

 


An example of the warning as while true,

Spoiler


aws3=[]spawn {while {true} do {

if(speed vehicle player > 380 && altWARN==1 && vehicle player isKindOf "plane") then {
    
titleText ["WARNING", "Plain", 0.1];
    playSound ["vtolalarm", true];
sleep 1.2;
titleText ["SPEED DOWN", "Plain", 0.1];
sleep 2.5;
    };

sleep 0.5
};};

 


An example of the warning as waitUntil,

Spoiler

altitude = [] spawn {

waitUntil {   

 sleep 2;

(getPos vehicle player) select 2 < 50     };

if (ALTwarn==1) then {     

playSound ["vtolalarm", true];     

titleText ["WARNING", "Plain", 0.1];

sleep 1;     

titleText ["ALTITUDE", "Plain", 0.1];

sleep 2;     

ALTwarning = []execVM "AWS\ALTwarn.sqf";   

         };

};


It's not a pressing concern, it works as is, but I am curious how you would do it.

 

Thanks!

 

 

  • Like 3

Share this post


Link to post
Share on other sites

I would likely do something like...

Spoiler


FTA_fnc_addWarningAction = {
	params[ "_unit" ];
	
	_unit setVariable[ "FTA_ALTWarnActionID",
		_unit addAction[ "WARN ON", { _this spawn FTA_fnc_warningSwitch }, [],	11 ]
	];
};


FTA_fnc_warningSwitch = {
	params[ "_target", "_caller", "_id" ];
	
	FTA_ALTWarn = !FTA_ALTWarn;
	
	_target setUserActionText[ _id, [ "WARN ON", "WARN OFF" ] select FTA_ALTWarn ];
	
	playSound[ "click", true ];
	hintSilent format[ "Warning System %1", [ "Offline", "Online" ] select FTA_ALTWarn ];
	
	if ( FTA_ALTWarn ) then {
		FTA_ALTWarnThread = [ _caller ] spawn {
			params[ "_player" ];
			
			while { FTA_ALTWarn } do {
	
				if ( speed vehicle _player > 380 ) then {
			
					titleText ["WARNING", "Plain", 0.1];
					playSound ["vtolalarm", true];
					sleep 1.2;
					titleText ["SPEED DOWN", "Plain", 0.1];
					sleep 2.5;
				};
				sleep 0.5
			};
		};
	};
	
	sleep 2;
	hint "";

};


FTA_ALTWarn = false;

player addEventHandler [ "GetInMan", {
	params[ "_unit", "_role", "_vehicle" ];
	
	if ( typeOf _vehicle isKindOf "plane" && { _role == "Driver" } ) then {
		[ _unit ] call FTA_fnc_addWarningAction;
	};
}];

player addEventHandler [ "GetOutMan", {
	params[ "_unit" ];
	
	_actionID = _unit getVariable[ "FTA_ALTWarnActionID", -1 ];
	if ( _actionID > -1 ) then {
		_unit removeAction _actionID;
		_unit setVariable [ "FTA_ALTWarnActionID", nil ];
		FTA_ALTWarn = false;
	};
}];

 

So the action is only available when a player gets in a plane as the pilot, and removed and warning state reset on exit.

Can a player swap seats in any vanilla planes? may want to think about seatSwitchedMan for compatibility?

May also be better to add the action to the vehicle itself and only allow driver/copilot access to the action.

Untested, just thinking out loud for suggestion.

  • Like 3
  • Thanks 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

×