dimon 32 Posted November 19, 2014 Based on fn_inTrigger. fn_inMarker scriptName "fn_inMarker.sqf"; /* File: fn_inMarker.sqf Author: Karel Moricky Edited: Dimon UA 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 ["_mrk","_mrkarea","_posx","_posy","_tarea","_tx","_ty","_tdir","_tshape","_in"]; _mrk = _this select 0; _position = _this select 1; _scalarresult = if (count _this > 2) then {_this select 2} else {false}; _posx = getMarkerPos _mrk select 0; _posy = getMarkerPos _mrk select 1; _mrkarea = getMarkerSize _mrk; _tx = _mrkarea select 0; _ty = _mrkarea select 1; _tdir = markerDir _mrk; _tshape = markerShape _mrk; _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 _mrk; _in = if (_scalarresult) then { _positiondis - _borderdis; } else { if (_positiondis < _borderdis) then {true} else {false}; }; }; if (_tshape == "ELLIPSE") then { //--- ELLIPSE _e = sqrt(_tx^2 - _ty^2); _posF1 = [_posx + (sin (_tdir+90) * _e),_posy + (cos (_tdir+90) * _e)]; _posF2 = [_posx - (sin (_tdir+90) * _e),_posy - (cos (_tdir+90) * _e)]; _total = 2 * _tx; _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 example: fn_inMarker = compile preprocessFile "fn_inMarker.sqf"; if ((({(["Base", getPos _x] call fn_inMarker) && (side _x == west)} count allunits ) < 3) && (({(["Base", getPos _x] call fn_inMarker) && (side _x == east)} count allunits) > 5)) then { if (!(['main_base', getPosATL player] call fn_inMarker)) exitWith{ Share this post Link to post Share on other sites
dimon 32 Posted January 27, 2015 fn_inarrayMarker Detects whether is position within array marker area. scriptName "fn_inarrayMarker.sqf"; /* File: fn_inarrayMarker.sqf Author: Karel Moricky Edited: Dimon UA Description: Detects whether is position within array marker area. Parameter(s): _this select 0: array 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 ["_arraymrk","_mrkarea","_posx","_posy","_tarea","_tx","_ty","_tdir","_tshape","_in"]; _arraymrk = _this select 0; _position = _this select 1; _scalarresult = if (count _this > 2) then {_this select 2} else {false}; { _posx = getMarkerPos _x select 0; _posy = getMarkerPos _x select 1; _mrkarea = getMarkerSize _x; _tx = _mrkarea select 0; _ty = _mrkarea select 1; _tdir = markerDir _x; _tshape = markerShape _x; _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 _x; _in = if (_scalarresult) then { _positiondis - _borderdis; } else { if (_positiondis < _borderdis) then {true} else {false}; }; }; if (_tshape == "ELLIPSE") then { //--- ELLIPSE _e = sqrt(_tx^2 - _ty^2); _posF1 = [_posx + (sin (_tdir+90) * _e),_posy + (cos (_tdir+90) * _e)]; _posF2 = [_posx - (sin (_tdir+90) * _e),_posy - (cos (_tdir+90) * _e)]; _total = 2 * _tx; _dis1 = _position distance _posF1; _dis2 = _position distance _posF2; _in = if (_scalarresult) then { (_dis1+_dis2) - _total; } else { if (_dis1+_dis2 < _total) then {true} else {false;}; }; }; if _in exitwith { true}; } foreach _arraymrk; _in fn_inarrayMarker Share this post Link to post Share on other sites
Schatten 291 Posted February 1, 2015 (edited) My version of function to detect whether is object within marker of "ellipse" or "rectangle" type: private ["_angle", "_distance", "_markerName", "_markerPosition", "_markerSize", "_markerSizeA", "_markerSizeB", "_object"]; _object = _this select 0; _markerName = _this select 1; _markerPosition = getMarkerPos _markerName; _markerSize = getMarkerSize _markerName; _markerSizeA = _markerSize select 0; _markerSizeB = _markerSize select 1; _angle = ([_markerPosition, _object] call BIS_fnc_dirTo) - (markerDir _markerName); if (_angle < 0) then {_angle = 360 + _angle}; if ((markerShape _markerName) == "ELLIPSE") then { _distance = _markerSizeA * _markerSizeB / (sqrt ((_markerSizeA * (cos _angle)) ^ 2 + (_markerSizeB * (sin _angle)) ^ 2)); _markerSizeA = abs (_distance * (sin _angle)); _markerSizeB = abs (_distance * (cos _angle)); }; _distance = [_object, _markerPosition] call BIS_fnc_distance2D; ((abs (_distance * (sin _angle))) < _markerSizeA) and {(abs (_distance * (cos _angle))) < _markerSizeB} Usage: isWithinMarker = compile (preprocessFileLineNumbers "isWithinMarker.sqf"); if ([player, "marker1"] call isWithinMarker) then {hint "You are within marker area"}; Edited June 14, 2015 by Schatten Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted August 15, 2015 My version of function to detect whether is object within marker of "ellipse" or "rectangle" type: [...] Usage: isWithinMarker = compile (preprocessFileLineNumbers "isWithinMarker.sqf"); if ([player, "marker1"] call isWithinMarker) then {hint "You are within marker area"}; Also works with BIS_fnc_inTrigger: ["marker1", player] call BIS_fnc_inTrigger Share this post Link to post Share on other sites