Jump to content
Sign in to follow this  
kelgram

Ideas on how to do these scripted events?

Recommended Posts

I have almost finished my first Rainbow Six mission and I was wondering if any of these ideas I have are possible?

They are not necessary but would be nice to have as additional functionality.

For the time being I have used pseudo code to describe them. Hopefully that will be helpful as a starting point.

AI sees a Frag grenade being thrown near them / in room, shouts "Grenade / Granata"

If (Grenade fired from West && Grenade < 10 metres from enemy Soldier)
play2dsound "Grenade";

AI hears soldier running outside or shooting

If (Player is not walking && player is < 10 metres from enemy Soldier)
play2dsound "What was that?";
If (Player is firing && player is < 10 metres from enemy Soldier)
play2dsound "Holy crap. get ready for them";

Team approaches building door, says over radio "Stacking up"

If (Player is < 2 metres from building door)
playSound "Stacking up";

Player presses binded key "H" all teams stop on their waypoints

if (Player presses keybind "H")
stop all teams on side of Player;
playSound "Holding";

Player spots enemy, radios in (overrides the ArmA 3 e.g. "I saw a Chicken at 007989 , next to that Tree"

if (Player sees enemy)
do not radio position;
playSound "Contact Spotted";

Share this post


Link to post
Share on other sites

Incoming wall of text..

All the following examples are written so they can be placed in a units init box for testing.

AI sees a Frag grenade being thrown near them / in room, shouts "Grenade / Granata"

this addEventHandler [ "FiredNear", {
_unit = _this select 0;
_shooter = _this select 1;
_distanceToShooter = _this select 2;
_ammo = _this select 6;

if ( _ammo isKindOf "GrenadeHand" && _distanceToShooter < 10 && ( side _shooter ) getFriend ( side _unit ) < 0.6  ) then {
	_unit sideRadio "SentIncomingGrenade";
};
}];

Adds an eventHandler to the unit of FiredNear. If the ammo is a grenade and the shooter is nearer than 10 meters and is an enemy then they will shout incoming grenade.

AI hears soldier running outside

lastDetectDelay = 30;
this setVariable [ "lastDetect", time - lastDetectDelay ];
this setVariable [ "EIDetection", [ format[ "EIDetection_%1", str this ], "onEachFrame", {
_unit = _this;
if ( time > _unit getVariable "lastDetect" ) then {
	_enemy = _this findNearestEnemy ( getPosATLVisual _this );
	if ( !isNull _enemy && { _enemy distance _unit <= 10 &&
		{
			[ _x, animationState _enemy ] call BIS_fnc_inString
		}count [ "mrun", "mevs" ] > 0
	} ) then {
		_unit sideRadio "SentEnemyContact";
		_unit setVariable [ "lastDetect", time + lastDetectDelay ];
	};
};

}, this ] call BIS_fnc_addStackedEventHandler ];

Checks every frame whether their is an enemy within 10 meters. If that enemy is playing a running or sprinting ( evasion ) animation they will announce that they know about an enemy contact.

I have added a delay of 30 seconds so they dont keep spamming the announcement.

The onEachFrame EH ID is stored on the unit in a variable called EIDetection so you can remove it if necessary via...

[ UNIT getvariable "EIDetection", "onEachFrame" ] call BIS_fnc_removeStackedEventHandler

AI hears soldier shooting outside

this addEventHandler [ "FiredNear", {
_unit = _this select 0;
_shooter = _this select 1;
_distanceToShooter = _this select 2;
_ammo = _this select 6;

if ( _distanceToShooter < 10 && ( side _shooter ) getFriend ( side _unit ) < 0.6 ) then {
	_unit sideRadio "SentEnemyContact";
};
}];

Pretty similar to the grenade detection. Both could be added to the same EH if needed.

Team approaches building door, says over radio "Stacking up"

this setVariable [ "nearDoor", [ format [ "nearDoor_%1", str this ], "onEachFrame", {
_unit = _this;
if !( _unit getVariable [ "onDoor", false ] ) then {
	_building = nearestBuilding _unit;
	if ( _unit distance _building < 20 ) then {
		_numDoors = getNumber (configFile >> "CFGVehicles" >> typeOf _building >> "numberOfDoors");
		for "_doorNum" from 1 to _numDoors do {
			_doorPos = _building selectionPosition ( format [ "Door_%1_trigger", _doorNum ] );
			_dist = (getPosATL _unit) distance ( _building modelToWorld _doorPos );
			if ( _dist <= 2 ) exitWith {
				_unit groupChat "Stack up on that door";
				_unit setVariable [ "onDoor", true ];
				_thread = [_unit, _building, _doorPos] spawn {
					_unit = _this select 0;
					_building = _this select 1;
					_doorPos = _this select 2;
					waitUntil { _unit distance ( _building modelToWorld _doorPos ) > 5 };
					_unit setVariable [ "onDoor",  false ];
				};
			};
		};
	};
};
}, this ] call BIS_fnc_addStackedEventHandler ];

On each frame it will check for the nearest building to the unit, if its within 20 meters it will see how many doors the building has. If the unit is within 2 meters of a door it will group chat "Stack up on that door". << will need replacing with your own radio sound.

The unit will not repeat the message until it has moved 5 meters away from its current door.

As previously the EH ID is stored on the unit in a variable called nearDoor so you can remove it.

Player presses binded key "H" all teams stop on their waypoints

h = []  spawn {
waitUntil { !isNull ( findDisplay 46 ) }; 
player setVariable [ "doStopCommand", ( findDisplay 46 ) displayAddEventHandler [ "KeyDown", {
	_key = _this select 1;
	_shift = _this select 2;
	_ctrl = _this select 3;
	_alt = _this select 4;
	if ( _key == 35 && { _x }count [ _shift, _ctrl, _alt ] == 0 ) then {
		{
			if ( side _x == side player ) then {
				commandStop _x;
			};
		}forEach allUnits;
	};
}]];
};

Adds an event to the players main display of keyDown. On pressing the key all units of the players side are commanded to stop.

Mileage may very with this code and will likely need experimenting with.

TBO rather than locking a certain key to this you would be better of adding a custom action to the player.

Player spots enemy, radios in (overrides the ArmA 3 e.g. "I saw a Chicken at 007989 , next to that Tree"

Although you can get a unit to say something on spotting an enemy, overriding the default i believe is not possible without creating a mod.

All that should give you something to work from, hope it helps.

Edited by Larrow

Share this post


Link to post
Share on other sites

Dude, words cannot express my thanks.

Would you mind if I credit you in this Mission pack?

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  

×