Jump to content
Sign in to follow this  
Apocal

Can anyone recommend a good restricted area script?

Recommended Posts

Has anyone tried out any area restriction scripts and which would you recommend?

Alternatively, is there anywhere where the "Zone Restriction" module is explained? I looked on Biki modules page but it's not covered there as of two hours ago.

Share this post


Link to post
Share on other sites

Didn't know there was a zone restriction module, heh never checked. In my map I just make a big a couple big box triggers surrounding the AO. First one gives you a warning if you leave it, second one puts a bullet between your eyes.

Share this post


Link to post
Share on other sites
Didn't know there was a zone restriction module, heh never checked. In my map I just make a big a couple big box triggers surrounding the AO. First one gives you a warning if you leave it, second one puts a bullet between your eyes.

Problem in my case is the AI. It winds up quite frequently piled up dead at the boundaries, thanks to the new flanking behavior driving it very wide of it's target.

Share this post


Link to post
Share on other sites

If you want it to only affect one unit (the player), just group the triggers to the player. Also what I did.

Share this post


Link to post
Share on other sites

I would just have the trigger double check its not an AI before killing them and if its an AI then have it doMove something like 50 meters towards the center of the allowed area.

Share this post


Link to post
Share on other sites

Gave it a shot and got it working. Unfortunately the script-heavy tacAI doesn't like obeying "doMove" :mad:

Share this post


Link to post
Share on other sites

This script is from my ctf template. It only works with human players but I think it can be adjusted for AI too. Markers BASE_EAST_1, ..., BASE_WEST_1, ..., GAME_AREA_1, ... Look how it's done and adjust to your needs.

//////////VARIABLES
////////////////////////////////////////////////////////////////////////////////
MARK_GAMEAREAS = true;
MARK_SPAWNAREAS_WEST = true;
MARK_SPAWNAREAS_EAST = true;

SPAWNAREAS_WEST = [];
SPAWNAREAS_EAST = [];
GAMEAREAS = [];

F_ROTATION =
{
private ["_p_dir", "_x", "_y", "_x_2", "_y_2"];

_p_dir = _this select 2;

_x = ((_this select 0) select 0) - ((_this select 1) select 0);
_y = ((_this select 0) select 1) - ((_this select 1) select 1);

_x_2 = _x * (cos _p_dir) + _y * (sin _p_dir);
_y_2 = -1 * _x * (sin _p_dir) + _y * (cos _p_dir);

[_x_2 + ((_this select 1) select 0), _y_2 + ((_this select 1) select 1)]
};

