Results 1 to 4 of 4

Thread: Tripwire flare mine script

  1. #1

    Tripwire flare mine script

    Hi!
    This is not a help or request thread but I just wanted to share my script

    I was tooling around with the tripflare mines (M49) in ACE2 but wanted something more than just a flash like a flare shot up into the sky, Sadly I found no threads about this or even about making it so I did some research and this is the result I came up with:

    Code:
    /*
    	Martin "xealot" Engström
    	xealot@gmail.com
    
    	Anton "tednoob" Johansson
    	johansson.anton@gmail.com
    
    	A simple script to enhance the ACE tripflare mines (M49)
    	Add one of the following lines once anywhere in your mission (init.sqf, gamelogic etc.)
    
    	Enable all M49 mines by default to shoot flares:
    	["ace_sys_explosives_trip", {Null = [_this, true] execVM "mine.sqf"}] call CBA_fnc_addEventHandler;
    
    	Only allow specific M49 mines to shoot flares:
    	["ace_sys_explosives_trip", {Null = [_this, false] execVM "mine.sqf"}] call CBA_fnc_addEventHandler;
    
    
    	To enable or disable a mine from shooting flares use this in its init:
    	this setVariable ["shootFlare", true];
    	or
    	this setVariable ["shootFlare", false];
    
    	TODO:
    		Check if the mine is in cover (bushes makes the flare get stuck)
    		Possibly rework script so that only the server randomizes alpha and directionangle and then triggers a new EH with those magic numbers
    		plus the mine position for all the clients to locally simulate the flare (should also send the time the mine was triggered)
    
    
    */
    _trigger = (_this select 0) select 0;
    _shootDefault = _this select 1;
    _mine = _trigger getVariable ["ace_sys_explosives_mine",objNull];
    _mineType = typeOf _mine;
    _shootFlare = _mine getVariable ["shootFlare", _shootDefault];
    
    if (((_mineType == "ACE_M49") or (_mineType == "ACE_M49_EDITOR")) and (_shootFlare)) then {
    	/* A tripflare was detonated. Create a flare with a particle trail directly upwards */
    	_mineX = getPosATL _mine select 0;
    	_mineY = getPosATL _mine select 1;
    	_mineZ = (getPosATL _mine select 2) + 1;
    
    	_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]];
    
    	_explosionTime = time;
    
    	//Parameters to fiddle with
    	_h = 180; //meters
    	_alpha = random(40)+10;
    	_directionAngle = (random 360);
    	_tb = 1; //seconds burntime
    	
    	//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;
    };
    Input on the code is always welcome but I was quite happy with the result, Ideally I want a better particle effect (something sparkly?) with some lightning.
    I might improve the code later depending on if I will get to use it more (or by request? ) so that it behaves a lot better in multiplayer as right now its completely client side and will have varying flightpaths for different players.

    - X
    Last edited by Xealot; Jul 10 2012 at 01:29.

  2. #2
    Thank you for sharing!

    below is a thread dedicated to tripwire flares, I have a post 2nd to last in it.
    http://forums.bistudio.com/showthrea...rigger-a-flare

    Hosting Missions for Invasion-1944, Iron Front: Liberation 1944, & Hell in the Pacific

    WarMod Series - Massive Addon & Mod Customizable Compilation Mods for Arma1, Arma2, & Arma2CO
    WarMod | A2WarMod |A2WarModACE | COWarMod | COWarModACE | COWarModI44 |COSLX

  3. #3
    Private First Class
    Join Date
    Feb 18 2007
    Posts
    32
    Author of the Thread
    I have revised the script a little and re-worked it so that it is now behaving the same for all clients over multiplayer.

    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:
    Code:
    Null = ([180,1,5,20,getPos importantGuy] call fnc_tripflare_conf) spawn fnc_tripflare_simflare;
    the fnc_tripflare_conf arguments are height, burn time, alpha min, alpha max, position.

    The only thing left with this script that I'm not completely satisfied with is the particle drop so that is subject to change sometime in the future, If you don't like it you can simply disable it by removing or commenting the drop command in fnc_tripflare_simflare.


    Just a small video to show the script in action:


    - X
    Last edited by Xealot; Jul 17 2012 at 03:39. Reason: added youtube link

  4. #4
    Would there be any interest in a non-ACE dependent script/addon emulating a bounding mine (M116, "Bouncing Betty", WWII German S-mine, etc.)?

    I've been desultorily working on one for a while. While I have more projects already planned/'in progress' than my time & (abysmal) knowledge of scripting can support, this is relatively simple for a basic emulation.

Similar Threads

  1. Tripwire Script
    By Shadow.D. ^BOB^ in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 9
    Last Post: Oct 18 2010, 03:04
  2. Flare script
    By MikeJHunter in forum ARMA 2 & OA : MISSIONS - Editing & Scripting
    Replies: 6
    Last Post: Jul 20 2009, 12:32
  3. Mine script
    By Ironsight in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 17
    Last Post: Oct 25 2005, 18:19
  4. Mapfact tripwire flare
    By Shadow in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 10
    Last Post: Sep 25 2004, 14:47
  5. Flare script
    By Sgt. Stryker in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 6
    Last Post: Mar 24 2004, 16:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •