Code:
/*
Martin "xealot" Engström
xealot@gmail.com
Anton "tednoob" Johansson
johansson.anton@gmail.com
ACE M49 tripflare enhancement script
version 2
Usage:
[default flare mode, (flare height), (burntime), (alpha min), (alpha max)] call fnc_tripflare_init;
Arguments:
flare mode boolean true: all M49 mines will shoot flares false: Only specific mines will shoot flares
flare height int Final ascend height for the flare in meter, Default: 180
burntime int Flare burn time in seconds, Default: 1
alpha min int Minimum flare path deviation in meters, Default: 10
alpha max int Maximum flare path deviation in meters, Default: 60
Example:
call compile preprocessFileLineNumbers "tripflare.sqf";
waitUntil {tripflare_initialized};
[true] call fnc_tripflare_init;
To selectively enable or disable M49 flares use:
this setVariable ["shootFlare", true];
this setVariable ["shootFlare", false];
*/
fnc_tripflare_simflare = {
/* Begin flare simulation at a given position */
/* time, pos, height, burn, alpha, angle */
_explosionTime = _this select 0;
_minePos = _this select 1;
_h = _this select 2;
_tb = _this select 3;
_alpha = _this select 4;
_directionAngle = _this select 5;
_mineX = _minePos select 0;
_mineY = _minePos select 1;
_mineZ = _minePos select 2;
_flare = "F_40mm_Red" createVehicleLocal [_mineX, _mineY, _mineZ + 1];
_flareLight = "#lightpoint" createVehicleLocal getpos _flare;
_flareLight setLightBrightness 0.4;
_flareLight setLightAmbient[1, 0, 0];
_flareLight setLightColor[1, 0, 0];
_flareLight lightAttachObject [_flare, [0,0,0]];
//Constants for a realistic simulation.
_g = -9.82; //m/s^2
_m = 1; //kg
_a = _alpha;
_Fb = ((_h-(_g/2)*_tb^2)*_m*(_a*pi/180)^2)/((1-cos(_a))*_tb^2);
_t = 0;
while { _t <= _tb } do {
_t = time - _explosionTime;
_horizontal = (_Fb/_m)*(_tb/(_a*pi/180))*(_t-sin((_a/_tb)*_t)*(_tb/(_a*pi/180)));
_newX = cos(_directionAngle)*_horizontal;
_newY = sin(_directionAngle)*_horizontal;
_newZ = -_Fb/_m*_tb^2/(_a*pi/180)^2*cos(_a/_tb*_t)+_g/2*_t^2+_Fb/_m*_tb^2/(_a*pi/180)^2;
_flare setPos [(_mineX + _newX), (_mineY + _newY), (_mineZ + _newZ)];
drop [["\Ca\Data\ParticleEffects\Universal\Universal",1,0,1,0], "", "billboard", 1, 3, getPos _flare,
[0, 0, 0], 1, 0.06, 0.04, 0, [1],
[[0.6, 0.5, 0.4, 0.6],[0.6, 0.5, 0.4, 0.4],[0.6, 0.5, 0.4, 0.2],[0.6, 0.5, 0.4, 0.1],[0.6, 0.5, 0.4, 0.0]],
[10000], 0.1, 0.1, "", "", ""];
sleep 0.0005;
};
waitUntil { not alive _flare };
sleep 5; // Fake a small ground burnout
deleteVehicle _flareLight;
};
fnc_tripflare_conf = {
/* height,burn,a_min,a_max,pos */
_h = _this select 0;
_alpha = random((_this select 3) - (_this select 2)) + (_this select 2);
_directionAngle = (random 360);
_tb = _this select 1;
_pos = [(_this select 4) select 0, (_this select 4) select 1, ((_this select 4) select 2) + 2];
_time = time;
_confArray = [_time, _pos, _h, _tb, _alpha, _directionAngle];
_confArray;
};
fnc_tripflare_tripped = {
/* An ACE mine eventhandler was set off - Should be ran on the server only */
if (isServer) then {
_trigger = (_this select 0) select 0;
_confArray = _this select 1; /* default,height,burn,a_min,a_max */
_mine = _trigger getVariable ["ace_sys_explosives_mine",objNull];
_mineType = typeOf _mine;
_shootFlare = _mine getVariable ["shootFlare", _confArray select 0];
if (((_mineType == "ACE_M49") or (_mineType == "ACE_M49_EDITOR")) and (_shootFlare)) then {
/* A tripflare mine was detonated and should send out a flare -
raise a CBA event for all the clients to begin simulate. */
_flareConf = [_confArray select 1, _confArray select 2, _confArray select 3, _confArray select 4, getPosATL _mine] call fnc_tripflare_conf;
["tripflare_tripped", _flareConf] call CBA_fnc_globalEvent;
};
};
};
fnc_tripflare_init = {
/* Init the flare system for server and clients. This code should be run by everyone */
_defaultMode = _this select 0;
_flareHeight = 180;
_burnTime = 1;
_alphaMin = 10;
_alphaMax = 60;
if (count _this > 1) then {
_flareHeight = _this select 1;
};
if (count _this > 2) then {
_burnTime = _this select 2;
};
if (count _this > 3) then {
_alphaMin = _this select 3;
};
if (count _this > 4) then {
_alphaMax = _this select 4;
};
tripflare_confArray = [_defaultMode, _flareHeight, _burnTime, _alphaMin, _alphaMax];
/* Set up event handlers */
if (isServer) then {
["ace_sys_explosives_trip", {Null = [_this, tripflare_confArray] spawn fnc_tripflare_tripped}] call CBA_fnc_addEventHandler;
};
["tripflare_tripped", {Null = (_this) spawn fnc_tripflare_simflare}] call CBA_fnc_addEventHandler;
};
tripflare_initialized = true;
In addition to that it works as before with all ACE M49 tripwire mines you can now also manually call a flare independent of ACE to be shot up into the sky at any position of your choice using fnc_tripflare_conf and fnc_tripflare_simflare by execting this: