Alerta com X Spears

Const

WeaponId = 3277; // ID da spear
WeaponOz = 20; // peso de cada spear
AlertAmount = 5; // quantidade para usar o alerta
TimeWait = 1; // em segundos
SoundNoWeapon = 'C:\Windows\Media\Notify.wav';
AlertSound = 'C:\Windows\Media\Notify.wav';

procedure Notify(Sound : String);
begin
if (Pos('.wav', AlertSound) <> 0) then PlaySound(AlertSound);
if (Pos('.wav', Sound) <> 0) then PlaySound(Sound);
end;

procedure CheckForWeapon;
var QtyMove : integer;
var QtyItems : integer;
var HasWeapons : boolean;
begin
QtyMove := 0;
HasWeapons := true;

if Self.LeftHand.Amount <= AlertAmount then begin sleep(TimeWait * 1000); if Self.LeftHand.Amount <= AlertAmount then begin HasWeapons := false; for x := 0 to Self.Containers.Count - 1 do begin if HasWeapons then Break; if Self.Containers.Container[x].Count - 1 then begin for y := 0 to Self.Containers.Container[x].Count - 1 do begin if Self.Containers.Container[x].Item[y].ID = WeaponId then begin QtyItems := Abs(Self.Capacity / WeaponOz); if QtyItems >= 1 then
begin
if Self.Containers.Container[x].Item[y].Amount >= QtyItems then QtyMove := QtyItems;
else QtyMove := Self.Containers.Container[x].Item[y].Amount;

QtyMove := QtyMove - 1;

if QtyMove then
begin
Self.Containers.Container[x].Item[y].MoveToBody(Self.LeftHand, QtyMove);
HasWeapons := true;
Break;
end;
end;
end;
end;
end;
end;
end;
end;

if not HasWeapons then Notify(SoundNoWeapon);
end;

begin
while not Terminated do
begin
UpdateWorld;
CheckForWeapon;
sleep(1000);
end;
end;