Jump to content
Sign in to follow this  
steelblood

Detecting Firing

Recommended Posts

Hi

I was just wondering how (If it is possible) to either write a script or put some conditions on a unit so that it detects when it's been fired upon.

So i want them to be set to never fire on there waypoints UNLESS FIRED UPON so how do i do this ?

Thanks Alot

Dan :D

Share this post


Link to post
Share on other sites

On the first waypoint. Preferable one very close to their start position set the waypoint change to:

Hold Fire - The leader will order the group to hold fire and disengage (CombatMode "Green"). Individual units will open fire on any enemy units that are both aware of their individual presence and can harm them.

Or:

Hold Fire, Engage At Will - The leader will order the group to hold fire and engage enemy units at will (CombatMode "White"). Individual units will move into a position from which they could shoot at the enemy, but will only open fire on an enemy unit that becomes aware of their presence and can harm them.

Share this post


Link to post
Share on other sites
On the first waypoint. Preferable one very close to their start position set the waypoint change to:

Hold Fire - The leader will order the group to hold fire and disengage (CombatMode "Green"). Individual units will open fire on any enemy units that are both aware of their individual presence and can harm them.

Or:

Hold Fire, Engage At Will - The leader will order the group to hold fire and engage enemy units at will (CombatMode "White"). Individual units will move into a position from which they could shoot at the enemy, but will only open fire on an enemy unit that becomes aware of their presence and can harm them.

Wow thanks alot dude ;)

Share this post


Link to post
Share on other sites

hi fairly new here. I am using eventhandler since seeing this thread today.

q. Has anyone seen a script or a event type (aka fired_loud) that accounts for silenced firing.

e.g. do not fire event on player if using silenced weapon.

I guess I could use "fired" then check what weapon unit has. (problem being matching all the types of weapon if I give ammo crates or they pick up weapon)

ta

Edited by cream-t

Share this post


Link to post
Share on other sites

In addition to what Muzzleflash has sayed, you can easily check pretty reliably if a group is engaging with a script along these lines:

fn_isEngaging.sqf:

/*
  Author:
   rübe

  Description:
   returns true if anybody of the given unit(s)/group is engaging

  Parameter(s):
   _this: unit(s)/group (unit, array of units or group)

  Returns:
   boolean
*/

private ["_units", "_engaging"];

_units = [];
_engaging = false;

switch (true) do
{
  case ((typeName _this) == "ARRAY"):
  {
     _units = _this;
  };
  case ((typeName _this) == "GROUP"):
  {
     _units = units _this;
  };
  default
  {
     _units = [_this];
  };
};

{
  if ((currentCommand _x) in ["ATTACK", "ATTACKFIRE", "FIRE"]) exitWith
  {
     _engaging = true;
  };
} forEach _units;


// return status
_engaging

Of course isEngaging needs to be checked repeatedly until not relevant anymore, but it's really an easy check (say as compared to a couple of fired event handlers).

At least I make use of this function in my fsms to a great effect (for a "onEngage" pseudo event handler on which I run custom code passed as parameters... for a simple radio message or a more complex reaction).

As soon as anyone of the group is engaging, the function returns true.

And this usually means business. :shoot:

Sure, it doesn't really detect/measure the "first" shot, but if you can live with that little difference, then maybe this would be an approach to consider.

Further you might wanna look into the commang "nearTargets" which is much to offer too: for example you could answer a question like "did a group make contact yet" or even "has a group been spotted yet" (by these targets in combination with knowsAbout) etc...

Have fun.

:yay:

I guess I could use "fired" then check what weapon unit has. (problem being matching all the types of weapon if I give ammo crates or they pick up weapon)

You may get away with this by exploiting the weapons config, though I don't know much about weapon and ammo configs.

If the config doesn't tells much about this, you might get away with a inString function, that looks for a bunch of key-words in the class-strong of ammo, "SD" for example, though again, I'm not sure how reliable this would end up. If everything fails, I'm afraid you'd need to check agains a prebuild "library" of silenced weapons/ammo. Since there isn't that much silenced armament in the game anyway, this would be quite feasable, though I agree, a more generic/robust solution would be preferable.

