Jump to content
Sign in to follow this  
cowboymiller

StayZone Scripting NOT in mission editor

Recommended Posts

Hey guys, having some trouble and thought i would reach out rather than pull my hair out. It may seem simple to some so please refrain from the hating. Im trying to create a Stayzone if you will using scripts. NOT in the mission editor. Where i place a marker, and the players MUST stay with in the marker area. if they venture out of the marker area, a timer is displayed of a given amount that they can return into the marker area with out being hurt or killed. Yes i can easily do this with the mission editor, markers and triggers, however im wanting to make it an exScript instead. THAT is where im having trouble. and yes ive researched it thru and thru and always get pointed back to "use the int line" in the mission editor. NOT what im looking for. Just a little direction in the script department WITH OUT using the editor. Thanks in advance for all the useful info!!

Share this post


Link to post
Share on other sites

If the marker is circular, you can simply check the distance from each player to the center.

_markerRadius = 500;
while { sleep 1; (player distance (markerPos "MYMARKERNAME")) > _markerRadius } do
{
  hint "CURRENTLY OUT OF BOUNDS";
  sleep 1;
};

Share this post


Link to post
Share on other sites

Kusluk, i like this idea. i was leaning towards an oval marker BUT never thought of a greater than less than. i can make it round then really dont even need a marker. just a pos. i was using the marker for more of a defined area visually, but i can easly say "say stay on this island" lol. it is MP however, so how could i check it against the player that has moved beyond the dis?

Share this post


Link to post
Share on other sites

Or just use any object as the center. Does not need to be a marker, per se. What exactly are you trying to do? Do you have more context? Several ways to tackle this.

Share this post


Link to post
Share on other sites

Let's say I've ported over the cherno map and want to restrict the players to the skalisty island. I don't want any players leaving the island. Maybe in a prison island setting. Ideally I would love to just place walls all the way around the island. But that's too tedious. Lol. But I don't want them to be able to slip off the island and swim to the main land. Let's pretend im limited on the bis functions I can use as well. Hope that's enough context. :)

Share this post


Link to post
Share on other sites

Cool. You can copy & paste those walls if you need them. Just do a few, then select them all. Copy/Paste. Select them all again, copy/paste, etc. Also there is spotlight script you can use too. Be kinda cool to have an old spotlight beam on the player trying to make an escape...

Share this post


Link to post
Share on other sites
/* 
------------------------------------------------------------------------------
FUNCION:     fnc_RestriccionZonaCombate
------------------------------------------------------------------------------
DESCRIPCION: Restriccion del jugador a la zona de combate.
            Se debe ejecutar cada vez que se hace respawn en cada cliente
------------------------------------------------------------------------------
PARAMETROS:
0: [sTRING]  marker name
1: [iNTEGER] Countdown
2: [OBJECT]  Player
------------------------------------------------------------------------------
EJEMPLO:
- Crear un marcador con un area de 50m llamado "mkZonaCombate"
0 = ["mkZonaCombate",15,player] spawn fnc_RestriccionZonaCombate;
------------------------------------------------------------------------------
*/

private ["_marcadorArea", "_soldado", "_segundos"];

_marcadorArea = [_this,0] call BIS_fnc_param;
_soldado =  [_this,1,player,[objNull]] call BIS_fnc_param;
_segundos = [_this,2,15,[0]] call BIS_fnc_param;

_CuentaAtras = 0;
_bEnZonaCombate = false;
_aviso = "";

if ((_marcadorArea != "") && ((markerShape _marcadorArea) != "ICON" )) then {
waitUntil {alive _soldado};
while {(alive _soldado)} Do {	
	_bEnZonaCombate = [_marcadorArea, (getPosATL _soldado)] call BIS_fnc_inTrigger;
	if (!_bEnZonaCombate) then {
		_CuentaAtras = [_segundos,false] call BIS_fnc_countdown;
		while {(!_bEnZonaCombate) && _CuentaAtras > 0} Do {
			_CuentaAtras = [0,false] call BIS_fnc_countdown;				
			_aviso = parseText Format ["<t size='2' color='#FF0000' align='center' underline='true'>ATENCION</t><br/><t size='1' color='#FFFFFF'>FUERA DEL LIMITE</t><br/><t size='2.5' align='center'>%1</t><br/><t size='1'>PARA MORIR</t>", round (_CuentaAtras)];
			hintSilent _aviso;
			sleep 0.2;
			_bEnZonaCombate = [_marcadorArea, (getPosATL _soldado)] call BIS_fnc_inTrigger;
		};
		if (!_bEnZonaCombate) then {
			while {(alive _soldado)} Do {
//					[[_soldado,1,true],"BIS_fnc_moduleLightning",nil,false,true] call BIS_fnc_MP;
//					sleep 1;
//					code to kill a soldier 
//					(i used a moduleLightning putit on editor with false on triger act, and change to true to kill)
//					[[_soldado],"CAOE_fnc_Relampago",false,false] call BIS_fnc_MP;
			};
		} else {
			_aviso = parseText "<t size='2' color='#008000' align='center' >SIN PELIGRO</t>";
			hintSilent _aviso;
		};
	};
};
};

Share this post


Link to post
Share on other sites

Ill give this a shot, however i am limited on the BIS_fn that i can use. Ill explain later once i get something working. the above script looks good however it is using a lot of the BIS_fns thanks again though!!

Edited by cowboymiller

Share this post


Link to post
Share on other sites

yes, but BIS_fnc are a functions too.. you can go inside the function to see how it works via "Functions" on editor:

BIS_fnc_param

/*
Author: Karel Moricky

Description:
Define script parameter

Parameter(s):
_this select 0: ARRAY			- list of params
_this select 1: NUMBER			- selected index
_this select 2 (Optional): ANY		- default param (used when param is missing or of wrong type)
					- you can overload default value by setting 'BIS_fnc_<functionName>_<index>'
_this select 3 (Optional): ARRAY	- list of allowed type examples (e.g. ["",[],0,objnull])
_this select 4 (Optional): NUMBER	- If value is ARRAY, checks if it has required number of elements

Returns:
ANY - either value from list of params, or default value
*/

///////////////////////////////////////////////////////////////////////////////////////////////////////////

#define FNC_DISABLEERRORS \
private ["_disableErrors"]; \
_disableErrors = false;

//	_disableErrors = if (count _this > 5) then {_this select 4} else {false};

#define FNC_TEXTTYPES \
private ["_textTypes"];\
_textTypes = "";\
{\
	_textTypes = _textTypes + typename _x;\
	if (_forEachIndex < count _types - 1) then {_textTypes = _textTypes + ", "};\
} foreach _types;

///////////////////////////////////////////////////////////////////////////////////////////////////////////

private ["_params","_id","_value","_thisCount"];
//disableserialization; //--- Do not put this here or none of the scripts where BIS_fnc_param is used will be serialized!

_thisCount = count _this;
//if (typename _this != typename [])	then {_this = [_this]};
_params = if (_thisCount > 0)		then {_this select 0}		else {[]};
_id = if (_thisCount > 1)		then {_this select 1}		else {0};
if (typename _params != typename [])	then {_params = [_params]};
//if (typename _id != typename 00)	then {_id = 0};
_value = if (count _params > _id)	then {_params select _id}	else {nil};

//--- Assign default value
if (_thisCount > 2) then {
private ["_default","_defaultOverload","_types","_typeDefault","_type"];
_default = _this select 2;

//--- Overload default value
#ifndef DISABLE_REWRITE
if !(isnil "_fnc_scriptName") then {
	_defaultOverload = missionnamespace getvariable (_fnc_scriptName + "_" + str _id);
	if !(isnil "_defaultOverload") then {
		_default = _defaultOverload;
	};
};
#endif

//--- Default set
if (isnil "_value") then {
	_value = _default;
};

//--- Check type
if (_thisCount > 3) then {
	_types = _this select 3;
	//if (typename _types != typename []) then {_types = [_types]};
	_type = typename _value;
	_typeDefault = typename _default;

	if !({_type == typename _x} count _types > 0) then {

		if ({_typeDefault == typename _x} count _types > 0) then {
			FNC_DISABLEERRORS
			if (!_disableErrors) then {
				FNC_TEXTTYPES
				["#%1: %2 is type %3, must be %4. %5 used instead.",_id,str _value, _type, _textTypes, str _default] call bis_fnc_error;
			};
			_value = _default;
		} else {
			FNC_DISABLEERRORS
			if (!_disableErrors) then {
				FNC_TEXTTYPES
				["#%1: Default %2 is type %3, must be %4",_id, str _default, _typeDefault, _textTypes] call bis_fnc_error;
			};
		};
	};
};

//--- Check number of elements (ARRAY type only)
if (_thisCount > 4) then {
	if (typename _value == typename []) then {
		private ["_valueCountRequired","_valueCount"];
		_valueCountRequired = [_this,4,0,[0,[]]] call bis_fnc_param;
		if (typename _valueCountRequired != typename []) then {_valueCountRequired = [_valueCountRequired]};
		_valueCount = count _value;
		if !(_valueCount in _valueCountRequired) then {
			_value = _default;
			["#%1: %2 elements provided, %3 expected: %4",_id,_valueCount,_valueCountRequired,_value] call bis_fnc_error;
		};
	};
};

_value
} else {
if (isnil "_value") then {nil} else {_value}
};

BIS_fnc_inTrigger

//
/*
File: inTrigger.sqf
Author: Karel Moricky

Description:
Detects whether is position within trigger area.

Parameter(s):
	_this select 0: OBJECT or ARRAY - Trigger or trigger area
	_this select 1: ARRAY or OBJECT - Position
	_this select 2 (Optional): BOOL - true for scalar result (distance from border)

Returns:
Boolean (true when position is in area, false if not).
*/
private ["_trig","_position","_scalarresult","_tPos","_tPosX","_tPosY","_tArea","_tX","_tY","_tDir","_tShape","_in"];

