Jump to content
Play3r

Units investigate explosion

Recommended Posts

Does any one have a Script to a hosted server that makes OpFor unit investigate explosions,
I want to have the option in my mission, that player can detonate some C4 or make a truck blow up, and then the OpFor units in a radius like 100 mtr ( variabel nummer ) run to the place.
i have found a script that makes the units run to the explosion if the objekt is placed in by the editor.

 

But the one i need is for all explosions made by the player.

 

the script i have found, don't know if it can be altered to work like i want it ?

 

Cheers 

Play3r

Object addEventHandler ["Explosion", {
    params ["_vehicle", "_damage", "_source"];
    if ((_vehicle distance _source)< 30) then {
        _list = _vehicle nearEntities ["CAManBase", 100] select {side _x == opfor}; 
        If (_list isNotEqualTo []) then {
            {
                _x doMove (getPosASL _source);
            } forEach _list;
        };
    };
}];

 

Share this post


Link to post
Share on other sites

Making it more complicated imo, to much coding involved, heres a different idea to try.

    Whatever vehicle you want the player to blow up, just give that vehicle a name and create a trigger with !alive check  ---->   !Alive vehiclename

in the condition box, then setup a group or units of enemy you want somewhere, give them a waypoint to the said vehicle area, set the end waypoint to guard or even search and destroy.

Sync the trigger to the first waypoint of the enemy group, (set waypoint activation).

 

When the player blows up the vehicle, the trigger goes off, and lets loose the enemy squad and they will come.

  • Like 1

Share this post


Link to post
Share on other sites

Hi Gunter

 

Yes I have done that, but if the player want to go in from the west and the truck is in the south. So that is why I wanted it to be any explosion anywhere on the map.

 

My idea was also to have enemy's run to it from anywhere they are, so the chance is that they will run against the player, so the player don't know where they come from.

Hope that makes any sense to why I was asking about it 

 

// Play3r 

Share this post


Link to post
Share on other sites

Ya i understand, you want to keep the enemy more dynamic as to not know where they will come from, you could set a

waypoint set it to guard and then expand the waypoint so it covers the entire AO, when they hear the explosion

then they would be inclined to investigate.

I do something like that in my ISIL Foothold mission but it dont cover the AO, just a guard waypoint and as far out as i am

when i make myself heard here they come looking for me, and you can tell they dont know where im at because their roaming around and

not engaging me til they get LOS of me, try a guard waypoint.

  • Thanks 1

Share this post


Link to post
Share on other sites
11 minutes ago, Gunter Severloh said:

Ya i understand, you want to keep the enemy more dynamic as to not know where they will come from, you could set a

waypoint set it to guard and then expand the waypoint so it covers the entire AO, when they hear the explosion

then they would be inclined to investigate.

I do something like that in my ISIL Foothold mission but it dont cover the AO, just a guard waypoint and as far out as i am

when i make myself heard here they come looking for me, and you can tell they dont know where im at because their roaming around and

not engaging me til they get LOS of me, try a guard waypoint.

 

Thanks Gunter will give it a try.

Maybe I will put 3-5 groups with a guard WP and test it.

Share this post


Link to post
Share on other sites
On 2/25/2024 at 3:06 PM, Gunter Severloh said:

you could set a

waypoint set it to guard

 

Huh, wasn't aware of this caveat of the guard waypoint. Pretty neat and simple to setup.

However I did some testing and it does seem a bit hit & miss. They'll take a full 2 minutes to react to an explosion 500 m away when there's only the explosion and no known enemy targets.

While it's probably realistic, as a player sitting and waiting for them to move, that's tad long since there are no visual or audible cues from their decision making...

They also won't move to where the explosion happens but rather stop nearby, and there's seem to be no search when they do arrive like with a S&D waypoint.

Since I was already writing up something that acts closer to how I imagined it I'll just post that below.

-----------------------------------------------------

It'd be nice if we had a mission event handler for explosions for this but as of today no such luck. So we have to jump through some hoops.

On 2/24/2024 at 6:28 PM, Play3r said:

player can detonate some C4 or make a truck blow up

Note that from the game's perspective those are 2 very different actions to monitor.

That means you have to attack this from two directions.

  1. Handle vehicles exploding
  2. Handle player detonating an explosive

Handle vehicles exploding

Add event handlers to all vehicles (including spawned vehicles)