Edited by ruebe

Share this post


Link to post
Share on other sites

How would i detect a group being fired upon though ? Such as a patrol through a town and when fired upon the waypoints and behaviour of the group change :)

Share this post


Link to post
Share on other sites

I've added this to my Domino edit. If I'm a soldier at daytime shooting in the vicinity, their knowsAbout is immediately set to 1 via reveal, and it stays that for a while. Their reaction is delayed, think of it as "what was that, should we go look" discussion (but I don't script any stopping etc, since that might have to be done on server). So they'll send in someone to check out what happened, and fire at me if they make a positive/get a visual target.

If I do it at night, and/or as a sniper with high camouflage value, they can come so close I can tie their shoes together, but they're not spotting me. Until I move :) This is with decent moonlight.

For vanilla game, I'm basing it highly pseudo on speed and caliber and shot type just so I can get some decent values from it, and reveal myself over a distance (see the comments). For ACE (when I get there) I assume I get better options.

The purpose of this whole mess is to get them to remove their oversized q-tips and aid them in their hearing, as otherwise I often get the feeling their are deaf as hell when you start shooting some 3-500 meters from their position. I don't know how successful this attempt is.

Might be an idea not to run it if other AI enhancement scripts are found running. Also some camShake stuff I'm adding for mounted guns, leaving it in in case someone wants to use it. Script/EH-Fired is run on client (any locality things to be aware of with reveal?):

In player setup script:

player addEventHandler ["fired",{_this + [nearestObject [_this select 0,_this select 4]] spawn DOM_EH_Fired}];
d_shottimer = 10;
d_shottimerold = 0;

DOM_EH_Fired (precompiled)

_unit = _this select 0;
_weapon = _this select 1;
_muzzle = _this select 2;
_mode = _this select 3;
_ammo = _this select 4;
_projectile = _this select 5; //Needed for stuff I'm not including here.
_vehtype = typeOf vehicle _unit;
_shaketypes1 = ["HMMWV_M1151_M2_DES_EP1","HMMWV_M998A2_SOV_DES_EP1","HMMWV_MK19_DES_EP1","HMMWV_M1151_M2_CZ_DES_EP1"]; //Less stable platform
_shaketypes2 = ["HMMWV_M998_crows_MK19_DES_EP1","HMMWV_M998_crows_M2_DES_EP1","M1126_ICV_M2_EP1","M1126_ICV_mk19_EP1","M1128_MGS_EP1","M2A2_EP1","M2A3_EP1","M6_EP1","M1129_MC_EP1"]; //More stable platform
_flareammo = ["F_40mm_White","F_40mm_Green","F_40mm_Red","F_40mm_Yellow"];
_flaremagsw = ["FlareWhite_M203","FlareGreen_M203","FlareRed_M203","FlareYellow_M203"];
_flaremagse = ["FlareWhite_GP25","FlareGreen_GP25","FlareRed_GP25","FlareYellow_GP25"];

//if(d_debug_mode) then {
//	_s = format ["Fired eventhandler fired:_unit = %1\n_wpn = %2\n_muzzle = %3\n_mode = %4\n_ammo = %5\n_proj = %6",_unit,_weapon,_muzzle,_mode,_ammo,_projectile];
//	hint _s; diag_log _s;
//};
if (_unit == vehicle player) then {
if (player != vehicle player) then {
	if (_vehtype in _shaketypes1) then {
		switch (_weapon) do {
			case "M2" : {addCamShake [3,0.7,20]};
			case "M2BC" : {addCamShake [0.8,0.7,20]};
			case "MK19" : {addCamShake [4,0.7,20]};
			case "M240_veh" : {addCamShake [0.6,0.7,20]};
		};
	} else {
		if (_vehtype in _shaketypes2) then {
			switch (_weapon) do {
				case "M2" : {addCamShake [0.2,0.35,20]}; //MGS, CROWS
				case "M2BC" : {addCamShake [0.4,0.7,20]}; //Stryker M2
				case "MK19" : {addCamShake [4,0.7,20]};
				case "MK19BC" : {addCamShake [2,0.35,20]}; //Stryker Mk19
				case "M240_veh" : {addCamShake [0.3,0.35,20]}; //Bradley/Linebacker
				case "M242BC" : {addCamShake [0.4,0.35,20]}; //Bradley/Linebacker
				case "M68" : {addCamShake [3,1,10]}; //MGS 105mm
			};
		};
	};
} else {
	if (_weapon in ["M136","RPG18"]) then {player removeWeapon secondaryWeapon player};
	d_shottimer = time;
	_check = false;
	if (_ammo isKindOf "BulletBase") then {
		_check = true;
	} else {
		if (_ammo isKindOf "RocketBase") then {
			_check = true;
		} else {
			if (_ammo isKindOf "MissileBase") then {
				_check = true;
			};
		};
	};
	if (d_shottimer > d_shottimerold && _check) then { //
		_radius = 300;
		d_shottimerold = time + 5;
		_enemies = [];
		_speed = (getNumber (configFile >> "CfgMagazines" >> (currentMagazine player) >> "initSpeed"));
		_caliber = getNumber (configFile >> "CfgAmmo" >> _ammo >> "caliber");
		if (_ammo isKindOf "BulletBase") then {
			_radius = (0.4 + (random 0.2)) * _speed * _caliber; //higher speed and caliber makes easier to detect due higher bang
		} else { //Gives Mk17 about 400, Mk17SD 150-200, Mk16 200-300, Mk16SD 70-100, M9 50-80, 
			if (_ammo isKindOf "RocketBase") then {
				_radius = 12500 * sqrt(1/_speed); //slower speed makes easier to detect since can be observed for longer
			} else { //Gives M136 about 400, MAAWS about 800
				if (_ammo isKindOf "MissileBase") then {
					_radius = 7500 * sqrt (1/_speed) //too slow speeds needs to reduce the factor, but still detects further away than rockets;
				}; //Gives stingers about 1200, Javelin and Dragon about 1600m
			};
		};
		_delay = (2 + random 4) * ((5-(_radius * 0.002)) max 1);
		_enemies = nearestObjects [player,["SoldierEB","StaticWeapon"],_radius];
		sleep _delay;
		{_x reveal player} forEach _enemies;
		if (d_debug_mode) then {player globalChat format ["delay: %1\nradius: %2\nspeed: %3\nRevealed to %4 enemies.", _delay, _radius, _speed, count _enemies]};
	};
};
};
//Stuff removed that is not relevant here.

It could probably be refined to death with all kinds of checks and possibilities, but I only need some reactions going when someone starts shooting in "their territory".

Share this post


Link to post
Share on other sites

@CarlGustaffa

Did you already made some experience how "addCamShake" behave in MP?

I use this in some of my impact features too and it always works in SP but in MP it has a strange behaviour sometimes it works sometimes not...

I use "addCamShake" on local/client side only in MP so any ideas why it behave like this?

Share this post


Link to post
Share on other sites

Server difficulty setting maybe? There is one called camerashake that might make a difference. I'm displaying server difficulty modes in my edit, using this in init.sqf:

//Difficultymodes:
d_diffmodes = [];
{d_diffmodes set [count d_diffmodes, [_x,difficultyEnabled _x]]} forEach [
"3rdPersonView","armor","autoSpot","autoGuideAT","autoAim","camerashake","clockIndicator","deathMessages","enemyTag","friendlyTag",
"hud","hudPerm","hudWp","hudWpPerm","map","netStats","suppressPlayer","tracers","ultraAI","weaponCursor"
]; //allowSeagull not relevant, realisticFatigue not supported afaik, unlimitedSaves not relevant. Camerashake is missing from biki.

And showing the result in a dialog.

Share this post


Link to post
Share on other sites
Server difficulty setting maybe?

Yep look's likt that's it. ;)

Many thank's CarlGustaffa. :)

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
Sign in to follow this  

×