_trig =		[_this,0,objnull,[objnull,[],""]] call bis_fnc_param;
_position =	[_this,1,[0,0,0]] call bis_fnc_param;
_scalarresult =	[_this,2,false,[false]] call bis_fnc_param;

if (typename _trig == typename objnull) then {
if (_trig iskindof "emptydetector") then {_trig = [position _trig,triggerarea _trig];} else {_scalarresult = 0;};
};
if (typename _scalarresult == typename 00) exitwith {["%1 is not a trigger",_trig] call bis_fnc_error; false};
if (typename _trig == typename "") then {_trig = [markerpos _trig,markersize _trig + [markerdir _trig,markershape _trig == "rectangle"]]};

//--- Trigger position
_position = _position call bis_fnc_position;
_position resize 2;
_tPos = [_trig,0,[0,0,0],[[],objnull]] call bis_fnc_paramin;
if (typename _tPos == typename objnull) then {_tPos = position _tPos};
_tPos resize 2;
_tPosX = [_tPos,0,0,[0]] call bis_fnc_paramin;
_tPosY = [_tPos,1,0,[0]] call bis_fnc_paramin;

if (_position distance [_tPosX,_tPosY] == 0) then {["Compared positions '%1' and '%2' cannot be the same.",_position,_trig] call bis_fnc_error; _tPosY = _tPosY + 0.01;};

//--- Trigger area
_tArea = [_trig,1,0,[[],0]] call bis_fnc_paramin;
if (typename _tArea == typename 0) then {_tArea = [_tArea,_tArea,0,false]};
_tX = [_tarea,0,0,[0]] call bis_fnc_paramin;
_tY = [_tarea,1,0,[0]] call bis_fnc_paramin;
_tDir = [_tarea,2,0,[0]] call bis_fnc_paramin;
_tShape = [_tarea,3,false,[false]] call bis_fnc_paramin;

_in = false;
if (_tshape) then {
private ["_difX","_difY","_dir","_relativeDir","_adis","_bdis","_borderdis","_positiondis"];

//--- RECTANGLE
_difx = (_position select 0) - _tPosx;
_dify = (_position select 1) - _tPosy;
_dir = atan (_difx / _dify);
if (_dify < 0) then {_dir = _dir + 180};
_relativedir = _tdir - _dir;
_adis = abs (_tx / cos (90 - _relativedir));
_bdis = abs (_ty / cos _relativedir);
_borderdis = _adis min _bdis;
_positiondis = _position distance _tPos;

_in = if (_scalarresult) then {
	_positiondis - _borderdis;
} else {
	if (_positiondis < _borderdis) then {true} else {false};
};

} else {
private ["_e","_posF1","_posF2","_total","_dis1","_dis2"];

//--- ELLIPSE
_e = sqrt(_tx^2 - _ty^2);
_posF1 = [_tPosx + (sin (_tdir + 90) * _e),_tPosy + (cos (_tdir + 90) * _e)];
_posF2 = [_tPosx - (sin (_tdir + 90) * _e),_tPosy - (cos (_tdir + 90) * _e)];
_posF1 resize 2;
_posF2 resize 2;
_total = 2 * _tx;

_dis1 = _position distance _posF1;
_dis2 = _position distance _posF2;
_in = if (_scalarresult) then {
	((_dis1 + _dis2) - _total) * 0.5;
} else {
	if (_dis1 + _dis2 < _total) then {true} else {false};
};
};

_in

BIS_fnc_countdown

/*
Author: Karel Moricky

Description:
Trigger countdown

Parameter(s):
	0: NUMBER - countdown in seconds
	1: BOOL - true to set the value globally

Returns:
NUMBER
*/

private ["_countdown","_isGlobal"];
_countdown = [_this,0,0,[0,true]] call bis_fnc_param;
_isGlobal = [_this,1,true,[true]] call bis_fnc_param;

switch (typename _countdown) do {
case (typename 0): {
	private ["_servertime"];
	_servertime = if (ismultiplayer) then {servertime} else {time};
	switch true do {
		case (_countdown < 0): {
			missionnamespace setvariable ["bis_fnc_countdown_time",nil];
			if (_isGlobal) then {publicvariable "bis_fnc_countdown_time";};
			-1
		};
		case (_countdown == 0): {
			private ["_time"];
			_time = missionnamespace getvariable "bis_fnc_countdown_time";
			if (isnil "_time") then {
				-1
			} else {
				(_time - _servertime) max 0
			};
		};
		case (_countdown > 0): {
			private ["_time"];
			_time = _servertime + _countdown;
			missionnamespace setvariable ["bis_fnc_countdown_time",_time];
			if (_isGlobal) then {publicvariable "bis_fnc_countdown_time";};
			_time
		};
		default {
			-1
		};
	};
};
case (typename true): {
	([] call bis_fnc_countdown) > 0
};
default {
	-1
};
};

Share this post


Link to post
Share on other sites

Thanks for the info. I'll try it out this weekend and let you know how it all goes. Thanks again.

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  

×