Hunting com Sumon
Hunting com Sumon

Const
Ignore='Monk'; // if the creature is a Monk, we wont attack it.
var x : integer; 
Looting:boolean;

function Attacking : boolean; 
var x : integer; 
begin 
Result := False; 
for x := 0 to Creatures.Count - 1 do 
begin 
if x >= Creatures.Count then Break; 
if Creatures.Creature[x].Attacking then 
begin 
Result := True; 
Exit; 
end; 
end; 
end;

function PlayerOnScreen : Boolean; 
var 
x: integer; 
begin 
Result := False; 
for x := 0 to Creatures.Count - 1 do 
begin 
if x >= Creatures.Count then Break; 
if Creatures.Creature[x].z=self.z then 
if Creatures.Creature[x].Name<>Self.Name then 
if not Creatures.Creature[x].NPC then 
begin 
Result :=true; 
Exit; 
end; 
end; 
end;

function GetCreatureByID(ID: integer): TCreature; 
var 
x: integer; 
begin 
Result := nil; 
for x := 0 to Creatures.Count - 1 do 
begin 
if x >= Creatures.Count then Break; 
if Creatures.Creature[x].ID = ID then 
begin 
Result := Creatures.Creature[x]; 
Exit; 
end; 
end; 
end;

 


function FindClosest : integer; 
var i, l, closest_num, closest_range, last_closest_range : integer; 
begin 
if not attacking then 
begin 
closest_num := -1; 
last_closest_range := 5000; 
for i := 0 to Creatures.Count - 1 do 
if (Creatures.Creature.Z = Self.Z) then 
if (Creatures.Creature.NPC = true) then 
if (Ignore<>Creatures.Creature.Name) then
begin 
closest_range := Round(Sqrt(Sqr(Self.X - Creatures.Creature.X)) + Sqr(Self.Y - Creatures.Creature.Y)); 
if (closest_range < last_closest_range) then 
begin 
last_closest_range := closest_range; 
closest_num := i; 
end; 
end; 
Result := closest_num; 
Exit; 
end; 
end;

var found, Bla,y : integer; 
begin 
updateworld; 
Bla:=Self.Containers.Count; 
Looting:=false; 
while not terminated do 
begin 
UpdateWorld; 
if Self.Containers.Count>Bla then begin D:=Self.Containers.Count; Looting:=true; end; 
if (Looting=true) then 
begin 
updateworld; 
Z:=self.x; 
y:=self.y; 
Self.DisplayText('Looting'); 
repeat 
sleep(200); 
updateworld; 
until (Z<>Self.x) or (y<>self.y); 
Looting:=false; 
Self.DisplayText('Finished looting'); 
end; 
updateworld; 
found := FindClosest; 
if (found <> -1) then 
if (attacking=false) and (PlayerOnScreen=false) and (Looting=false) then 
Creatures.Creature[found].Attacking := true; 
Sleep(1000); 
end; 
end;