Jump to content
mrflay

Detecting when satchel / demolition charge is detonated

Recommended Posts

I need a way to detect when the player detonates a satchel charge close to a helicopter wreck. I tried the "FiredNear" event, but it only fires then the satchel is placed, not when it is detonated.

As a workaround I wrote this script that detects when the satchel is placed and then waits for it to explode.

/* FLAY_fnc_ExplosionDetector
* 
* Description:
*      This script is used to detect when a satchel or demolition charge detonates.
*
* Usage:
*      [<detector>, (<radius>), (<callback>)] call FLAY_fnc_ExplosionDetector
*
* Params:
*       <detector>: OBJECT - Any object (used to determine the detection radius). 
*         <radius>: NUMBER - Maximum distance from the detector an explosion will be detected.
*		 <callback>: CODE   - Function that should be called when explosion is detected.
*
* Notes:
*      The callback is passed two arguments when an explosion is detected:
*      
*        <detector>: OBJECT - The detector object. 
*       <explosive>: OBJECT - The explosive object that detonated.
*/

private ["_detector", "_radius", "_callback"];

_detector = _this select 0;
_radius = [_this,1,50,[0]] call BIS_fnc_param;
_callback = [_this,2,{},[{}]] call BIS_fnc_param;

_detector setVariable ["flay.detector.status", false];
_detector setVariable ["flay.detector.radius", _radius];
_detector setVariable ["flay.detector.callback", _callback];

FLAY_ev_ExplosionDetectorHandler = {

_ammo = _this select 6;

if (_ammo in ["DemoCharge_Remote_Ammo", "SatchelCharge_Remote_Ammo"]) then { 

	_this spawn {

		private ["_detector", "_unit", "_ammo", "_explosive", "_distance", "_radius", "_callback"];

		_detector = _this select 0;
		_unit = _this select 1;    // unit that placed the explosive
		_ammo = _this select 6;

		_explosive = (position _unit) nearestObject _ammo;

		waitUntil { not (alive _explosive) };

		_distance = _explosive distance _detector;
		_radius = _detector getVariable ["flay.detector.radius", 0];

		if (_distance < _radius) then {
			_detector setVariable ["flay.detector.status", true];
			_callback = _detector getVariable "flay.detector.callback";
			if (!isNil _callback) then {
				[_detector, _explosive] call _callback;
			};
		};
	};
};
};

_detector addEventHandler ["FiredNear", { _this call FLAY_ev_ExplosionDetectorHandler; } ];

While this gets the job done, I would prefer a simpler solution/workaround if there is one.

Any ideas?

Share this post


Link to post
Share on other sites
I tried the "FiredNear" event, but it only fires then the satchel is placed, not when it is detonated.

It's worse than that. firednear doesn't work at all on dedicated servers, so this is strictly limited to single player without some funky remote scripting.

If you have a look for my tky_ied stuff that was released for Arma2, you can see how I did it. The way forward is to put a dummy object under the wreck and put a handledamage on that that senses damage from a satchel. Why a dummy object? Because the chances are handle damage won't work on a wreck.

Also, because satchels are so big, if you have more than one wreck nearby, they'll all get damaged by the satchel. Again, had some success in tky_ied with this. Have a look at my code and it's workarounds.

Edited by Tankbuster

Share this post


Link to post
Share on other sites
It's worse than that. firednear doesn't work at all on dedicated servers, so this is strictly limited to single player without some funky remote scripting.

Awesome! :p

If you have a look for my tky_ied stuff that was released for Arma2, you can see how I did it. The way forward is to put a dummy object under the wreck and put a handledamage on that that senses damage from a satchel. Why a dummy object? Because the chances are handle damage won't work on a wreck.

When I tried this approach I had issues with the wreck completely blocking the blast so the handledamage event handler did not execute. I was using the soda can object since it was the most inconspicuous item that would take damage. Is there another item that works better, or should I just litter the area with soda cans? :)

Also, because satchels are so big, if you have more than one wreck nearby, they'll all get damaged by the satchel. Again, had some success in tky_ied with this. Have a look at my code and it's workarounds.

Thanks, I'll take a peek.

Share this post


Link to post
Share on other sites

I THINK I used the heliempty. I can't get at my main PC right now. Try using that as a dummy object.

Share this post


Link to post
Share on other sites
I THINK I used the heliempty. I can't get at my main PC right now. Try using that as a dummy object.

I could not get it to work with the heliempty. Anyways, It's not a big deal. The mission I'm doing is single player, so using the "FiredNear" event is not a problem. I'll keep your solution in mind for the future though. Thanks!

Share this post


Link to post
Share on other sites

Hi, yes this is necro post. So can you help me, how exactly use your script? Where you put script and conditions? If it possible to place entire code on object or trigger or somethig. I have some mission and needed to find who is placed satchel or demoCharge. Thanks for your help.

On 8/7/2013 at 11:36 AM, mrflay said:

I need a way to detect when the player detonates a satchel charge close to a helicopter wreck. I tried the "FiredNear" event, but it only fires then the satchel is placed, not when it is detonated.

As a workaround I wrote this script that detects when the satchel is placed and then waits for it to explode.

  Reveal hidden contents

 



/* FLAY_fnc_ExplosionDetector
* 
* Description:
*      This script is used to detect when a satchel or demolition charge detonates.
*
* Usage:
*      [<detector>, (<radius>), (<callback>)] call FLAY_fnc_ExplosionDetector
*
* Params:
*       <detector>: OBJECT - Any object (used to determine the detection radius). 
*         <radius>: NUMBER - Maximum distance from the detector an explosion will be detected.
*		 <callback>: CODE   - Function that should be called when explosion is detected.
*
* Notes:
*      The callback is passed two arguments when an explosion is detected:
*      
*        <detector>: OBJECT - The detector object. 
*       <explosive>: OBJECT - The explosive object that detonated.
*/

private ["_detector", "_radius", "_callback"];

_detector = _this select 0;
_radius = [_this,1,50,[0]] call BIS_fnc_param;
_callback = [_this,2,{},[{}]] call BIS_fnc_param;

_detector setVariable ["flay.detector.status", false];
_detector setVariable ["flay.detector.radius", _radius];
_detector setVariable ["flay.detector.callback", _callback];

FLAY_ev_ExplosionDetectorHandler = {

_ammo = _this select 6;

if (_ammo in ["DemoCharge_Remote_Ammo", "SatchelCharge_Remote_Ammo"]) then { 

	_this spawn {

		private ["_detector", "_unit", "_ammo", "_explosive", "_distance", "_radius", "_callback"];

		_detector = _this select 0;
		_unit = _this select 1;    // unit that placed the explosive
		_ammo = _this select 6;

		_explosive = (position _unit) nearestObject _ammo;

		waitUntil { not (alive _explosive) };

		_distance = _explosive distance _detector;
		_radius = _detector getVariable ["flay.detector.radius", 0];

		if (_distance < _radius) then {
			_detector setVariable ["flay.detector.status", true];
			_callback = _detector getVariable "flay.detector.callback";
			if (!isNil _callback) then {
				[_detector, _explosive] call _callback;
			};
		};
	};
};
};

_detector addEventHandler ["FiredNear", { _this call FLAY_ev_ExplosionDetectorHandler; } ];
 

 

While this gets the job done, I would prefer a simpler solution/workaround if there is one.

Any ideas?

 

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

×