Jump to content
Mr H.

Sharing is caring: draw triggers area in game.

Recommended Posts

Hey guys thought I'd share it with you, it might come in handy when debugging your missions.
 

/*
Function name:MRH_fnc_drawTrigger
Authors: Mr & Mrs H.(she did the maths)
Description: draw triggers in game when the player goes near them, trigger is drawn in red, in green if it's been activated. Statements and other infos are displayed. Useful for debugging missions.
Return value:
Public: Yes
Parameters: None
Example(s):
[] spawn MRH_fnc_drawTrigger;
*/
MRH_fnc_drawTrigger =
{
	onEachFrame 
 {
_trigger = (getPos player) nearestObject "EmptyDetector";

_triggerPos = getPosATL _trigger;
_x = _triggerPos select 0;
_y = _triggerPos select 1;
_z = _triggerPos select 2;

_triggerSize = triggerArea _trigger;
_xsize = _triggerSize select 0;
_ysize = _triggerSize select 1;
_zsize = _triggerSize select 4;
_angle = _triggerSize select 2;

MRH_inside_fnc_rotatePoint = {
	
	params ["_pos","_angle","_center"];
	
    _x = _pos select 0;
	_y = _pos select 1;
	_a = _center select 0;
	_b = _center select 1;
	
	_xformat = _x - _a;
	_yformat = _y - _b;
	_newx = (_a + (_xformat * cos _angle)) + (_yformat* sin _angle);
	_newy = (_b - (_xformat * sin _angle)) + (_yformat* cos _angle);


	_newz = _pos select 2;
	[_newx,_newy,_newz]

	};


_isRectangle = _triggerSize select 3;

_color = [1,0,0,1];
if (triggerActivated _trigger) then {_color = [0,1,0,1]};

if (_isRectangle) then {
_posA = [(_x +_xsize),(_y - _ysize),_z];
_posB = [(_x +_xsize),(_y + _ysize),_z];
_posC = [(_x -_xsize),(_y + _ysize),_z];
_posD = [(_x -_xsize),(_y - _ysize),_z];


	
_posA = [_posA, _angle,_triggerPos] call MRH_inside_fnc_rotatePoint;
_posB = [_posB, _angle,_triggerPos] call MRH_inside_fnc_rotatePoint;
_posC = [_posC, _angle,_triggerPos] call MRH_inside_fnc_rotatePoint;
_posD = [_posD, _angle,_triggerPos] call MRH_inside_fnc_rotatePoint;

_posAd = [_posA select 0,_posA select 1,(_z+_zsize)];
_posBd = [_posB select 0,_posB select 1,(_z+_zsize)];
_posCd = [_posC select 0,_posC select 1,(_z+_zsize)];
_posDd = [_posD select 0,_posD select 1,(_z+_zsize)];

	 drawLine3D [_posA, _posB, _color];
	 drawLine3D [_posB, _posC, _color];
	 drawLine3D [_posC, _posD, _color];
	 drawLine3D [_posD, _posA, _color];

	 drawLine3D [_posAd, _posBd, _color];
	 drawLine3D [_posBd, _posCd, _color];
	 drawLine3D [_posCd, _posDd, _color];
	 drawLine3D [_posDd, _posAd, _color];

	 drawLine3D [_posAd, _posA, _color];
	 drawLine3D [_posBd, _posB, _color];
	 drawLine3D [_posCd, _posC, _color];
	 drawLine3D [_posDd, _posD, _color];
 }
 else
 {
	 if (_zsize <1) then {_zsize =100};
	 for "_i" from 1 to 360 do {
		 //_distance = _ysize;
	 _x = (_triggerPos select 0)+ _xsize*(cos _i);
	_y = (_triggerPos select 1) + _ysize*(sin _i);
	_moved = [[_x,_y,0],_angle, _triggerPos] call MRH_inside_fnc_rotatePoint;
	_return = [_moved select 0,_moved select 1,_z];
	_return2= [_moved select 0,_moved select 1,(_z + _zsize)];
	drawLine3D [_return, _return2, _color];

	 };
	
 };



_triggerType = triggerType _trigger;
_activation = triggerActivation _trigger;
_attachedVeh= triggerAttachedVehicle _trigger;
_statements = triggerStatements _trigger;

_text = format ["Trigger name:%1,Class:%2,Type:%3,Activation:%4, Attached vehicle:%5, Statements%6",str _trigger,str typeof _trigger, str _triggerType, str _activation, str _attachedVeh, str _statements];


drawIcon3D ["", _color,_triggerPos, 1, 1, 45, _text, 1, 0.05, "TahomaB"];
 };
};

 

  • Like 7

Share this post


Link to post
Share on other sites
Quote

Authors: Mr & Mrs H.(she did the maths)

Thanks Mr & Mrs H.

:rofl::rofl::rofl::rofl:

Good work!

  • Like 1
  • Haha 2

Share this post


Link to post
Share on other sites
3 minutes ago, HazJ said:

Thanks Mr & Mrs H.

:rofl::rofl::rofl::rofl:

Good work!

Except perhaps some zero division in case of...  non-area trigger.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

@Mr H.

Are you telling us porkies (lies)? :rofl::rofl:

Did Mrs H do the coding and you did the math? :happy:

  • Haha 1

Share this post


Link to post
Share on other sites

@pierremgiYes I thought about the divisor by zero issue for non area triggers but forgot to fix it, it should be fairly easy.

  • Thanks 1

Share this post


Link to post
Share on other sites

Great tool!

You could use params to define multiple variables in one line.

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

×