Jump to content

[Code Snippet] Hostage Rescue Script

Recommended Posts

This is just a simple hostage rescue script that I wrote today while playing around with the new BIS subtitle and holdAction functions; it spawns a hostage, with animations, and creates a task which will complete if the hostage is freed, or fail if the hostage dies.

You have to be within 5 meters of the hostage to untie them. The hostage will automatically be deleted upon task completion.


Just paste the following code into the debug console (not MP tested because I haven't tried to make it 100% MP compatible). Enjoy.

private _position = player getPos [linearConversion [0, 1, random 1, 10, 5], random 360];

h = [_position, WEST] spawn {
	comment "HallyG's (probably buggy) hostage script";
	params [
		["_pos", [], ["", [], objNull]],
		["_side", WEST, [sideUnknown]]

	_pos = _pos call {
		if (_this isEqualType objNull) exitWith {getPosATL _this};
		if (_this isEqualType "") exitWith {getMarkerPos _this};
		if (_this isEqualType locationNull) exitWith {locationPosition _this};
		if (_this isEqualTo []) exitWith {[0,0,0]};

	if (_pos isEqualTo [0,0,0]) exitWith {};

	private _fnc_hostageSpawn = {
		params ["_centre", "_side"];

		private _type = (["b","o","i"] select ([WEST,EAST,INDEPENDENT] find _side)) + "_soldier_unarmed_f";
		private _grp = createGroup CIVILIAN;
		private _unit = _grp createUnit [_type, _centre, [], 1, "NONE"];

		_unit setCaptive true;
		_unit disableAI "MOVE";
		_unit setMimic "dead";
		removeAllWeapons _unit;

		_unit spawn {
			while {(alive _this) && (captive _this)} do {
				_this playMoveNow ("acts_aidlpsitmstpssurwnondnon" + format ["0%1",str (ceil random 5)]);
				sleep 0.1;

			if (alive _this) then {
				_this enableAI "MOVE";
				_this playMoveNow ("acts_aidlpsitmstpssurwnondnon_out");

	private _randomString = {
		private _string = "";
		private _alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

		for "_i" from 1 to _this do {
			_string = _string + (_alp select [floor random count _alp, 1]);
	sleep 1;
	private _unit = [_pos, _side] call _fnc_hostageSpawn;
	private _taskID = 8 call _randomString;

		["Rescue the hostage near to the player! You have to be within 5 meters of the hostage to untie them!", "HOSTAGE RESCUE", ""],
		[_unit, false],
	] call bis_fnc_taskCreate;

	[_unit, _taskID] spawn {
		params ["_unit", "_taskID"];
		waitUntil {!alive _unit};
		if !(([_taskID] call BIS_fnc_taskState) isEqualTo "SUCCEEDED") then {
			[_taskID, "FAILED"] call bis_fnc_taskSetState;
		"Untie Hostage",
		"(alive _target) && (_target distance _this < 5)",
		"(alive _target) && (_target distance _this < 5)",
			["Hostage #1","Hurry the f*ck up!"] remoteExec ["BIS_fnc_showSubtitle", _caller];
			_unit = (_this select 3) select 0;
			["Hostage #1","Thank you!"] remoteExec ["BIS_fnc_showSubtitle", _caller];
			_unit setMimic "combat";
			_unit enableAI "MOVE";
			_unit setCaptive false;
			sleep 1;
			[(_this select 3) select 1, "SUCCEEDED"] call bis_fnc_taskSetState;
			sleep 5;
			deleteVehicle _unit;
			["Hostage #1","What are you doing? Don't f*cking leave me here!"] remoteExec ["BIS_fnc_showSubtitle", _caller];
		[_unit, _taskID],
	] remoteExec ["bis_fnc_holdActionAdd", 0];
  • Like 1

Share this post

Link to post
Share on other sites

Nice, works well. Anyway you mind making MP compatible.




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