F_BORDERS =
{
private
[
	"_p_base_areas",
	"_p_game_areas",
	"_p_obj",
	"_p_step",
	"_idx_limit",
	"_f_ingamearea",
	"_idx_area",
	"_center",
	"_w",
	"_h",
	"_d",
	"_rect",
	"_i",
	"_x_strt",
	"_y_strt",
	"_x_end",
	"_y_end",
	"_x",
	"_y",
	"_obj_pos",
	"_obj",
	"_angle_step",
	"_prev_obj_pos",
	"_tmp",
	"_x_tan",
	"_y_tan"
];

_p_base_areas = _this select 0;
_p_game_areas = _this select 1;
_p_obj = _this select 2;
_p_step = _this select 3;

_idx_limit = (count _p_base_areas);

_f_ingamearea =
{
	private
	[
		"_p_obj_pos",
		"_p_idx_area",
		"_p_idx_limit",
		"_res",
		"_idx_area",
		"_center",
		"_w",
		"_h",
		"_d",
		"_rect",
		"_x_min",
		"_x_max",
		"_y_min",
		"_y_max",
		"_p_obj_pos_2"
	];

	_p_obj_pos = _this select 0;
	_p_idx_area = _this select 1;
	_p_idx_limit = _this select 2;
	_res = true;

	if (surfaceIsWater [_p_obj_pos select 0, _p_obj_pos select 1]) exitWith {_res = false; _res};

	_idx_area = 0;
	{
		scopeName "loop";

		if (_idx_area != _p_idx_area) then
		{
			_center = position _x;
			_w = triggerArea _x select 0;
			_h = triggerArea _x select 1;
			_d = triggerArea _x select 2;
			_rect = triggerArea _x select 3;

			if (_rect) then // rectangle
			{
				_x_min = (_center select 0) - _w;
				_x_max = (_center select 0) + _w;
				_y_min = (_center select 1) - _h;
				_y_max = (_center select 1) + _h;
				_p_obj_pos_2 = [_p_obj_pos, _center, -_d] call F_ROTATION;

				if
				(
					((_p_obj_pos_2 select 0) >= _x_min) &&
					((_p_obj_pos_2 select 0) <= _x_max) &&
					((_p_obj_pos_2 select 1) >= _y_min) &&
					((_p_obj_pos_2 select 1) <= _y_max)
				)
				then
				{
					if (_idx_area < _p_idx_limit) then
					{
						_res = false;
						breakOut "loop";
					}
					else
					{
						_res = true;
						breakOut "loop";
					};
				}
				else
				{
					if (_idx_area >= _p_idx_limit) then
					{
						_res = false;
					};
				};
			}
			else
			{
				if (_w == _h) then // circle
				{
					if ((_p_obj_pos distance _center) <= _w) then
					{
						if (_idx_area < _p_idx_limit) then
						{
							_res = false;
							breakOut "loop";
						}
						else
						{
							_res = true;
							breakOut "loop";
						};
					}
					else
					{
						if (_idx_area >= _p_idx_limit) then
						{
							_res = false;
						};
					};
				}
				else // ellipse
				{
					_p_obj_pos_2 = [_p_obj_pos, _center, -_d] call F_ROTATION;

					if
					(
						(
							((((_p_obj_pos_2 select 0) - (_center select 0)) / _w) ^ 2) +
							((((_p_obj_pos_2 select 1) - (_center select 1)) / _h) ^ 2)
						) <= 1
					)
					then
					{
						if (_idx_area < _p_idx_limit) then
						{
							_res = false;
							breakOut "loop";
						}
						else
						{
							_res = true;
							breakOut "loop";
						};
					}
					else
					{
						if (_idx_area >= _p_idx_limit) then
						{
							_res = false;
						};
					};
				};
			};
		};
		_idx_area = _idx_area + 1;
	} forEach (_p_base_areas + _p_game_areas);

	_res
};

_idx_area = 0;
{
	_center = position _x;
	_w = triggerArea _x select 0;
	_h = triggerArea _x select 1;
	_d = triggerArea _x select 2;
	_rect = triggerArea _x select 3;

	if (_rect) then // rectangle
	{
		_x_strt = (_center select 0) - _w;
		_x_end = (_center select 0) + _w;
		_y = (_center select 1) + _h;

		for "_i" from _x_strt to _x_end step _p_step do // top
		{
			_obj_pos = [[_i, _y], _center, _d] call F_ROTATION;
			if ([_obj_pos, _idx_area, _idx_limit] call _f_ingamearea) then
			{
				_obj = _p_obj createVehicleLocal _obj_pos;
				_obj setPos _obj_pos;
				_obj setDir (_d + 180);
			};
		};

		_x_strt = (_center select 0) - _w;
		_x_end = (_center select 0) + _w;
		_y = (_center select 1) - _h;

		for "_i" from _x_strt to _x_end step _p_step do // bottom
		{
			_obj_pos = [[_i, _y], _center, _d] call F_ROTATION;
			if ([_obj_pos, _idx_area, _idx_limit] call _f_ingamearea) then
			{
				_obj = _p_obj createVehicleLocal _obj_pos;
				_obj setPos _obj_pos;
				_obj setDir _d;
			};
		};

		_y_strt = (_center select 1) - _h;
		_y_end = (_center select 1) + _h;
		_x = (_center select 0) - _w;

		for "_i" from _y_strt to _y_end step _p_step do // left
		{
			_obj_pos = [[_x, _i], _center, _d] call F_ROTATION;
			if ([_obj_pos, _idx_area, _idx_limit] call _f_ingamearea) then
			{
				_obj = _p_obj createVehicleLocal _obj_pos;
				_obj setPos _obj_pos;
				_obj setDir (_d + 90);
			};
		};

		_y_strt = (_center select 1) - _h;
		_y_end = (_center select 1) + _h;
		_x = (_center select 0) + _w;

		for "_i" from _y_strt to _y_end step _p_step do // right
		{
			_obj_pos = [[_x, _i], _center, _d] call F_ROTATION;
			if ([_obj_pos, _idx_area, _idx_limit] call _f_ingamearea) then
			{
				_obj = _p_obj createVehicleLocal _obj_pos;
				_obj setPos _obj_pos;
				_obj setDir (_d - 90);
			};
		};
	}
	else
	{
		if (_w == _h) then // circle
		{
			_angle_step = 2 * (asin ((_p_step / 2) / _w));
			_x_strt = _center select 0;
			_y_strt = (_center select 1) + _w;

			for [{_i = 0}, {_i < 360}, {_i = _i + _angle_step}] do
			{
				_obj_pos = [[_x_strt, _y_strt], _center, _i] call F_ROTATION;
				if ([_obj_pos, _idx_area, _idx_limit] call _f_ingamearea) then
				{
					_obj = _p_obj createVehicleLocal _obj_pos;
					_obj setPos _obj_pos;
					_obj setDir (_i + 180);
				};
			};
		}
		else // ellipse
		{
			_prev_obj_pos = [0, 0];
			if (_w > _h) then
				{_angle_step = 2 * (asin ((_p_step / 2) / _w)) * (_h / _w)}
			else
				{_angle_step = 2 * (asin ((_p_step / 2) / _h)) * (_w / _h)};

			for "_i" from 0 to 360 step _angle_step do
			{
				_obj_pos =
				[
					(_center select 0) + _w * (cos _i),
					(_center select 1) + _h * (sin _i)
				];

				if ((_prev_obj_pos distance _obj_pos) >= _p_step) then
				{
					_prev_obj_pos = _obj_pos;

					_tmp = sqrt ((_h ^ 2) * ((cos _i) ^ 2) + (_w ^ 2) * ((sin _i) ^ 2));
					_x_tan = (-1 * _w * (sin _i)) / _tmp;
					_y_tan = (_h * (cos _i)) / _tmp;

					_obj_pos = [_obj_pos, _center, _d] call F_ROTATION;
					if ([_obj_pos, _idx_area, _idx_limit] call _f_ingamearea) then
					{
						_obj = _p_obj createVehicleLocal _obj_pos;
						_obj setPos _obj_pos;
						_obj setDir (_d + (_x_tan atan2 _y_tan) - 90);
					};
				};
			};
		};
	};
	_idx_area = _idx_area + 1;
} forEach _p_base_areas;
};
////////////////////////////////////////////////////////////////////////////////




