Jump to content
Sign in to follow this  
swot

activate trigger by firing weapon

Recommended Posts

hey guys the title says it all, i want to be able to activate a trigger by simply firing off a shot.

this is for like a shoot and scoot scenario, when i fire my rifle a team of soldiers will try and pursue me.

any help?

Share this post


Link to post
Share on other sites

yes but can an eventhandler be placed in the conditions section of a trigger, if so could you please show an example? thnx

Share this post


Link to post
Share on other sites

I'm not sure you understand how an EH works, or I'm not understanding your question.

The eventhandler is added to a unit. In this case when you add a 'fired' event handler to a unit, the EH does what ever you told it to when the unit fires his weapon.

This page has some related examples.

http://community.bistudio.com/wiki/addEventHandler

Share this post


Link to post
Share on other sites

Basic AI will act like this really as long as the shot is close enough. :)

Share this post


Link to post
Share on other sites

you need to add the event handler on the init line of the unit that fires:

FiredH = this addEventHandler ["fired", {EHScrtp = _this exec "firedweapon.sqf"}]

Then you can create the script and put a global variable there.

gotrigger = true;

Put the global variable in the condition of the trigger. If it is a MP mission you might want to use publicvariable as well

Share this post


Link to post
Share on other sites

@CarlosTex: You're using exec with .sqf, if should be execVM.

@OP: The following is what I use in an MP mission to (among other things) achieve what you want - sorta kinda. It doesn't tell them to go look for you, all it does it reveal you to nearby enemies. Their awareness of you is set to 1, but they need to get a visual confirmation on you before they open fire.

Other interesting things it does is add some camera shakes to vehicle weapons (which currently are rock solid), and initialize a flare system but this is commented out as I didn't want to include that stuff here (a bit on the advanced side).

Enemies in vehicles are not considered, as I use this in a Domination edit and vehicles there typically have their engines running. They react to rocket fire well enough anyway. Distance depends on weapon used. There are probably errors in it and stupid decisions, I just wanted to experiment a little and was happy with the results.

The script that is fired from the eventhandler:

_unit = _this select 0;
_weapon = _this select 1;
_muzzle = _this select 2;
_mode = _this select 3;
_ammo = _this select 4;
_magazine = _this select 5; //Not in use yet.
_projectile = _this select 6; //_this expanded removed, now uses internal projectile support.
_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 (_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;
	};
};
};
//For AI, add back ammo if shooting flares
if (_unit != player) then {
_restore = "";
if (_muzzle == "GP25Muzzle") then {
	switch (_ammo) do {
		case "F_40mm_White" : {_restore = "FlareWhite_GP25"};
		case "F_40mm_Green" : {_restore = "FlareGreen_GP25"};
		case "F_40mm_Red" : {_restore = "FlareRed_GP25"};
		case "F_40mm_Yellow" : {_restore = "FlareYellow_GP25"};
	};
} else {
	switch (_ammo) do {
		case "F_40mm_White" : {_restore = "FlareWhite_M203"};
		case "F_40mm_Green" : {_restore = "FlareGreen_M203"};
		case "F_40mm_Red" : {_restore = "FlareRed_M203"};
		case "F_40mm_Yellow" : {_restore = "FlareYellow_M203"};
	};
};
if (_restore != "") then {_unit addMagazine _restore};
};
//if (_ammo in _flareammo) then {
//	["glflareclient", [_projectile]] call XNetCallEvent;
//	["glflareserver", [_projectile]] call XNetCallEvent;
//};

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

×