Game chat scanner, looking for needed phrases

A simple example showing how you can scan all chat messages

A simple example that logs all chat messages:

uses SysUtils;

procedure ChatScanerThread();
begin
  while delay(100) do begin
    if (ChatMessage.Unread) and (ChatMessage.Time < 3333) then begin
      Print(ChatMessage.Sender+': '+IntToStr(Ord(ChatMessage.ChatType))+' :'+ChatMessage.text);
    end;
  end;
end;

begin
  Script.NewThread(@ChatScanerThread);
  Delay(-1);
end.

It can be slightly improved to find the ads we need:

uses SysUtils;

var phrases: array of string = ['sell draconic bow', 'wts drac bow', 'wts DB'];   // we set lines which need to be looked for
    
procedure ChatScanerThread();
var i: integer;
begin         
  while delay(100) do begin
    if (ChatMessage.Unread) and (ChatMessage.ChatType = mtShout) then begin
      for i:= Low(phrases) to High(phrases) do begin
        if (Pos(LowerCase(phrases[i]), LowerCase(ChatMessage.text)) > 0) then begin
          Print(ChatMessage.Sender+': '+ChatMessage.Text);
          PlaySound(ExePath+'\Sounds\msg.wav');
          Engine.SetGameWindow(true);
          break;
        end;
      end;        
    end;
  end;
end;

begin  
  Script.NewThread(@ChatScanerThread);
  Delay(-1);
end.