//////////CTF TRIGGERS, FLAG MARKERS
////////////////////////////////////////////////////////////////////////////////
_m_name = "";

_m_color =
if (markerType "respawn_west" != "") then {
markerColor "respawn_west";

} else {
if (markerType "respawn_west_1" != "") then {
markerColor "respawn_west_1";

} else {
"colorgreen";
}};

_i = 1;
while {call compile format ["markerType 'BASE_WEST_%1' != ''", _i]} do
{
call compile format ["_m_name = 'BASE_WEST_%1'", _i];
_m_color = markerColor _m_name;

_trig = createTrigger ["emptydetector", markerPos _m_name];
_trig setTriggerArea [markerSize _m_name select 0, markerSize _m_name select 1, markerDir _m_name, markerShape _m_name == "rectangle"];
_trig setTriggerActivation ["east", "present", true];
_trig setTriggerStatements ["vehicle player in thisList", "player setDamage 1", ""];

SPAWNAREAS_WEST = SPAWNAREAS_WEST + [_trig];
_i = _i + 1;
};

_marker = createMarkerLocal ["FLAG_WEST", position FLAG_WEST];
_marker setMarkerShapeLocal "icon";
_marker setMarkerTypeLocal "flag1";
_marker setMarkerSizeLocal [1, 1];
_marker setMarkerColorLocal _m_color;

