Advertisement
Dimon_UA

Untitled

Oct 4th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. scriptName "Functions\misc\fn_inTrigger.sqf";
  2. /*
  3.     File: inTrigger.sqf
  4.     Author: Karel Moricky
  5.  
  6.     Description:
  7.     Detects whether is position within trigger area.
  8.  
  9.     Parameter(s):
  10.         _this select 0: Trigger
  11.         _this select 1: Position
  12.         _this select 2: OPTIONAL - scalar result (distance from border)
  13.  
  14.     Returns:
  15.     Boolean (true when position is in area, false if not).
  16. */
  17. private ["_trig","_object","_posx","_posy","_tarea","_tx","_ty","_tdir","_tshape","_in"];
  18.  
  19. _trig = _this select 0;
  20. _position = _this select 1;
  21. _scalarresult = if (count _this > 2) then {_this select 2} else {false};
  22.  
  23. _posx = position _trig select 0;
  24. _posy = position _trig select 1;
  25. _tarea = triggerarea _trig;
  26. _tx = _tarea select 0;
  27. _ty = _tarea select 1;
  28. _tdir = _tarea select 2;
  29. _tshape = _tarea select 3;
  30. _in = false;
  31.  
  32. if (_tshape) then {
  33.  
  34.     //--- RECTANGLE
  35.     _difx = (_position select 0) - _posx;
  36.     _dify = (_position select 1) - _posy;
  37.     _dir = atan (_difx / _dify);
  38.     if (_dify < 0) then {_dir = _dir + 180};
  39.     _relativedir = _tdir - _dir;
  40.     _adis = abs (_tx / cos (90 - _relativedir));
  41.     _bdis = abs (_ty / cos _relativedir);
  42.     _borderdis = _adis min _bdis;
  43.     _positiondis = _position distance _trig;
  44.  
  45.     _in = if (_scalarresult) then {
  46.         _positiondis - _borderdis;
  47.     } else {
  48.         if (_positiondis < _borderdis) then {true} else {false};
  49.     };
  50.  
  51. } else {
  52.     //--- ELLIPSE
  53.     _e = sqrt(_tx^2 - _ty^2);
  54.     _posF1 = [_posx + (sin (_tdir+90) * _e),_posy + (cos (_tdir+90) * _e)];
  55.     _posF2 = [_posx - (sin (_tdir+90) * _e),_posy - (cos (_tdir+90) * _e)];
  56.     _total = 2 * _tx;
  57.  
  58.     _dis1 = _position distance _posF1;
  59.     _dis2 = _position distance _posF2;
  60.     _in = if (_scalarresult) then {
  61.         (_dis1+_dis2) - _total;
  62.     } else {
  63.         if (_dis1+_dis2 < _total) then {true} else {false};
  64.     };
  65. };
  66.  
  67. _in
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement