uses SysUtils;

function CheckTrains(amount: integer = 5; R: integer = 1500): boolean;   
var i, j, count: integer;
begin
  result:= false;
  for i:= 0 to CharList.Count-1 do begin                                      // running through the list of characters
    count:= 0;                                                                // reset counter of mobs running after character
    if (User.DistTo(CharList.Items(i)) < R*1.5)                               // if i-th character in radius x1.5 from us
    and (CharList.Items(i).Moved) then begin                                  // and he moves then
      for j:= 0 to NpcList.Count-1 do begin                                   // running through the list of mobs
        if (NpcList.Items(j).Target = CharList.Items(i))                      // if the j-th mob holds in the target of the i-th player
        and (not (NpcList.Items(j).Dead)                                      // and this mob is not dead
        and (CharList.Items(i).DistTo(NpcList.Items(j)) < R)) then Inc(count);// and the distance between the i-th player and the j-th mob < R, then we increase the count of mobs
        if (count >= amount) then begin                                       // if the mobs counter > the number of mobs that we check, then
          result:= true;                                                      // assign the result to true
          Print('Detected train of '+IntToStr(count)+'+ mobs, run for '+CharList.Items(i).Name);     // print information
          exit;                                                               // and exit function
        end;
      end;
    end;
  end;
end;

begin
  while delay(555) do begin
    if (Engine.Status = lsOnline) then begin
      // resort to spot, turn on the interface, etc.
      
      if CheckTrains(4, 2000) then begin   // If someone is driving train of 4+ mobs in a radius of less than 2k, then
        // Turning off the interface, doing relog or taking other measures. 
      
      end;
    end;
  end;
end.