Event handler for objects being hit/damaged

Workshop for all Mission Engineer Comrades. Home of the FA Mission Making Template.
Post Reply
EsotericReverie
Posts: 84
Joined: Thu Sep 05, 2013 8:30 am

Event handler for objects being hit/damaged

Post by EsotericReverie »

Hi everyone!

I'm rather new to this forum, having only played ArmA 3 for a few weeks, and never really played 2. I was very fond the original OP Flashpoint but only the single player campaign, and also rather liked Dragon Rising. I play a good deal of Planetside 2 with RPS folk and part of that band of friends have now started looking into ArmA 3. We're working on getting to know the editor, which is good fun, but sometimes hard and confusing.

One thing that I've currently got a problem with is simulating IEDs. I've got all the basics down, have a thing in the world, add a trigger, spawn a shell that explodes. BOOM! But I want to be able to simulate unstable explosives, that will ignite if shot at, for instance, and I can't figure out how to do that.

I've tried adding triggers based on damage values for these plastic containers I have, seems to do nothing. I've also tried adding event handlers for the "hit" and "hitPart" events on the containers. They don't seem to get triggered.

Do only some object types get events? If so, is there a way to achieve what I want to do?

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: Event handler for objects being hit/damaged

Post by wolfenswan »

Try HandleDamage, it passes the projectile.

For example something I made to make only demo charges hurt crates:

Code: Select all

_box addEventHandler [
	"HandleDamage",
	{
	 _box = _this select 0;
	 _ammoName = _this select 4;

	 if (_ammoName == "DemoCharge_Remote_Ammo") then {
	 	[_box] execVM "ws_scripts\ws_eola_cache_destroyed.sqf";
	 	};
	}];
And ws_eola_cache_Destroyed.sqf:

Code: Select all

if !(isServer) exitWith {};

_box = _this select 0;
_box setDamage 1;
deleteVehicle _box ;

if (isNil "ws_eola_caches_destroyed") then {ws_eola_caches_destroyed = 0};
ws_eola_caches_destroyed = ws_eola_caches_destroyed + 1; publicVariable "ws_eola_caches_destroyed";

if (ws_eola_caches_destroyed < ws_eola_caches_target ) then {

[[format ["A cache has been destroyed. Caches remaining: %1",(ws_eola_caches_target - ws_eola_caches_destroyed)],"PLAIN"],"BIS_fnc_titleText",true] spawn BIS_fnc_MP;
} else {
[["All caches were destroyed!","PLAIN"],"BIS_fnc_titleText",true] spawn BIS_fnc_MP;
sleep 5;
	myEnd = [ws_eola_ending] execVM "f\server\f_mpEndBroadcast.sqf";
};
If you wanted to simulate a stray bullet causing a car or crate to explode you'd have to add an eventhandler using HandleDamage checking if one of the "bullet" ammo types hit it and roll the dice.

EsotericReverie
Posts: 84
Joined: Thu Sep 05, 2013 8:30 am

Re: Event handler for objects being hit/damaged

Post by EsotericReverie »

Like so, for instance, on the Init of the canisters?

Code: Select all

h1 = this addEventHandler ["HandleDamage", {BombActivated = true;}];
Edit to clarify:
I don't really care much what kind of damage it is, just that it's enough, I suppose

Code: Select all

_this getDammage > /threshold/
would do for that.

EsotericReverie
Posts: 84
Joined: Thu Sep 05, 2013 8:30 am

Re: Event handler for objects being hit/damaged

Post by EsotericReverie »

I actually also have a trigger that triggers on:
IED1 getDammage > 0.1 or IED2 getDammage > 0.1 ...
That doesn't seem to do anything much.

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: Event handler for objects being hit/damaged

Post by wolfenswan »

the problem with the HandleDamage Eventhandler is that you might be overriding the damage passed to the unit, making it not receive any damage.

Use sth. like this to get an idea of how it works:

Code: Select all

this addEventHandler [
   "HandleDamage",
   {
    _box = _this select 0;
_damage = _this select 2;
_source = _this select 3;
    _ammoName = _this select 4;
    
damage _box = damage _box + _damage;  // This makes sure that the damage received is passed on.

    player globalchat format ["%1 was damaged for %2 by %3, using %4. Total damage is %5",_box,_Damage,_source,_ammoName,getDamage _box];
   }];

EsotericReverie
Posts: 84
Joined: Thu Sep 05, 2013 8:30 am

Re: Event handler for objects being hit/damaged

Post by EsotericReverie »

Yeah, the correct syntax would be:

Code: Select all

this addEventHandler [
   "HandleDamage",
   {
    _box = _this select 0;
_damage = _this select 2;
_source = _this select 3;
    _ammoName = _this select 4;
    
_box setDamage getDa[b]mm[/b]age _box + _damage;  // This makes sure that the damage received is passed on.

    player globalchat format ["%1 was damaged for %2 by %3, using %4. Total damage is %5",_box,_Damage,_source,_ammoName,getDamage _box];
   }];
Although that too does nothing. Not even this does anything:

Code: Select all

this addEventHandler [
   "HandleDamage",
   {hint "gotcha!"}];
Something makes me think the HandleDamage event is not fired for the plastic canister...

User avatar
wolfenswan
Posts: 1209
Joined: Wed May 25, 2011 4:59 pm

Re: Event handler for objects being hit/damaged

Post by wolfenswan »

that might be true, some of the misc. objects don't have a damage model most likely.

Post Reply