Jump to content
Sign in to follow this  
maxl30

how to create a light bar (addon) ?

Recommended Posts

I'm fairly sure he's asking about writing a custom mod to add a lightbar to a vehicle that doesn't have a built in configuration for it. Right now, only boats and the Offroad have a configuration for a police lightbar, and these are not available for other vehicles. 
I've been writing one myself (it's not without its issues that I'm working through) but the way I'm doing it is as follows:

 

Here's a dumbed down version of my mod to get you going:

 

config.cpp:

#define private		0
#define protected		1
#define public		2
class DefaultEventhandlers;	// External class reference

class CfgPatches {
	class RPDLightbarMod {
		units[] = {};
		weapons[] = {};
		requiredVersion = 0.1;
		requiredAddons[] = {"A3_Soft_F"};

	};
};
class CfgVehicles {
  class SUV_01_base_f; //External reference

  class C_SUV_01_F: SUV_01_base_f {
    scope = public;
    class EventHandlers {
      init = "lightbar = [_this select 0] execVM ""\rpd\script\initLightbar.sqf"";";
    };
  };
 class Static; // External class reference

  class lightbar : Static {
    scope = public;
    model = "\rpd\lightbar\lightbar.p3d";
    displayName = "lightbar";
    hiddenSelections[] = {};
    hiddenSelectionsTextures[] = {};
  };
}; 

In this I simply override the SUV configuration and add an 'init' eventhandler that tells it to run the script when it's created. It also defines the lightbar object itself. You'll have to get your own model though, and you'll probably need to play with the hiddenSelections based on the model you use.

 

script\initLightbar.sqf:

private["_car","_lightbar"];
_car = _this select 0; //Get the car reference
deleteCheckLoop = compile preprocessFile "\rpd\script\fn_deleteCheckLoop.sqf"; //Prepare the cleanup loop

switch typeOf _car do
{
  case "C_SUV_01_F":
  {
    if(_car getVariable["copcar",false]) then {
      _lightbar = "lightbar" createVehicle getPos _car;
      _lightbar attachTo [_car, [0,-0.65, 0.41]];
      _lightbar setVariable ["parent",_car,true];
      _lightbar setVariable ["isModAttachment",true,true];
      _car setVariable ["hasLightbar",true,true];
      [_car,_lightbar] spawn deleteCheckLoop;
    };
  };
};

This creates the lightbar and attaches it, while adding some variables to the object for us to use later.

fn_deleteCheckLoop.sqf

private ["_car","_lightbar"];

_car = _this select 0;
_lightbar = _this select 2;

waitUntil {!(alive _car) || isNull _car}; //Wait until the car no longer exists

if(!isNil "_lightbar") then {deleteVehicle _lightbar}; //Delete it! 

This script basically waits until the car is deleted, and then deletes the lightbar as well. You may want to do some extra checks in your mission to make sure things are cleaned up properly just in case, but this should work. That's why I set those variables. :)

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

×