Jump to content
Sign in to follow this  
yoannis1995

Position of object

Recommended Posts

Hi !

I wonder if it's possible to know if an object, like a smokeshell or a mine or c4 from ACE, is inside a zone definided by a trigger or a marker or whatever ?!

Thanks :)

Share this post


Link to post
Share on other sites

There is a BIS function for checking if something is in a trigger. The Function Module must be placed on the map.

_isUnitInTrigger = [MyTrigger, getPos MyUnit] call BIS_fnc_inTrigger;

Returns TRUE or FALSE.

I have modified that and made one for checking for objects in markers....which seemed more useful. No Function Module necessary.

In your init.sqf add this line....

fnc_InMarker = compile preProcessFile "fnc_InMarker.sqf";

For the function create a file called "fnc_InMarker.sqf" and add this code to it.

/*

****fnc_InMarker.sqf
****BIS_fnc_InTrigger modified by Twirly to work with markers.
****Sept 1st 2011

Description:
Detects whether is position within marker area.

Parameter(s):
	_this select 0: Marker
	_this select 1: Position
	_this select 2: OPTIONAL - scalar result (distance from border)

Returns:
Boolean (true when position is in area, false if not).
*/
private ["_mkr","_object","_posx","_posy","_tstuff","_tx","_ty","_tdir","_tshape","_in"];

_mkr = _this select 0;
_position = _this select 1;
_scalarresult = if (count _this > 2) then {_this select 2} else {false};

_posx = getmarkerpos _mkr select 0;
_posy = getmarkerpos _mkr select 1;
_tstuff = markersize _mkr;
_tx = _tstuff select 0;
_ty = _tstuff select 1;
_tdir = markerdir _mkr;
_tshape = markershape _mkr;
_in = false;

if (_tshape == "RECTANGLE") then {
//--- RECTANGLE
_difx = (_position select 0) - _posx;
_dify = (_position select 1) - _posy;
_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 getmarkerpos _mkr;

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

} else {

//--- ELLIPSE
_dis = sqrt abs(_tx^2 - _ty^2);
_posF1 = [_posx + (sin (_tdir) * _dis),_posy + (cos (_tdir) * _dis)];
_posF2 = [_posx - (sin (_tdir) * _dis),_posy - (cos (_tdir) * _dis)];
_n = _tx max _ty;
_total = 2 * _n;
_dis1 = _position distance _posF1;
_dis2 = _position distance _posF2;

_in = if (_scalarresult) then {
	(_dis1 + _dis2) - _total;
} else {
	if (_dis1 + _dis2 < _total) then {true} else {false};
};
};

_in

Call it with...

_isUnitInMarker = [MyMarker, getPos MyUnit] call fnc_inMarker;

Returns TRUE or FALSE.

Share this post


Link to post
Share on other sites

Thanks, but the fonctions are for units or objects but i would like to check if the player has placed a object like smokeshell or mines or C4 from ACE in the trigger. So how can i do that ?

Share this post


Link to post
Share on other sites

OK see if this will help then.This snippet will complete excuting if smoke is within a radius (50m) of something ("mkr_marker").... a marker in this case. You might have to adapt to suit your purposes.

_run = true;
_list = [];

_smoketypes = ["SmokeShell","SmokeShellYellow","SmokeShellRed","SmokeShellGreen","SmokeShellPurple","SmokeShellBlue","SmokeShellOrange"];

while {_run} do {
_list = (getmarkerpos "mkr_marker") nearObjects 50;
for "_i" from 0 to (count _list)-1 do {
	if (typeOf (_list select _i) in _smoketypes) then {
		_run = false;
	};
	sleep 0.01;
};
sleep 1;
};

hint "smoke detected";

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  

×