Script for protection from Summoners

This script suppose to help players to help from summoners attacks:

uses
  SysUtils;

type
  TBasicSet = record
    Active: Boolean;
    AutoAtk: Boolean;
    AutoHeal: Boolean;
    AutoBuff: Boolean;
    AutoEvent: Boolean;
    AutoScript: Boolean;
    AutoScriptPath: string;
    FRange1: Integer;
    FRange2: Integer;
    FAutoMove: Boolean;
    MTarget: Boolean;
    Performance: Integer;
    Performance2: Integer;
    FastNuke: Boolean;
  end;
  PBasicSet = ^TBasicSet;

function PetIsAttackingMe(var pet: TL2Npc): Boolean;
var
  i: Integer;
  npc: TL2Npc;
begin
  Result := False;
  for i := 0 to NpcList.Count - 1 do
  begin
    npc := NpcList.Items(i);
    if npc.ispet and npc.pvp and (not npc.dead) and (User.DistTo(npc) < 300) then
    begin
      pet := npc;
      Result := True;
      Exit;
    end;
  end;
end;

procedure ToggleManualTarget(enable: Boolean);
begin
  PBasicSet(Engine.GetFaceSet(0))^.MTarget := enable;
  Engine.UpdateCfg(True);
end;

var
  pet: TL2Npc;

begin
  while Delay(1000) do
  begin
    if PetIsAttackingMe(pet) then
    begin
      ToggleManualTarget(True);
      Engine.SetTarget(pet);
    end
    else
      ToggleManualTarget(False);
  end;
end.

Author: Velmsun