Create initServer.sqf in your mission root and fill it with:

Spoiler

// A few settings
TAG_react_radius = 1000;
TAG_react_sides = [opfor];
TAG_react_behaviours = ["SAFE","AWARE"];
TAG_speed_of_sound = 343;
TAG_vehicle_classes = ["Car", "Tank", "Helicopter", "Plane"];
TAG_react_condition = { true }; // _this contains the group to check, can be used to stop certain groups from responding

TAG_fnc_eh_react_to_explosion = {
	params ["_position", "_damage", "_source"];
	//diag_log text format ["Boom - p: %1     d: %2     s: %3", _position, _damage, _source];
	if( _position isEqualType objNull ) then { _position = getPos _position; };	

	if ( !isNull _source && _damage > 0.01 ) then {
		
		private _list = _position nearEntities ["CAManBase", TAG_react_radius] select { side group _x in TAG_react_sides };
		{
			if( behaviour _x in TAG_react_behaviours && !( group _x getVariable ["TAG_is_deciding_reaction", false] ) ) then {
				if( leader _x == _x ) then {
					group _x setVariable ["TAG_is_deciding_reaction", true];
					
					[_x, getPos _source, _x distance _position] spawn {
						params ["_x", "_to", "_dist"];
						private _grp = group _x;

						// Simulate sound propagation and human reaction time
						sleep ( _dist / TAG_speed_of_sound ); 

						if( _grp call TAG_react_condition ) then {		
							// Simulate human decision making time
							sleep ( 5 + floor random 5 ); 

							private _original_wp = currentWaypoint _grp;
							private _wp = _grp addWaypoint [_to, 15, _original_wp];
							_wp setWaypointBehaviour "AWARE";
							_wp setWaypointType "SAD";
							_wp setWaypointSpeed "NORMAL";
							_wp setWaypointForceBehaviour true;

							_grp setCurrentWaypoint _wp;
							
							sleep 15;

							_wp setWaypointForceBehaviour false;
							
							if( _original_wp > 0 ) then {
								// Wait for Seach & Destroy wp to complete
								waitUntil { currentWaypoint _grp > _wp # 1 };

								deleteWaypoint _wp;
								// Return to previous waypoint
								if( count waypoints _grp > 0 ) then {
									_grp setCurrentWaypoint [_grp, _original_wp - 1];
								};	
							};

							_grp setVariable ["TAG_is_deciding_reaction", false];
						} else {
							_grp setVariable ["TAG_is_deciding_reaction", false];
						};
					};
				};
			};
		} forEach _list;
	};
};

// Loop over all vehicles and add event handlers to handle explosions
{ 	
	_x addEventHandler [ "Killed" , 
		{
			params ["_veh", "", "", "_useEffects"];
			if( _useEffects && { 
				{ alive _x && behaviour _x in ["COMBAT", "STEALTH"] } count crew _veh == 0 
			} ) then {
				[_veh, 1, _veh] call TAG_fnc_eh_react_to_explosion;
			};
		} 
	];
	_x addEventHandler [ "Explosion", TAG_fnc_eh_react_to_explosion ];
} forEach vehicles;

 

 

 

Handle player detonating an explosive

Add event handlers for when a player placed explosive explodes.

Create initPlayerLocal.sqf in your mission root and fill it with: 

Spoiler

player addEventHandler [
	"FiredMan", 
	{
		params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle"];
		if( _weapon == "Put" ) then {
			// Check if a it's an explosive device
			if( _ammo isKindOf ["TimeBombCore", configFile >> "CfgAmmo"] ) then {
				_projectile addEventHandler [ "Explode", 
					{
						params ["_projectile", "_pos"];
						private _args = [ ASLToAGL _pos, 1, _projectile ];
						if( isServer ) then {
							_args call TAG_fnc_eh_react_to_explosion;	
						} else {
							_args remoteExec ["TAG_fnc_eh_react_to_explosion", 2];
						};
					}
				];
			};
		};
	}	
];

 

 

Edited by mrcurry
Fixed TAG_is_deciding_reaction not resetting
  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Hi mrcurry.

I can see what you mean by a vehicle ecploding, but if player want to blow up a truck they still have to place somethnig to blow it up with, that is why i mean by "player can detonate some C4 or make a truck blow up".

Thanks for the script i will try it in my SOG misison, i'm trying to make.

 

i can see that you already have put in my next question for the units:  "do they go back to there route if they find nothing" and i see that is in the script.

 

Thanks alot mrcurry

 

// Play3r

Share this post


Link to post
Share on other sites
On 2/24/2024 at 2:28 PM, Play3r said:

Does any one have a Script to a hosted server that makes OpFor unit investigate explosions (...)

 

Hey, @Play3r pretty sure this might helps you to build your mission context:

 

 
Look at "UXO Doctrine" over there 😉
 

  • Thanks 1

Share this post


Link to post
Share on other sites
On 2/25/2024 at 3:50 PM, mrcurry said:

 

Huh, wasn't aware of this caveat of the guard waypoint. Pretty neat and simple to setup.

However I did some testing and it does seem a bit hit & miss. They'll take a full 2 minutes to react to an explosion 500 m away when there's only the explosion and no known enemy targets.

While it's probably realistic, as a player sitting and waiting for them to move, that's tad long since there are no visual or audible cues from their decision making...

They also won't move to where the explosion happens but rather stop nearby, and there's seem to be no search when they do arrive like with a S&D waypoint.

Since I was already writing up something that acts closer to how I imagined it I'll just post that below.

-----------------------------------------------------

It'd be nice if we had a mission event handler for explosions for this but as of today no such luck. So we have to jump through some hoops.

Note that from the game's perspective those are 2 very different actions to monitor.

That means you have to attack this from two directions.

  1. Handle vehicles exploding
  2. Handle player detonating an explosive

Handle vehicles exploding

Add event handlers to all vehicles (including spawned vehicles)

Create initServer.sqf in your mission root and fill it with:

  Reveal hidden contents


// A few settings
TAG_react_radius = 100;
TAG_react_sides = [opfor];
TAG_react_behaviours = ["SAFE","AWARE"];
TAG_speed_of_sound = 343;
TAG_vehicle_classes = ["Car", "Tank", "Helicopter", "Plane"];
TAG_react_condition = { true }; // _this contains the group to check, can be used to stop certain groups from responding

TAG_fnc_eh_react_to_explosion = {
	params ["_position", "_damage", "_source"];
	diag_log text format ["Boom - p: %1     d: %2     s: %3", _position, _damage, _source];
	if( _position isEqualType objNull ) then { _position = getPos _position; };	

	if ( !isNull _source && _damage > 0.01 ) then {
		
		private _list = _position nearEntities ["CAManBase", TAG_react_radius] select { side group _x in TAG_react_sides };
		{
			if( behaviour _x in TAG_react_behaviours && !( group _x getVariable ["TAG_is_deciding_reaction", false] ) ) then {
				if( leader _x == _x ) then {
					group _x setVariable ["TAG_is_deciding_reaction", true];
				};

				[_x, getPos _source, _x distance _position] spawn {
					params ["_x", "_to", "_dist"];
					private _grp = group _x;

					// Simulate sound propagation and human reaction time
					sleep ( _dist / TAG_speed_of_sound ); 

					if( leader _x == _x ) then {
						if( _grp call TAG_react_condition ) then {		
							// Simulate human decision making time
							sleep ( 5 + floor random 5 ); 

							private _original_wp = currentWaypoint _grp;
							private _wp = _grp addWaypoint [_to, 15, _original_wp];
							_wp setWaypointBehaviour "AWARE";
							_wp setWaypointType "SAD";
							_wp setWaypointSpeed "NORMAL";
							_wp setWaypointForceBehaviour true;

							_grp setCurrentWaypoint _wp;
							
							sleep 15;

							_wp setWaypointForceBehaviour false;
							
							if( _original_wp > 0 ) then {
								// Wait for Seach & Destroy wp to complete
								waitUntil { currentWaypoint _grp > _wp # 1 };

								deleteWaypoint _wp;
								// Return to previous waypoint
								if( count waypoints _grp > 0 ) then {
									_grp setCurrentWaypoint [_grp, _original_wp - 1];
								};	
							};

						} else {
							_grp setVariable ["TAG_is_deciding_reaction", false];
						};
					};
				};
			};
		} forEach _list;
	};
};

// Loop over all vehicles and add event handlers to handle explosions
{ 	
	_x addEventHandler [ "Killed" , 
		{
			params ["_veh", "", "", "_useEffects"];
			if( _useEffects && { 
				{ alive _x && behaviour _x in ["COMBAT", "STEALTH"] } count crew _veh == 0 
			} ) then {
				[_veh, 1, _veh] call TAG_fnc_eh_react_to_explosion;
			};
		} 
	];
	_x addEventHandler [ "Explosion", TAG_fnc_eh_react_to_explosion ];
} forEach vehicles;

// If you are spawning vehicles you also need this part
TAG_meh_entity_created = addMissionEventHandler [
	"EntityCreated", 
	{ 
		params [ "_entity" ];
		private _t = typeOf _entity;
		if( TAG_vehicle_classes findIf { _t isKindOf _x } >= 0 ) then {
			_entity addEventHandler [ "Killed" , 
				{
					params ["_veh", "", "", "_useEffects"];
					if( _useEffects && { 
						{ alive _x && behaviour _x in ["COMBAT", "STEALTH"] } count crew _veh == 0 
					} ) then {
						[_veh, 1, _veh] call TAG_fnc_eh_react_to_explosion; 
					};
				} 
			];
			_entity addEventHandler [ "Explosion", TAG_fnc_eh_react_to_explosion ];
		};
	} 
];

 

 

 

Handle player detonating an explosive

Add event handlers for when a player placed explosive explodes.

Create initPlayerLocal.sqf in your mission root and fill it with: 

  Reveal hidden contents


player addEventHandler [
	"FiredMan", 
	{
		params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_vehicle"];
		if( _weapon == "Put" ) then {
			// Check if a it's an explosive device
			if( _ammo isKindOf ["TimeBombCore", configFile >> "CfgAmmo"] ) then {
				_projectile addEventHandler [ "Explode", 
					{
						params ["_projectile", "_pos"];
						private _args = [ ASLToAGL _pos, 1, _projectile ];
						if( isServer ) then {
							_args call TAG_fnc_eh_react_to_explosion;	
						} else {
							_args remoteExec ["TAG_fnc_eh_react_to_explosion", 2];
						};
					}
				];
			};
		};
	}	
];

 

 

 

 

Hi @mrcurry

 

i get a error when i use the script.

Don't know i i did it wrong, but did just copy the Server script to my initserver,sqf.

also the initPlayerLocal,sqf was also got copied, but i get  error about a varible

don't know if you can guide me on what to do, my line 27 is where right under the line:
private _list = _position nearEntities ["CAManBase", TAG_react_radius] select { side group _x in TAG_react_sides };
        {    <- this is linie 27 in my script

 

https://imgur.com/EvuRJTc

i hope this helps.

 

// Cheers Play3r

 

 

Share this post


Link to post
Share on other sites
On 3/1/2024 at 3:31 PM, Play3r said:

 

 

Hi @mrcurry

 

i get a error when i use the script.

Don't know i i did it wrong, but did just copy the Server script to my initserver,sqf.

also the initPlayerLocal,sqf was also got copied, but i get  error about a varible

don't know if you can guide me on what to do, my line 27 is where right under the line:
private _list = _position nearEntities ["CAManBase", TAG_react_radius] select { side group _x in TAG_react_sides };
        {    <- this is linie 27 in my script

 

https://imgur.com/EvuRJTc

i hope this helps.

 

// Cheers Play3r

 

 

 

I double-checked the code and there's no syntax errors on my end.

The possible causes I can see are:

A - You didn't the copy the entire code

B - When you copied it some extra web characters came along for the ride

C - You did some changes in the code after copying

 

Considering the error message "Invalid number in expression" and it's position B seems most likely.

 

Finding the solution:

  1. Make sure you copied the entire initServer.sqf code.
  2. When copying code from the forum make sure you copy only from a code section and only from one code section at the time. If the selection goes outside the code tags it can introduce errors. See the spoiler below for an example.
    Spoiler

    This is inside the spoiler tag

    
    //Code section 1
    //This is inside the code tag

    This is inside the spoiler tag

    
    // Code section 2

    Remember to check so you dont copy the extra line at the end

  3. If the problem persists open your initServer.sqf in a competent text editor like Notepad++ or VSCode and look for (and remove) these naughty little buggers:
    RogueUnicodeCharacters.png?rlkey=v532hly

 

  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)

Hi mrcurry

 

Thanks for the guide, i use Posidion tools for my scripts, and i did not see any "marks" or other things when i copied it, i have removed all spaces in the script and i still get the same error, guess i have to try it in Notebook ++ then.

But thanks for the awesome guide in the problem solving, just going to bookmark this.

 

// PLay3r

all i did change was the TAG_react_radius to 250

Edited by Play3r

Share this post


Link to post
Share on other sites

heya, this looked interesting, so i tried it and it's definitely working, but am getting this error at start of mission.

 

but other than that, when i cursortarget the truck under the net in the pic, 3 groups swarm that area from their intended patrol, one of them can be seen behind the hangar and theyre set up for a 30 radius patrol, never going far away from the hangar itself. Works great. Just the error needs to go away :D   (no unwanted symbols, i checked)

 

dfdfdfdf.jpg

 

fdf.jpg

Share this post


Link to post
Share on other sites
Posted (edited)

Yes the script is awesome but i see that you have error in InitPlayerLocal and mine is in the InitServer.

 

i have just made a new copy and put it in Notepath ++ and did not see any "unwanted symbols", so will test it right now.

After my new copy i have no error what so ever, and it work great.

 

Thanks @mrcurry for the script.

Edited by Play3r
after test to tell it works..
  • Like 1

Share this post


Link to post
Share on other sites

@mrcurry i nned your help again.

 

i can only make the script run one time. 

if i place a explosive charge on the ground, and detonate it the units in the radius (set to 500) comes running.

If i then place a new one they just keep going there own ways they don't come to look.

 

@RS30002 Can you tried that?

 

Share this post


Link to post
Share on other sites
16 hours ago, Play3r said:

@mrcurry i nned your help again.

 

i can only make the script run one time. 

if i place a explosive charge on the ground, and detonate it the units in the radius (set to 500) comes running.

If i then place a new one they just keep going there own ways they don't come to look.

 

@RS30002 Can you tried that?

 

That's my bad, I missed to reset the "is reacting" flag when they were done with the investigation.

They should react as soon as the investigation is complete now, even if they are on their way back to the original position.

Also refactored the code a little bit to not run unnecessarily for soldier's who aren't group leaders.

I've updated the code in this post. Tested and works.

 

A better approach would be to queue up explosions and have the groups react in a prioritized fashion based on the closest one and spread the jobs about among several reacting groups... but I think the current setup is good enough.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
3 hours ago, mrcurry said:

That's my bad, I missed to reset the "is reacting" flag when they were done with the investigation.

They should react as soon as the investigation is complete now, even if they are on their way back to the original position.

Also refactored the code a little bit to not run unnecessarily for soldier's who aren't group leaders.

I've updated the code in this post. Tested and works.

 

A better approach would be to queue up explosions and have the groups react in a prioritized fashion based on the closest one and spread the jobs about among several reacting groups... but I think the current setup is good enough.

 

Great script.

 

how do i use:

 

TAG_react_condition = { true }; // _this contains the group to check, can be used to stop certain groups from responding

i want to exclude some named units in the area, to not get the seek and destroy waypoint

 

Share this post


Link to post
Share on other sites
21 hours ago, RS30002 said:

how do i use:

 


TAG_react_condition = { true }; // _this contains the group to check, can be used to stop certain groups from responding

i want to exclude some named units in the area, to not get the seek and destroy waypoint

 

Something like this: 

TAG_react_condition = { 
	!(_this in [group unit_name_1, group unit_name_2]) 
};

 

Edit

 @RS30002 A better way is to do this:

TAG_react_condition = { 
	_this getVariable ["react_to_explosions", true] // Check the group's setting, by default all groups react
};

and in group's init (Attributes for the group/collection):

this setVariable ["react_to_explosions", false]; // Disables reaction
// or
this setVariable ["react_to_explosions", true]; // Enables reaction

This way you do not have to list every group that should ignore it, instead you can control everything in the editor without having to do additional changes to code every time you add a new group that shouldn't react.

This also allows you to turn it on and off at will, for example when the group reaches a certain waypoint.

 

You could also add interesting behaviours by checking against the skill of the unit, make more "disciplined" units stick to their post maybe...

TAG_react_condition = {
 	_this getVariable ["react_to_explosions", true] 
	&&
	leader _this skillFinal "commanding" < 0.5 // only groups with poor leadership will react
};

 

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

×