Jump to content
MasterPuffin

[Release] MP Vehicle Emergency Lights Script

Recommended Posts

This script is best used with a keyhandler, however if you have a bit of experience with coding you can get it also work with addaction. This script works in MP

********************************

Put the following code in your keyhandler:

	case 38: {//L key
			if (_shift) then {
				_vehicle = (vehicle player);
				if (isNil {_vehicle getVariable "EmergencyVeh"}) then {
					_vehicle setVariable ["EmergencyVeh", false, true];
				};
				_ComVeh = _vehicle getVariable "EmergencyVeh";
				if (vehicle player != player && (driver _vehicle == player && _ComVeh isEqualTo true)) then {
					if (isNil {_vehicle getVariable "lights"}) then {
						_vehicle setVariable ["lights", false, true];
					};
					_LightState = _vehicle getVariable "lights";
					if (_LightState isEqualTo true) then {
						_vehicle setVariable ["lights", false, true];
					}
				else
					{
						[[[_vehicle],"scripts\light.sqf"],"BIS_fnc_execVM",true,false,false] call BIS_fnc_MP;
						_vehicle setVariable ["lights", true, true];
					};
				};
            };
          };

Create a folder called scripts. Inside this folder create a file called light.sqf and put the following code into it:

Private ["_vehicle","_lightRed","_lightBlue","_lightleft","_lightright","_leftRed"];
_vehicle = _this select 0;

if(isNil "_vehicle" OR isNull _vehicle) exitWith {};
_lightRed = [20, 0.1, 0.1];
_lightBlue = [0.1, 0.1, 20];


_lightleft = "#lightpoint" createVehicle getpos _vehicle;   
sleep 0.2;
_lightleft setLightColor _lightRed; 
_lightleft setLightBrightness 0.2;  
_lightleft setLightAmbient [0.1,0.1,1];

switch (typeOf _vehicle) do
{
	case "C_Offroad_01_F":
	{
		_lightleft lightAttachObject [_vehicle, [-0.37, 0.0, 0.56]];
	};
	
	case "B_MRAP_01_F":
	{
		_lightleft lightAttachObject [_vehicle, [-0.8, -0.90, 0.6]];
	};
	
	case "C_SUV_01_F":
	{
		_lightleft lightAttachObject [_vehicle, [1.1,0.4,-0.05]];
	};
	
	case "I_Heli_light_03_unarmed_F":
	{
		_lightleft lightAttachObject [_vehicle, [1.23, 4.7, -1.42]];
	};
	
	case "B_Heli_Light_01_F":
	{
		_lightleft lightAttachObject [_vehicle, [-0.75, 1.7, -0.95]];
	};	
	
	case "C_Hatchback_01_sport_F":
	{
		_lightleft lightAttachObject [_vehicle, [0.62, 1.87, -0.52]];
	};
		
	case "C_Offroad_02_unarmed_F":
	{
		_lightleft lightAttachObject [_vehicle, [0.62, 1.87, -0.52]];
	};
		
	case "O_MRAP_02_F":
	{
		_lightleft lightAttachObject [_vehicle, [-0.8, -0.90, 0.6]];
	};
			
	case "B_APC_Wheeled_01_cannon_F":
	{
		_lightleft lightAttachObject [_vehicle, [-0.8, -0.90, 0.6]];
	};
		
	case "B_Heli_Transport_01_F":
	{
		_lightleft lightAttachObject [_vehicle, [1.23, 4.7, -1.42]];
	};
};

_lightleft setLightAttenuation [0.181, 0, 1000, 130]; 
_lightleft setLightIntensity 10;
_lightleft setLightFlareSize 0.38;
_lightleft setLightFlareMaxDistance 150;
_lightleft setLightUseFlare true;

_lightright = "#lightpoint" createVehicle getpos _vehicle;   
sleep 0.2;
_lightright setLightColor _lightBlue; 
_lightright setLightBrightness 0.2;  
_lightright setLightAmbient [0.1,0.1,1]; 

switch (typeOf _vehicle) do
{
	case "C_Offroad_01_F":
	{
		_lightright lightAttachObject [_vehicle, [0.37, 0.0, 0.56]];
	};
	
	case "B_MRAP_01_F":
	{
		_lightright lightAttachObject [_vehicle, [0.8, -0.90, 0.6]];
	};
	
	case "C_SUV_01_F":
	{
		_lightright lightAttachObject [_vehicle, [-1.1,0.4,-0.05]];
	};
	
	case "I_Heli_light_03_unarmed_F":
	{
		_lightright lightAttachObject [_vehicle, [-1, 3.2, -2]];
	};
	
	case "B_Heli_Light_01_F":
	{
		_lightright lightAttachObject [_vehicle, [0.75, 1.7, -0.95]];
	};	
	
	case "C_Hatchback_01_sport_F":
	{
		_lightright lightAttachObject [_vehicle, [-0.62, 1.87, -0.52]];
	};
	
	case "C_Offroad_02_unarmed_F":
	{
		_lightright lightAttachObject [_vehicle, [0.37, 0.0, 0.56]];
	};
		
	case "O_MRAP_02_F":
	{
		_lightright lightAttachObject [_vehicle, [0.8, -0.90, 0.6]];
	};
			
	case "B_APC_Wheeled_01_cannon_F":
	{
		_lightright lightAttachObject [_vehicle, [0.8, -0.90, 0.6]];
	};
		
	case "B_Heli_Transport_01_F":
	{
		_lightright lightAttachObject [_vehicle, [-1, 3.2, -2]];
	};
};
  
_lightright setLightAttenuation [0.181, 0, 1000, 130]; 
_lightright setLightIntensity 10;
_lightright setLightFlareSize 0.38;
_lightright setLightFlareMaxDistance 150;
_lightright setLightUseFlare true;

_lightleft setLightDayLight true;
_lightright setLightDayLight true;

_transitionState = sunOrMoon;
_brightness = 0;

_repeat = true;

if (_transitionState < 1) then {
	_brightness = 2;
} else {
	_brightness = 50;
};

_leftRed = true;  
while{ (alive _vehicle) && (_repeat isEqualTo true)} do  
{  
	if(_leftRed) then  
	{  
		_leftRed = false;  
		_lightright setLightBrightness 0.0;  
		sleep 0.05;
		_lightleft setLightBrightness _brightness;  
	}  
		else  
	{  
		_leftRed = true;  
		_lightleft setLightBrightness 0.0;  
		sleep 0.05;
		_lightright setLightBrightness _brightness;  
	};  
	sleep 0.05;
	_repeat = _vehicle getVariable "lights";	
};  
deleteVehicle _lightleft;
deleteVehicle _lightright;

You can remove any vehicles you don't need or add some. Just remember that you have to add them twice (for the left and the right light).

 

Now you can place a vehicle in the editor and put the following in the init box:

this setVariable ["EmergencyVeh", true, true];

Only vehicles with this variable can activate the lights.

 

As always, if you have any questions feel free to ask!

Cheers

Puffin

  • Like 2

Share this post


Link to post
Share on other sites

if you wand your light permanently on instead of blinking replace the while part in the light.sqf with the following code:

 

while{ (alive _vehicle) && (_repeat isEqualTo true)} do  
{  
	if(_leftRed) then  
	{  _lightleft setLightBrightness _brightness;  
	}  
		else  
	{  
		_lightright setLightBrightness _brightness;  
	};  
	sleep 1;
	_repeat = _vehicle getVariable "lights";	
};  
deleteVehicle _lightleft;
deleteVehicle _lightright;

 

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

×