Script for The finest food quest

Tired of making The finest food quest? Try the script below to automate your quest job!

uses SysUtils;

const
  QuestId=623;
  NotStarted=0;
  Started=1;
  Completed=2;
  JEREMY = 31521; 

  
  
function GetQuestStage(quest_id: integer): integer;
var i: byte;
begin
  result:= 0;
  for i:= 1 to 32 do if Engine.QuestStatus(quest_id, i) then result:= i;
end;

function IsAgr(Mob: TL2Npc): boolean;
begin
  result:= (Mob.AtkOID = User.OID) and (not Mob.Dead);
end;

function MobsAreHittingMe(): boolean;             
var i: integer;
begin
  result:= false;
  for i:= 0 to NpcList.Count-1 do begin
    if (IsAgr(NpcList(i))) then begin
      result:= true;
      exit;
    end;
  end;
end;

procedure selectDialogs(npcId:integer; selections: array of integer);
var
  i: integer;
begin
  if Engine.setTarget(npcId) then begin
    Engine.SetTarget(npcId);
    delay(500);
    Engine.DlgOpen;
    for i in selections do begin
      Delay(500);
      Engine.DlgSel(i);
    end;
  end;
end;

procedure StartTheFinestFood;
begin
  while true do begin
    delay(300);
    case GetQuestStage(QuestId) of

      NotStarted:
      begin
        Engine.MoveTo(149539, -112675, -2090);
        selectDialogs(31521,[1,3,1]);
      end;

      Started:
      begin
        if not(User.InRange(153817, -110268, -2688, 2500)) then begin
          Engine.MoveTo(149913, -112453, -2090);
          Engine.MoveTo(150309, -112278, -2203);
          Engine.MoveTo(150730, -112115, -2249);
          Engine.MoveTo(151442, -111842, -2350);
          Engine.MoveTo(151898, -111623, -2415);
          Engine.MoveTo(152377, -111342, -2496);
          Engine.MoveTo(152893, -110949, -2580);
          Engine.MoveTo(153413, -110500, -2661);
          Engine.MoveTo(153848, -110124, -2694);
          Engine.MoveTo(154096, -109906, -2707);
        end;

        Engine.FaceControl(0, true);
      end;

      Completed:
      begin
        if Engine.SetTarget(31521) then begin
          selectDialogs(31521,[1,1,1]);
        end
        else if not MobsAreHittingMe then begin
          Engine.FaceControl(0, false);

          Engine.MoveTo(154096, -109906, -2707);
          Engine.MoveTo(153848, -110124, -2694);
          Engine.MoveTo(153413, -110500, -2661);
          Engine.MoveTo(152893, -110949, -2580);
          Engine.MoveTo(152377, -111342, -2496);
          Engine.MoveTo(151898, -111623, -2415);
          Engine.MoveTo(151442, -111842, -2350);
          Engine.MoveTo(150730, -112115, -2249);
          Engine.MoveTo(150309, -112278, -2203);
          Engine.MoveTo(149913, -112453, -2090);
        end;
      end;

    end;
  end;
end;

  
begin
  Script.NewThread(@StartTheFinestFood);
  delay(-1);
end.

Author: Velmsun