Jump to content
gc8

How to use EachFrame addEventHandler

Recommended Posts

Hi Does anyone know how to use the eachframe handler?

 

I tried this code:

 

player addEventHandler ["EachFrame", 
{
player sidechat format["Test %1",time];

}];
 

but it prints nothing...

 

 

Share this post


Link to post
Share on other sites
#define NAMETAGSHID Sfx_Handler_Nametags

 Fn_Sfx_EnableNametags = {
	if (productVersion select 2 >= 158) then {
		if (not isNil {NAMETAGSHID}) then {
			removeMissionEventHandler ["EachFrame", NAMETAGSHID]};
		if (_this) then {
			NAMETAGSHID = addMissionEventHandler ["EachFrame", {call Fn_Sfx_DrawNametags}]}
	} else {
		if (_this) then {
			["NAMETAGSHID", "onEachFrame", {call Fn_Sfx_DrawNametags}] call BIS_fnc_addStackedEventHandler
		} else {		
			["NAMETAGSHID", "onEachFrame"] call BIS_fnc_removeStackedEventHandler}
	}
};

Fn_Sfx_DrawNametags = {
	private _bvd = 33.3 * (1 - (fog ^ 1.5) * 0.75) * (1 - (rain ^ 1.5) * 0.25);
	private _mag = ([0.5,0.5] distance2D worldToScreen positionCameraToWorld [0,3,4]) * (getResolution select 5) * 1.5;
	{
		if (alive _x and _x isEqualTo vehicle _x) then {
			if (not isPlayer _x and side _x isEqualTo side player) then {
				private _dst = 1 max ((_x distance player) / _mag);
				if (_dst < _bvd) then {
					if ([objNull, "VIEW"] checkVisibility [eyePos player, eyePos _x] > 0) then {
						private _tag = _x getVariable "Nametag";
						if (isNil "_tag") then {
							_tag = ["",[1,1,1,0.5],[],0.5,0.5,0,name _x,2,0.05,"RobotoCondensed"];
							_x setVariable ["Nametag", _tag];
						};
						_tag set [0, format ["\A3\Ui_f\data\GUI\Cfg\Ranks\%1_gs.paa", toLower rank _x]];
						_tag set [6, name _x];
						_tag set [2, _x modelToWorldVisual ((_x selectionPosition "pilot") vectorAdd [0,0,0.30 + 0.018 * _dst])];
						_tag set [3, 1 / _dst ^ 0.3];
						_tag set [4, 1 / _dst ^ 0.3];
						_tag set [8, 0.05 / _dst ^ 0.25];
						drawIcon3D _tag;
					}
				}
			}
		}
	} forEach allUnits;
};

 

  • Like 1

Share this post


Link to post
Share on other sites

thanks guys addMissionEventHandler was the way.

 

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

×