{$EVENT evtTick:OnTickMess}
{$EVENT evtMissionStart:OnMissionStartMess}


procedure SendMessage;
begin
	with aMessage do 
	begin	
		with MSG[aID] do 
		begin
			ShowOVMsg(aID, isOverlay);
			Done := true;
		end;
		
	end;
end;

function ClearMessages : Integer;
var I, J : Integer;
	fMSG : array of KD_MSGtype;
begin
	with aMessage do 
	begin
		for I := 0 to high(MSG) do 
			If not MSG[I].Done then 
			begin
				J := Length(fMSG);
				SetLength(fMSG, J + 1);
				fMSG[J] := MSG[I];
				
			end else
				inc(RESULT);
		MSG := fMSG;
	end;
end;


 
procedure OnTickMess;
var MSGSent : Boolean;
	I : Integer;
begin
	with aMessage do 
	begin
		If (GT = aTimeToReset) then 
			A.OverlayTextSet(-1, '');
			
		If length(MSG) = 0 then 
			Exit;
		for I := 0 to high(MSG) do 
			If (GT >= MSG[I].aTime) or (MSG[I].aTime = 0) then 
			begin
				SendMessage;
				MSGSent := true;
			end;
		If MSGSent then 
			ClearMessages;
	end;
end;

Procedure OnMissionStartMess;
begin	
	aMessage.aID := 0;
	aMessage.aPlayer := PLAYER;
	aMessage.DoOverlay := true;
end;