All pastes #2093035 Raw Edit

Unnamed

public text v1 · immutable
#2093035 ·published 2011-11-08 12:32 UTC
rendered paste body
if (!isDedicated) then {
  
  if (isNil "sandi_barrier_index") then { // not initialised
    sandi_barrier_index = 0;
    sandi_barrier_barriers = [];
  };
  _id = sandi_barrier_index; 
  sandi_barrier_index = sandi_barrier_index +1;
  sandi_barrier_barriers set [_id, 1];

  [_id, _this] spawn {
    _id        = _this select 0;
    _args      = _this select 1;
    
    _shape = "rectangle";
    _text  = "The AO ends here";
    
    _pos       = _args select 0;
    _xDistance = _args select 1;
    _yDistance = _args select 2;
    _theta     = _args select 3;
    if (count _args > 4) then {
      _shape   = _args select 4;
      _text    = _args select 5;
    } else {
      // old syntax
    };
     
    _cos = cos(_theta);
	  _sin = sin(_theta);
	  _rCos = cos(_theta * -1);
	  _rSin = sin(_theta * -1);

    waitUntil {!isNull player};

    _xOverOld = 0;
    _yOverOld = 0;

    while {true} do {
      scopeName "loop";
      _sleep = 10;

      _disabled = false; 
      if (!isNil "sandi_barrier_disabled") then { 
        if (sandi_barrier_disabled) then { 
          _disabled = true; 
        }; 
      };
      
      _state = sandi_barrier_barriers select _id;
      
      _playerVeh = objNull;
      if (vehicle player == player) then { // on foot
        _playerVeh = player;
      } else { // in a vehicle
        if (driver (vehicle player) == player) then { // player is driving
          _playerVeh = vehicle player;
        } else {
          _disabled = true;
          _sleep = 1;
        };
      };

      if (!_disabled && _state == 1) then {

        _x = ((getPos _playerVeh) select 0) - (_pos select 0);
        _y = ((getPos _playerVeh) select 1) - (_pos select 1);

        _x2 = (_cos * _x) - (_sin * _y);
        _y2 = (_sin * _x) + (_cos * _y);

        _xOver = 0;
        if (_x2 > _xDistance) then {
          _xOver = _x2 - _xDistance;
        } else { if (_x2 < (_xDistance *-1)) then {
          _xOver = (_x2 * -1) - _xDistance;
        } };
        
        _yOver = 0;
        if (_y2 > _yDistance) then {
          _yOver = _y2 - _yDistance;
        } else { if (_y2 < (_yDistance *-1)) then {
          _yOver = (_y2 * -1) - _yDistance;
        } };

        if (_xOver > (_xOverOld +0.1) || _yOver > (_yOverOld +0.1)) then {
          hint _text;
          if (player == vehicle player) then {
            player playMove "aidlpercmstpslowwrfldnon_player_0s";
          };
          _playerVeh setVelocity [0,0,0];
        };
        _xOverOld = _xOver;
        _yOverOld = _yOver;
        
        if (_x2 > (_xDistance -100)) then {
          _sleep = 0.2;
        } else { if (_x2 < ((_xDistance -100) *-1)) then {
          _sleep = 0.2;
        }};
        _newY2 = _y2;
        if (_y2 > (_yDistance -100)) then {
          _sleep = 0.2;
        } else { if (_y2 < ((_yDistance -100) *-1)) then {
          _sleep = 0.2;
        }};

      } else {
        if (_state == 0) then { // delete barrier
          breakOut "loop";
        };
      };
      sleep _sleep;
    };

  };
  _id // return 
};