if (markerType "respawn_east" != "") then {
markerColor "respawn_east";

} else {
if (markerType "respawn_east_1" != "") then {
markerColor "respawn_east_1";

} else {
"colorred";
}};

_i = 1;
while {call compile format ["markerType 'BASE_EAST_%1' != ''", _i]} do
{
call compile format ["_m_name = 'BASE_EAST_%1'", _i];
_m_color = markerColor _m_name;

_trig = createTrigger ["emptydetector", markerPos _m_name];
_trig setTriggerArea [markerSize _m_name select 0, markerSize _m_name select 1, markerDir _m_name, markerShape _m_name == "rectangle"];
_trig setTriggerActivation ["west", "present", true];
_trig setTriggerStatements ["vehicle player in thisList", "player setDamage 1", ""];

SPAWNAREAS_EAST = SPAWNAREAS_EAST + [_trig];
_i = _i + 1;
};

_marker = createMarkerLocal ["FLAG_EAST", position FLAG_EAST];
_marker setMarkerShapeLocal "icon";
_marker setMarkerTypeLocal "flag1";
_marker setMarkerSizeLocal [1, 1];
_marker setMarkerColorLocal _m_color;

_i = 1;
while {call compile format ["markerType 'GAME_AREA_%1' != ''", _i]} do
{
call compile format ["_m_name = 'GAME_AREA_%1'", _i];

_trig = createTrigger ["emptydetector", markerPos _m_name];
_trig setTriggerArea [markerSize _m_name select 0, markerSize _m_name select 1, markerDir _m_name, markerShape _m_name == "rectangle"];
_trig setTriggerActivation ["any", "present", true];
_trig setTriggerStatements ["! (vehicle player in thisList) && alive player", "", ""];

GAMEAREAS = GAMEAREAS + [_trig];
_i = _i + 1;
};

if (count GAMEAREAS > 0) then
{
_grp = createGroup sideLogic;
_unit = _grp createUnit ["logic", [0, 0], [], 0, "none"];

_waypoint = _grp addWaypoint [[0, 0], 0];
_waypoint setWaypointType "and";
_waypoint setWaypointStatements ["true", "player setDamage 1"];
{_x synchronizeWaypoint [_waypoint]} forEach GAMEAREAS;

_waypoint = _grp addWaypoint [[0, 0], 0];
_waypoint setWaypointType "cycle";
};

if (MARK_SPAWNAREAS_WEST && count SPAWNAREAS_WEST > 0) then {
[sPAWNAREAS_WEST, GAMEAREAS, "sign_mp_op", 10] spawn {call F_BORDERS};
};

if (MARK_SPAWNAREAS_EAST && count SPAWNAREAS_EAST > 0) then {
[sPAWNAREAS_EAST, GAMEAREAS, "sign_mp_blu", 10] spawn {call F_BORDERS};
};

if (MARK_GAMEAREAS && count GAMEAREAS > 0) then {
[GAMEAREAS, [], "sign_danger", 10] spawn {call F_BORDERS};
};
////////////////////////////////////////////////////////////////////////////////

Share this post


Link to post
Share on other sites

Thank you very much d3nn, gonna give it a shot and see if AI obey the posted limits.

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  

×