So I tried to compile my autofighter with the form in pascal script with simba 1.00 and I just get the error 'compiling failed'.


Does simba 1.00 have 100% form support?


Script:

Simba Code:
program autoFighter;

{$I SRL/SRL.Simba}
{$i SRL/srl/misc/debug.simba}
Const
  VERSION = 3.02;
  Disp = '3.02';

type groundObjects = record
  Color, tol, filter, width, height, textBMP, amount:Integer;
  hmod, smod:Extended;
  name, odds, value:string;
end;

type NPCS = record
  Color, tol, filter, width, height, textBMP, killed, XP, Combat, Health:Integer;
  hmod, smod:Extended;
  name:string;
  RClick:Boolean;
  Drops:TIntegerArray;
end;

type Foods = record
  name:string;
  bmp, used, heal, tol, cost:Integer;
end;

type Pot = record
  color, tol, used, time, cost, timeout:Integer;
  hmod, smod:Extended;
  name, info:string;
end;

type Prayers = record
  Location:TPoint;
  name, info:string;
  level:Integer;
  Exceptions:TIntegerArray;
end;

type formInfo = record
  FightForm:Tform;
  Buttons: Array[0..3] of TButton;
  NPCButtons: Array[0..2] of TButton;
  LootButtons: Array[0..2] of TButton;
  PotionButtons: Array[0..1] of TButton;
  Edits:Array [0..1] of TEdit;
  Labels: Array[0..6] of TLabel;
  FoodInfo: Array [0..1] of TLabel;
  PotionInfo: Array[0..1] of TLabel;
  NPCInfo: Array[0..1] of TLabel;
  LootInfo: Array[0..2] of TLabel;
  LoginLabels: Array[0..1] of TLabel;
  Tabs: Array[0..6] of TTabSheet;
  Options:Array[0..4] of TListBox;
  Chosen:Array[0..4] of TListBox;
  NPCLabels:Array[0..2] of TLabel;
  GPanels:Array[0..1] of TPanel;
  PrayButtons: Array[0..1] of TButton;
  InfoLabels:Array[0..4] of TLabel;
  PrayLabels:Array [0..2] of TLabel;
  FoodButtons:Array[0..1] of TButton;
  CheckBoxes:Array[0..7] of TCheckBox;
  Shapes: Array[0..4] of Tshape;
  Trim: Array[0..6] of TShape;
  DropList:TListbox;
  TPage:TPageControl;
  PrayCombo:TComboBox;
  TimeOutEdit:TEdit;
  ClickDelay:TEdit;
end;

var
  t, timeout, looted, casketBMP, praysDrank, waitclick, failsafe, failsafe_timeout:Integer;
  loot, debug, usecasket, usePrayer, keepPraying, ranout, useForm:boolean;
  usePots, keepPotting, useFood, pressed:Boolean;
  foodUse, potsUse, NPCKill, prayUse, LootItem:TIntegerArray;
  t_username, t_password, PrayPotType:string;
  groundObject: array [0..5] of groundObjects;
  NPC: array [0..3] of NPCS;
  Food: array [0..5] of Foods;
  Pots: array [0..7] of Pot;
  Prayer: array[0..29] of Prayers;
  FormData:FormInfo;

Procedure t_DeclarePlayers;
begin
  t_username := 'hello world';
  t_password := '';
  useform := true;
  Loot := false;
  debug := false;
  usecasket := false;
  usePrayer := false;
  keepPraying := false;
  usePots := false;
  keepPotting := false;
  PrayPotType := 'pray';
  useFood := false;
  fooduse := [];
  potsUse := [];
  NPCKill := [];
  prayUse := [];
  lootItem := [];
  timeout := 19000;
end;

function declareNPCs:Integer;
begin

  with Npc[0] do
  begin
    Color := 3949893;
    tol := 7;
    filter := 50;
    width := 40;
    height := 40;
    hmod := 0.00;
    smod := 0.13;
    XP := 12921;
    Health := 100;
    Combat := 20;
    textBMP := BitmapFromString(0, 0, 'null');
    RClick := false;
    Drops :=[0, 1, 2, 3, 4, 5]
    name := 'Rock crab';
  end;

  with Npc[1] do
  begin
    Color := 7448542;
    tol := 10;
    filter := 60;
    width := 40;
    height := 70;
    hmod := 0.09;
    smod := 2.66;
    XP := 7920;
    Health := 350;
    Combat := 28;
    textBMP := BitmapFromString(0, 0, 'null');
    RClick := false;
    Drops :=[1]
    name := 'Hill gaint';
  end;

  with Npc[2] do
  begin
    Color := 3625911;
    tol := 10;
    filter := 60;
    width := 40;
    height := 70;
    hmod := 0.12;
    smod := 1.44;
    XP := 12000;
    Health := 1110;
    Combat := 86;
    textBMP := BitmapFromString(0, 0, 'null');
    RClick := false;
    Drops :=[1, 4]
    name := 'Fire gaint';
  end;

  with Npc[3] do
  begin
    Color := 8960470;
    tol := 8;
    filter := 60;
    width := 40;
    height := 70;
    hmod := 0.02;
    smod := 2.14;
    XP := 12000;
    Health := 1110;
    Combat := 53;
    textBMP := BitmapFromString(0, 0, 'null');
    RClick := false;
    Drops :=[1, 4]
    name := 'Ogre';
  end;

  result := length(NPC);
end;

function declareObjects:Integer;
begin

  with groundObject[0] do
  begin
    Color := 935263;
    tol := 3;
    filter := 40;
    width := 45;
    height := 45;
    hmod := 0.03;
    smod := 0.31;
    textBMP := BitmapFromString(67, 9, 'meJzVk7ENwCAMBBdJnyJLZMQ07MI' + 'ErJVEQrIQfj+2OyQXDjzoL29Kbcd58Sq1FYdM1/28fyUOJu7xONwR' + 'pHuenMsnXCeYxEDf0oJxXbakn/SjEhqGvUVHIrNAoMmlHlJITxLRI' + 'FqZA7H+PPcMs4MgiUT4dEUT4RqCHAJxphAdoRAsOegfLZ4Uf++hR7' + '18Djyp3esDukgt2Q==');
    name := 'casket';
    odds := 'Uncommon';
    value := '10000-50000';
  end;

  with groundObject[1] do
  begin
    Color := 2144231;
    tol := 3;
    filter := 30;
    width := 40;
    height := 40;
    hmod := 0.02;
    smod := 1.99;
    textBMP := BitmapFromString(56, 7, 'meJybuuOYjLo2fjR1x7GpRCjDRA4' + 'T/gMRVdSjOQDiJDSHwblYxfH4Ao+9ECkiFQARVvdgZeNyPJ4Ax+UM' + 'ZHEi2XjCE9OduBIDnd1JRnjij/oBcSeRYUiheyiPd/zhjD8rYQYsV' + 'nE87gQAhnaXCQ==');
    name := 'coins';
    odds := 'Common';
    value := '1';
  end;

  with groundObject[2] do
  begin
    Color := 10462821;
    tol := 15;
    filter := 10;
    width := 15;
    height := 15;
    hmod := 0.17;
    smod := 0.80;
    textBMP := BitmapFromString(71, 5, 'meJyTUdeWgaGpO47BEZogMgOPYmT' + 'kMOE/MkITx89G047VfGQ1WA1HczMmG5dPMT1LkuNJZeMxH5diZPdj' + 'egpT5eDxFBVjCn8KpNwj+FMg5Z4iMnZoEVNEmo8sCAATqnzk');
    name := 'blue charm';
    odds := 'Uncommon';
    value := '0';
  end;

  with groundObject[3] do
  begin
    Color := 7705733;
    tol := 11;
    filter := 10;
    width := 15;
    height := 15;
    hmod := 0.08;
    smod := 0.07;
    textBMP := BitmapFromString(73, 4, 'meJybuuOYjLo2BE3dcWwqjIvJRhb' + 'BoxgZOUz4D0RwBoSNLIUpQjkb2YVoXEyPYPqLVK9h2o7pGJp6jYxY' + 'wypFideQETHiVPEakTFFlVgjVRyrGgDBwDkW');
    name := 'green charm';
    odds := 'Uncommon';
    value := '0';
  end;

  with groundObject[4] do
  begin
    Color := 6981784;
    tol := 3;
    filter := 10;
    width := 15;
    height := 15;
    hmod := 0.18;
    smod := 3.46;
    textBMP := BitmapFromString(74, 5, 'meJybuuOYjLo2HE3dcQyO0ASRGXg' + 'UIyOHCf+BCKsUXBZNDVYupjKs5mCKYPUFVjYuL2P6GtOp+H1BKhtX' + 'AGIqnoo77jB9h6mSSN/hihTq+g5TkMK4w584h5DviIyvAfQdpmIAw' + '9mLjw==');
    name := 'gold charm';
    odds := 'Common';
    value := '0';
  end;

  with groundObject[5] do
  begin
    Color := 4014466;
    tol := 5;
    filter := 10;
    width := 15;
    height := 15;
    hmod := 0.06;
    smod := 3.31;
    textBMP := BitmapFromString(71, 5, 'meJyTUdeWgaGpO47BEZogMgOPYmT' + 'kMOE/EOERx6oAIohHDbICZCmsgsjOw2Tj8immZ4n0FKZ7cHkZqywe' + 'u9AUILsf01OYKinxFB4n4fEUrhjB5SkyYgp/CqSRp/DrIslTRMYOk' + 'ZbS2lMA4/Z85A==');
    name := 'chrimson charm';
    odds := 'Rare';
    value := '0';
  end;

  result := length(groundObject);
end;

function declareFood: Integer;
begin

  with Food[0] do
  begin
    name := 'Trout';
    heal := 70;
    tol := 120;
    cost := 45;
    bmp := BitmapFromString(9, 6, 'meJw9jN0KglAQBh/QEJEQReWgRzTM' + '1PT4jxcSUfTUDSwIc7PzLWNdPNsJ3avyfB1ERRiXKqkT3Wa5OWWsK' + 'kyadfltKMrp/tiqZm+7ox/eSIF/Wcfla6YP0KEmb5zz+mMSqAGRM8' + 'Uq0IGneeGpwR8Bb0T0');
  end;

  with Food[1] do
  begin
    name := 'Lobster';
    heal := 120;
    tol := 110;
    cost := 165;
    bmp := BitmapFromString(9, 4, 'meJyTjtstHbdX2LFZzHu6eMBCiZAV' + 'UlFbeXn5ZBIPyWVeFPWaKuo5ESguHrhYImy1VMwOmaSjMsnHJIKXA' + 'dUAEUg8aIlk+DrpuN2yKSfksq4wMTAAtUiGrQWKA5VJRm6Sjt8PFA' + 'QiAJg9IgE=');
  end;

  with Food[2] do
  begin
    name := 'Shrimp';
    heal := 30;
    tol := 100;
    cost := 0;
    bmp := BitmapFromString(8, 4, 'meJyTqT8k03BYunq3VPlWyaJ14lkL' + 'ReImCAXVShSslixcK5G7TCx1lmj8ROGIdgGfEn6XdOHIDtGkqaIJk' + '4EiggGV/G45fE6pfA6Jgn7lQoHVQI0CngUgEcdkXttYJgYGAG8RHiQ=');
  end;

  with Food[3] do
  begin
    name := 'Pizza';
    heal := 90;
    tol := 135;
    cost := 280;
    bmp := BitmapFromString(6, 4, 'meJxL65qR0j41sWViQtOEuPqe7u6J' + '6T2zUjunJ7VNBgrGN/YBBTN656SBlQEFgcoEJEpypyyGKAMKArlAB' + 'AAEniFr');
  end;

  with Food[4] do
  begin
    name := 'Swordfish';
    heal := 140;
    tol := 130;
    cost := 250;
    bmp := BitmapFromString(10, 5, 'meJyLd4iKB6NUl4Qs95Q8z4wS39x' + 'kp7gQiwBHbbvygMLKwOLqoNLakPL60IrGsCogt8A7C6je39S7OaKm' + 'K6a5J661L75tQkJHe1Q9UA1QS45HWqxdBJDbEd2IpgBoTql/PtCi1' + 'si61Qnz4QqAshMTu4AMoAKgAwBUDz5D');
  end;

  with Food[5] do
  begin
    name := 'Shark';
    heal := 200;
    tol := 130;
    cost := 1200;
    bmp := BitmapFromString(9, 5, 'meJwLy2wMy2yMyG4GosicViCKymsH' + 'IiA3NKMeKAUUic7viCvqSSidkFQxObV6OpANlDJwCoMgoGKgSGL5R' + 'KBUStVUuDgyAkoBEaY40EyglvS6WQBlCjOd');
  end;

  result := length(Food);
end;

function declarePots:Integer;
begin

  with Pots[0] do
  begin
    color := 10433329;
    tol := 10;
    hmod := 0.03;
    smod := 0.11;
    cost := 1000;
    timeout := 800000;
    name := 'Super Attack';
    info := 'Increases Attack level by 15%';
  end;

  with Pots[1] do
  begin
    color := 9868958;
    tol := 12;
    hmod := 0.20;
    smod := 0.19;
    cost := 1000;
    timeout := 800000;
    name := 'Super Strength';
    info := 'Increases Strength level by 15%';
  end;

  with Pots[2] do
  begin
    color := 3311009;
    tol := 10;
    hmod := 0.02;
    smod := 0.10;
    cost := 1000;
    timeout := 800000;
    name := 'Super Defense';
    info := 'Increases Defense level by 15%';
  end;

  with Pots[3] do
  begin
    color := 11183412;
    tol := 8;
    hmod := 0.03;
    smod := 0.13;
    cost := 350;
    timeout := 600000;
    name := 'Attack Potion';
    info := 'Increases Attack level by 10%';
  end;

  with Pots[4] do
  begin
    color := 3185307;
    tol := 11;
    hmod := 0.02;
    smod := 0.08;
    cost := 750;
    timeout := 600000;
    name := 'Strength Potion';
    info := 'Increases Strength level by 10%';
  end;

  with Pots[5] do
  begin
    color := 3383089;
    tol := 10;
    hmod := 0.03;
    smod := 0.08;
    cost := 550;
    timeout := 600000;
    name := 'Defense Potion';
    info := 'Increases Defense level by 10%';
  end;

  with Pots[6] do
  begin
    color := 10847539;
    tol := 9;
    hmod := 0.02;
    smod := 0.14;
    cost := 2000;
    timeout := 600000;
    name := 'Range Potion';
    info := 'Increases Range level by 10%';
  end;

  with Pots[7] do
  begin
    color := 8611642;
    tol := 9;
    hmod := 0.04;
    smod := 0.08;
    cost := 1100;
    timeout := 500000;
    name := 'Magic Potion';
    info := 'Increase Magic level by 10%';
  end;

  result := length(Pots);
end;

function declarePrayers:Integer;
begin

  with Prayer[0] do
  begin
    Location := Point(0, 0);
    name := 'Thick skin';
    info := 'Increases defense by 5%';
    Exceptions := [5, 13, 25, 27, 28, 29];
    level := 1;
  end;

  with Prayer[1] do
  begin
    Location := Point(0, 1);
    name := 'Burst of strength';
    info := 'Increases strength by 5%';
    Exceptions := [3, 4, 6, 11, 12, 14, 20, 21, 25, 27, 28, 29]
    level := 4;
  end;

  with Prayer[2] do
  begin
    Location := Point(0, 2);
    name := 'Clarity of thought';
    info := 'Increases attack by 5%';
    Exceptions := [3, 4, 7, 11, 12, 15, 20, 21, 25, 27, 28, 29];
    level := 7;
  end;

  with Prayer[3] do
  begin
    Location := Point(0, 3);
    name := 'Sharp eye';
    info := 'Increases range by 5%';
    Exceptions := [1, 2, 4, 6, 7, 11, 12, 14, 15, 20, 21, 25, 27, 28, 29];
    level := 8;
  end;

  with Prayer[4] do
  begin
    Location := Point(0, 4);
    name := 'Mystic will';
    info := 'Increases magic by 5%';
    Exceptions := [1, 2, 3, 6, 7, 11, 12, 14, 15, 20, 21, 25, 27, 28, 29];
    level := 9;
  end;

  with Prayer[5] do
  begin
    Location := Point(1, 0);
    name := 'Rock skin';
    info := 'Increases defense by 10%';
    level := 10;
    Exceptions := [0, 13, 25, 27, 28, 29];
  end;

  with Prayer[6] do
  begin
    Location := Point(1, 1);
    name := 'Super strength';
    info := 'Increases strength by 10%';
    Exceptions := [1, 3, 4, 11, 12, 14, 20, 21, 25, 27, 28, 29];
    level := 13;
  end;

  with Prayer[7] do
  begin
    Location := Point(1, 2);
    name := 'Improved reflexes';
    info := 'Increases attack by 10%';
    Exceptions := [2, 3, 4, 11, 12, 15, 20, 21, 25, 27, 28, 29];
    level := 16;
  end;

  with Prayer[8] do
  begin
    Location := Point(1, 3);
    name := 'Rapid restore';
    info := '2x restore rate for all stats but prayer';
    Exceptions := [26];
    level := 19;
  end;

  with Prayer[9] do
  begin
    Location := Point(1, 4);
    name := 'Rapid heal';
    info := '2x restore rate for health';
    Exceptions := [26];
    level := 22;
  end;

  with Prayer[10] do
  begin
    Location := Point(2, 0);
    name := 'Protect item';
    info := 'Keep 1 extra item if you die';
    Exceptions := [];
    level := 25;
  end;

  with Prayer[11] do
  begin
    Location := Point(2, 1);
    name := 'Hawk eye';
    info := 'Increases range by 10%';
    Exceptions := [1, 2, 3, 4, 6, 7, 12, 14, 15, 20, 21, 25, 27, 28, 29];
    level := 26;
  end;

  with Prayer[12] do
  begin
    Location := Point(2, 2);
    name := 'Mystic lore';
    info := 'Increases magic by 10%';
    Exceptions := [1, 2, 3, 4, 6, 7, 11, 14, 15, 20, 21, 25, 27, 28, 29];
    level := 27;
  end;

  with Prayer[13] do
  begin
    Location := Point(2, 3);
    name := 'Steel skin';
    info := 'Increases defense by 15%';
    Exceptions := [0, 5, 25, 27, 28, 29];
    level := 28;
  end;

  with Prayer[14] do
  begin
    Location := Point(2, 4);
    name := 'Ultimate strength';
    info := 'Increases strength by 15%';
    Exceptions := [1, 3, 4, 6, 11, 12, 20, 21, 25, 27, 28, 29];
    level := 31;
  end;

  with Prayer[15] do
  begin
    Location := Point(3, 0);
    name := 'Incredible reflexes';
    info := 'Increases attack by 15%';
    Exceptions := [2, 3, 4, 7, 11, 12, 20, 21, 25, 27, 28, 29];
    level := 34;
  end;

  with Prayer[16] do
  begin
    Location := Point(3, 1);
    name := 'Protect summoning';
    info := 'null';
    Exceptions := [22, 24];
    level := 36;
  end;

  with Prayer[17] do
  begin
    Location := Point(3, 2);
    name := 'Protect magic';
    info := 'Decreases NPC magic damage by 40%';
    Exceptions := [18, 19, 22, 24];
    level := 37;
  end;

  with Prayer[18] do
  begin
    Location := Point(3, 3);
    name := 'Protect missiles';
    info := 'Decreases NPC range damage by 40%';
    Exceptions := [17, 19, 22, 24];
    level := 40;
  end;

  with Prayer[19] do
  begin
    Location := Point(3, 4);
    name := 'Protect melee';
    info := 'Decreases NPC melee damage by 40%';
    Exceptions := [17, 18, 22, 24];
    level := 43;
  end;

  with Prayer[20] do
  begin
    Location := Point(4, 0);
    name := 'Eagle eye';
    info := 'Increases range by 15%';
    Exceptions := [1, 2, 3, 4, 6, 7, 11, 12, 14, 15, 21, 25, 27, 28, 29];
    level := 44;
  end;

  with Prayer[21] do
  begin
    Location := Point(4, 1);
    name := 'Mystic mite';
    info := 'Increases magic by 15%';
    Exceptions := [1, 2, 3, 4, 6, 7, 11, 12, 14, 15, 20, 25, 27, 28, 29];
    level := 45;
  end;

  with Prayer[22] do
  begin
    Location := Point(4, 2);
    name := 'Retribution';
    info := 'null';
    Exceptions := [17, 18, 19, 23, 24];
    level := 46;
  end;

  with Prayer[23] do
  begin
    Location := Point(4, 3);
    name := 'Redemption';
    info := 'Heals you when your health is low';
    Exceptions := [17, 18, 19, 22, 24];
    level := 49;
  end;

  with Prayer[24] do
  begin
    Location := Point(4, 4);
    name := 'Smite';
    info := 'null';
    Exceptions := [17, 18, 19, 22, 23];
    level := 52;
  end;

  with Prayer[25] do
  begin
    Location := Point(5, 0);
    name := 'Chivarly';
    info := 'def + 20%, str + 18%, and atk + 15%';
    Exceptions := [0, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 15, 20, 21, 27, 28, 29];
    level := 60;
  end;

  with Prayer[26] do
  begin
    Location := Point(5, 1);
    name := 'Rapid renewal';
    info := 'Restores life at 5x the normal rate';
    Exceptions := [8, 9];
    level := 65;
  end;

  with Prayer[27] do
  begin
    Location := Point(5, 2);
    name := 'Peity';
    info := 'Def + 25%, str + 23%, and atk+ 20%';
    Exceptions := [0, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 15, 20, 21, 25, 28, 29];
    level := 70;
  end;

  with Prayer[28] do
  begin
    Location := Point(5, 3);
    name := 'Rigour';
    info := 'range + 20%, defense + 25%';
    Exceptions := [0, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 15, 20, 21, 25, 27, 29];
    level := 74;
  end;

  with Prayer[29] do
  begin
    Location := Point(5, 4);
    name := 'Augury';
    info := 'magic + 20%, defense + 25%';
    Exceptions := [0, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 15, 20, 21, 25, 27, 28];
    level := 77;
  end;

  result := length(Prayer);

end;

Procedure freeMemory;
var
  i:Integer;
begin
  Writeln('Thanks for using this script!');
  FreeBitmap(casketBMP);
  for i := 0 to high(groundObject) do
    FreeBitmap(groundObject[i].textbmp);
  for i := 0 to high(NPC) do
    FreeBitmap(NPC[i].textbmp);
  for i := 0 to high(food) do
    Freebitmap(Food[i].bmp);
  if (loot = true) then
    Writeln('==================Loot table==================');
  for i := 0 to high(lootItem) do
  begin
    if (loot = true) then
      Writeln('Object ' + groundObject[lootItem[i]].name + ' looted: ' + ToStr(groundObject[lootItem[i]].amount));
  end;
  Writeln('=============================================');
  for i := 0 to high(NPCKill) do
  begin
    Writeln('===============NPC kill table===============');
    Writeln('NPC ' + NPC[NPCKill[i]].name + ' killed ' + ToStr(NPC[NPCKill[i]].killed) + ' times');
  end;
  if (useFood = true) then
    Writeln('===============Food Used===============');
  for i := 0 to high(fooduse) do
  begin
    if (useFood = true) then
      Writeln(Food[foodUse[i]].name + ' eaten ' + ToStr(Food[fooduse[i]].used) + ' times (' + ToStr((Food[FoodUse[i]].cost * Food[FoodUse[i]].used)) + ' worth)' );
  end;
  if (usePrayer = true) then
  begin
    Writeln('===============Prayer pots Used===============');
    Writeln(ToStr(Round(praysDrank/3)) + ' Potions(3)');
  end;
  if (usePots = true) then
  begin
    Writeln('===============Potions Used===============');
    for i := 0 to high(PotsUse) do
      Writeln(Pots[PotsUse[i]].name + '(3) drank ' + ToStr(Round(Pots[PotsUse[i]].used/3)) + ' (' + ToStr((Pots[PotsUse[i]].cost * Pots[PotsUse[i]].used)/3) + ' worth)');
  end;
  Writeln('=============================================');
end;

procedure filterTPAsBetween(var atpa: T2DPointArray; len1, len2: integer);
var
  h, l, i: integer;
  c: T2DPointArray;
begin
  h := high(atpa);
  for i := 0 to h do
  begin
    l := length(atpa[i]);
    if (not (inRange(l, len1, len2))) then
    begin
      setLength(c, length(c) + 1);
      c[high(c)] := atpa[i];
    end;
  end;
  atpa := c;
end;

procedure TIAAppend(var TIA: TIntegerArray; x: Integer);
var
  aL: Integer;
begin
  aL := (Length(TIA) + 1);
  SetLength(TIA, aL);
  TIA[(aL - 1)] := Integer(x);
end;

function TIADelete(var TIA: TIntegerArray; x: Integer): Boolean;
var
  i, h: Integer;
begin
  h := High(TIA);
  Result := ((x <= h) and (x > -1));
  if not Result then
    Exit;
  for i := x to (h - 1) do
    TIA[i] := TIA[(i + 1)];
  SetLength(TIA, h);
end;

function IntInArray(int:Integer; TIA:TIntegerArray):Boolean;
var
  i:Integer;
begin
  for i := 0 to high(TIA) do
    if (TIA[i] = int) then result := true;
end;

Procedure report(status:string);
var
  kills_PH, XP_PH, Loot_PH, timeoutleft, i, killed, XP:Integer;
begin
  if (debug = true) then
    exit;
  for i := 0 to high(NPCKill) do
  begin
    killed := killed + NPC[NPCKill[i]].killed;
    XP := XP + (NPC[NPCKill[i]].XP*NPC[NPCKill[i]].killed);
  end;
  kills_PH := Round(killed * (3600.0 / (GetTimeRunning / 1000.0)));
  XP_PH := Round((killed*12921) * (3600.0 / (GetTimeRunning / 1000.0)));
  Loot_PH := Round(Looted * (3600.0 / (GetTimeRunning / 1000.0)));
  timeoutleft := (timeout - (TimeFromMark(t)));
  Cleardebug;
  Writeln('=======================================');
  Writeln('Time running: ' + Timerunning);
  Writeln('State: ' + Status);
  Writeln('Kills: ' + ToStr(GroupDigits(Killed,',')) + ' per hour: ' + ToStr(kills_PH));
  Writeln('XP gained: ' + ToStr(GroupDigits(XP,',')) + ' per hour: ' + ToStr(GroupDigits(XP_PH,',')));
  if (loot = true) then
    Writeln('Items Looted: ' + ToStr(Groupdigits(looted,',')) + ' per hour: ' + ToStr(Loot_PH));
  Writeln('Timeout left: ' + ToStr(GroupDigits(timeoutleft,',')));
  Writeln('=======================================');
end;

Procedure dBug(bugmsg:string);
begin
  if (debug = true) then
    Writeln(ToStr(bugmsg));
end;

function containsText():boolean;
var
  x,y:Integer;
begin
  Result := FindColortolerance(x, y, 188639, 8, 8, 157, 24, 50);
end;

function t_loggedin:Boolean;
begin
  result := (GetColor(472, 491) = 16777215);
end;

Procedure t_SetangleHigh();
begin
  Keydown(VK_Up);
  wait(RandomRange(2000, 3000));
  KeyUp(VK_Up);
end;

function CompassBalenced():Boolean;
var
  x, y:Integer;
begin
  Result := (FindColortolerance(x, y, 1911089, 542, 11, 545, 14, 20) and (FindColortolerance(x, y, 920735, 530, 24, 534, 27, 25)));
end;

Procedure MakeCompassNorth;
begin
  if not CompassBalenced() then
  begin
    MarkTime(t);
    Keydown(VK_Right);
    Dbug('Making compass north');
    waitfunc(@CompassBalenced, 100, 3000);
    KeyUp(VK_Right);
  end;
end;

function findGroundItem(col, tol, w, h, filter, tBMP:Integer; hmod, smod:extended):Boolean;
var
  TPA:TPointArray;
  ATPA:T2DPointArray;
  i, x, y, tx, ty:Integer;
begin
  if (not t_loggedin) then exit;
  Dbug('Looking for ground items');
  ColorToleranceSpeed(2);
  SetColorSpeed2Modifiers(hmod, smod);
  FindColorsSpiralTolerance(256, 166, TPA, col, 3, 3, 514, 339, tol);
  ColorToleranceSpeed(1);
  SetColorSpeed2Modifiers(0.02, 0.02);
  if (Length(TPA) > 0) then
  begin
    Dbug('TPA length: ' + toStr(Length(TPA)));
    ATPA := TPAToATPAEx(TPA, w, h);
    filterTPAsBetween(ATPA, 1, filter);
    SortATPAFromFirstpoint(ATPA, Point(256, 166));
    Dbug('ATPA length: ' + toStr(Length(ATPA)));
    if (debug = true) then
      DebugATPABounds(ATPA);
    for i := 0 to high(ATPA) do
    begin
      MiddleTPAEx(ATPA[i], x, y);
      mouse(x, y, 0, 0, Mouse_Right);
      wait(300);
      if findBitmapToleranceIn(TBMP, tx, ty, 0, 0, 514, 339, 100) then
      begin
        result := true;
        mouse(tx, ty, 0, 0, Mouse_Left);
        wait(1200);
        while (ismoving) do
          wait(200);
        exit;
      end;
    end;
  end;
end;

procedure t_logout;
begin
  Mouse(755, 11, 0, 0, Mouse_left);
  wait(400);
  Mouse(641, 406, 0, 0, Mouse_left);
  wait(500);
end;

function findPotion(col, tol:Integer;hmod, smod:Extended):Boolean;
var
  TPA:TPointArray;
  ATPA:T2DPointArray;
  x, y:Integer;
begin
  if (not t_loggedin) then
    exit;
  Dbug('Looking for Potion');
  ColorToleranceSpeed(2);
  SetColorSpeed2Modifiers(hmod, smod);
  FindColorsSpiralTolerance(579, 235, TPA, col, 551, 208, 733, 465, tol);
  ColorToleranceSpeed(1);
  SetColorSpeed2Modifiers(0.02, 0.02);
  if (Length(TPA) > 0) then
  begin
    Dbug('TPA length: ' + toStr(Length(TPA)));
    ATPA := TPAToATPAEx(TPA, 7, 4);
    SortATPAFromFirstpoint(ATPA, Point(579, 235));
    Dbug('ATPA length: ' + toStr(Length(ATPA)));
    if (debug = true) then
      DebugATPABounds(ATPA);
    MiddleTPAEx(ATPA[0], x, y);
    Mouse(x, y, 0, 0, Mouse_left);
    wait(1000);
    result := true;
  end;
end;

procedure tabInv;
var
  x, y:Integer;
begin
  if not FindColorTolerance(x, y, 4303081, 642, 170, 672, 205, 18) then
    Mouse(658, 188, 0, 0, Mouse_left);
end;

function lowPrayer:Boolean;
var
  x, y:Integer;
begin
  result := not FindColorTolerance(x, y, 65280, 740, 71, 759, 80, 15);
end;

procedure prayUp;
begin
  if (lowPrayer) then
  begin
    case (PrayPotType) of
      'pray':
      begin
        Report('Drinking prayer pots');
        case findPotion(8037427, 9, 0.03, 0.11) of
          True: praysdrank := praysdrank +1;
          False:
          begin
            if (keepPraying = true) then
            begin
              Writeln('Ran out of prayer pots, terminating');
              t_logout;
              TerminateScript;
            end;
          end;
        end;
      end;
      'restore':
      begin
        Report('Drinking resture pots');
        case findPotion(5191290, 8, 0.03, 0.09) of
          True: praysdrank := praysdrank +1;
          False:
          begin
          if (keepPraying = true) then
            begin
              Writeln('Ran out of prayer pots, terminating');
              t_logout;
              TerminateScript;
            end;
          end;
        end;
      end;
    end;
  end;
end;

procedure tabPrayer;
begin
  Mouse(717, 189, 0, 0, Mouse_left);
end;

procedure startPrayer;
var
  basex, basey, i:Integer;
begin
  basex := 570;
  basey := 227;
  tabPrayer;
  wait(300);
  for i := 0 to high(PrayUse) do
  begin
    Mouse(basex + (37 * Prayer[PrayUse[i]].location.y), basey + (35 * Prayer[PrayUse[i]].location.x), 0, 0, Mouse_left);
    wait(400);
  end;
end;

function needEat:Boolean;
var
  x, y:Integer;
begin
  result := not FindColorTolerance(x, y, 65280, 723, 31, 745, 41, 15);
end;

procedure eatUp;
var
  i, x, y:Integer;
begin
  if (needEat) then
  begin
    report('Eating Food');
    tabInv;
    for i := 0 to high(fooduse) do
    begin
      if (needEat) then // added again to avoid overeating
      begin
        case (FindbitmapToleranceIn(Food[FoodUse[i]].bmp, x, y, 551, 211, 738, 467, Food[FoodUse[i]].tol)) of
          True:
          begin
            Food[FoodUse[i]].used := Food[FoodUse[i]].used + 1;
            wait(600);
          end;
          False:
          begin
            report('Ran out of food');
            wait(4000);
            t_logout;
            Writeln('ran out of food script terminate');
            TerminateScript;
          end;
        end;
      end;
    end;
  end;
end;

procedure potUp;
var
  i:Integer;
  needPot:Boolean;
begin
  if (ranout = true) then
    exit;
  if (Debug) then
  begin
    for i := 0 to high(PotsUse) do
      Writeln(Pots[PotsUse[i]].name + ' ' + ToStr(TimeFromMark(Pots[PotsUse[i]].time)) + ' ms');
  end;
  for i := 0 to high(PotsUse) do
  begin
    if (TimeFromMark(Pots[PotsUse[i]].time)>Pots[PotsUse[i]].timeout) then
    begin
      Report('Drinking ' + Pots[PotsUse[i]].name);
      tabInv;
      case findPotion(Pots[PotsUse[i]].color, Pots[PotsUse[i]].tol, Pots[PotsUse[i]].hmod, Pots[PotsUse[i]].smod) of
        True:
        begin
          Pots[PotsUse[i]].used := Pots[PotsUse[i]].used + 1;
          MarkTime(Pots[PotsUse[i]].time);
        end;
        False:
        begin
          case KeepPotting of
            True:
              begin
                Writeln('Ran out of pots, Terminating script!');
                t_logout;
                TerminateScript;
              end;
            False: ranout := true;
          end;
        end;
      end;
    end;
  end;
end;

procedure lootItems;
var
  i:Integer;
begin
  if (loot = false) then exit;
  Dbug('Starting loot items procedure');
  for i := 0 to high(lootItem) do
  begin
    report('Looting ' + groundObject[lootItem[i]].name);
    Dbug('Looting ' + groundObject[lootItem[i]].name);
    if findGroundItem(groundObject[lootItem[i]].color, groundObject[lootItem[i]].tol, groundObject[lootItem[i]].width, groundObject[lootItem[i]].height, groundObject[lootItem[i]].filter, groundObject[lootItem[i]].textBMP, groundObject[lootItem[i]].hmod, groundObject[lootItem[i]].smod) then
    begin
      Dbug('Found ' + groundObject[lootItem[i]].name)
      inc(groundObject[lootItem[i]].amount);
      looted := looted+1;
    end;
  end;
end;

Procedure usecaskets;
var
  x, y:Integer;
begin
  tabInv;
  If FindBitMapToleranceIn(casketBMP, x, y, 556, 213, 732, 462, 130) then
  begin
    report('Opening casket');
    DBug('Opening casket');
    Mouse(x, y, 0, 0, Mouse_left);
    wait(500);
  end;
end;

function countText:Integer;
var
  textTPA:TPointArray;
begin
  FindColorsTolerance(textTPA, 12378347, 251, 145, 514, 362, 1);
  result := length(textTPA);
end;

function LoginError:String;
begin
  case (countText) of
    364: result := 'internet';
    2181: result := 'details';
  end;
end;

function d_boxup:Boolean;
begin
  result := (CountColortolerance(1842209, 270, 172, 493, 250, 5)<200);
end;

Procedure DeleteSpace(amt:integer);
var
  i:integer;
begin
  for i := 0 to amt do
  begin
    KeyDown(8);
    wait(40);
  end;
  KeyUp(8);
end;

function noDetails:Boolean;
begin
  result := ((t_username = '') or (t_password = ''));
end;

Procedure t_loginPlayer;
var
  x, y:Integer;
begin
  if t_loggedin then exit;
  if noDetails then
  begin
    Writeln('You are logged out and did not enter in any login details, terminating script');
    TerminateScript;
  end;
  if (d_boxup) then
  begin
    case (LoginError) of
      'internet':
      begin
        Writeln('Error connecting to server waiting');
        wait(10000);
        Mouse(381, 320, 0, 0, Mouse_left);
        wait(500);
      end;
      'details':
      begin
        Writeln('Invalid username or password');
        Mouse(378, 375, 0, 0, Mouse_left);
        wait(500)
      end;
    end;
  end;
  if findColorTolerance(x, y, 1315865, 280, 175, 486, 197, 15) then
  begin
    Mouse(475, 186, 0, 0, Mouse_Left);
    DeleteSpace(20);
    TypeSend(t_username);
    wait(200);
    DeleteSpace(15);
    TypeSend(t_password);
    waitfunc(@T_loggedin, 400, 5000);
  end;
end;

function hpExists(bounds:TBox; offx, offy:Integer):Boolean;
var
  counts: array[0..1] of integer;
begin
   // arrays not needed but looks better IMO
  if (not t_loggedin) then exit;
  try
    ColorToleranceSpeed(2);
    SetColorSpeed2Modifiers(0.76, 0.00);
    counts[0] := CountColorTolerance(48994, bounds.x1-offx, bounds.y1-offy, bounds.x2, bounds.y2, 6);
    SetColorSpeed2Modifiers(5.50, 0.26);
    counts[1] := CountColorTolerance(11644162, bounds.x1-offx, bounds.y1-offy, bounds.x2, bounds.y2, 9);
    ColorToleranceSpeed(1);
    SetColorSpeed2Modifiers(0.02, 0.02);
    DBug('Green count: ' + ToStr(counts[0]) + ' Red count: ' + toStr(counts[1]));
    if (counts[0]>30) or (counts[1]>30) then
      result := true;
  except
    Writeln('TBox is out of Bounds');
    result := false;
  end;
end;

function isFighting:Boolean;
var
  Bounds:Tbox;
begin
  Bounds := IntToBox(246, 141, 285, 170);
  result := hpExists(Bounds, 0, 10);
end;

Procedure waitingProc;
begin
  Dbug('Found NPC');
  wait(waitclick);
  while (isMoving) do
    wait(200);
end;

function findNPC(col, tol, w, h, filter, tBMP:Integer; hmod, smod:extended; clickR:Boolean):Boolean;
var
  TPA:TPointArray;
  ATPA:T2DPointArray;
  i, x, y, tx, ty:Integer;
  Bounds:TBox;
begin
  DBug('Started find NPC proc');
  ColorToleranceSpeed(2);
  SetColorSpeed2Modifiers(hmod, smod);
  FindColorsSpiralTolerance(256, 166, TPA, col, 3, 3, 514, 339, tol);
  ColorToleranceSpeed(1);
  SetColorSpeed2Modifiers(0.02, 0.02);
  if (Length(TPA) > 0) then
  begin
    DBug('TPA length: ' + ToStr(length(TPA)));
    ATPA := TPAToATPAEx(TPA, w, h);
    filterTPAsBetween(ATPA, 1, filter);
    SortATPAFromFirstpoint(ATPA, Point(256, 166));
    DBug('ATPA length: ' + ToStr(length(ATPA)));
    if (debug = true) then
      DebugATPABounds(ATPA);
    for i := 0 to high(ATPA) do
    begin
      Bounds := GetTPABounds(ATPA[i]);
      MiddleTPAEx(ATPA[i], x, y);
      if not hpExists(Bounds, 6, 6) then
      begin
        mmouse(x, y, 0, 0);
        if waitfunc(@containsText,50, 300) then
        begin
          case (ClickR) of
            True:
            begin
              ClickMouse2(Mouse_Right);
              wait(300);
              If FindBitMapToleranceIn(tBMP, tx, ty, 3, 3, 514, 339, 130) then
              begin
                result := true;
                mouse(tx, ty, 0, 0, Mouse_left);
                waitingProc;
                exit;
              end;
            end;
            False:
            begin
              result := true;
              ClickMouse2(Mouse_left);
              waitingproc;
              exit;
            end;
          end;
        end;
      end;
    end;
  end;
end;

Procedure fightNPCs;
var
  i:Integer;
begin
  for i:= 0 to high(NPCKill) do
  begin
    DBug('Finding NPC ' + NPC[NPCKill[i]].name);
    case (findNPC(NPC[NPCKill[i]].Color, NPC[NPCKill[i]].tol, NPC[NPCKill[i]].width, NPC[NPCKill[i]].height, NPC[NPCKill[i]].filter, NPC[NPCKill[i]].textBMP, NPC[NPCKill[i]].hmod, NPC[NPCKill[i]].smod, NPC[NPCKill[i]].RClick)) of
      True:
      begin
        marktime(t);
        repeat
          MarkTime(failsafe);
          report('Attacking ' + NPC[NPCKill[i]].name);
          wait(200);
          if (useFood = true) then
            eatUp;
          if (usePrayer = true) then
            PrayUp;
        until (not Isfighting) or (TimeFromMark(t) > timeout);
        if (not isfighting) then
        begin
          NPC[NPCKill[i]].killed := NPC[NPCKill[i]].killed +1;
          lootItems;
        end;
      end;
      False:
      begin
        report('Could not find ' + NPC[NPCKill[i]].name);
        MarkTime(failsafe);
        wait(500);
      end;
    end;
  end;
end;

procedure Update(Sender: TObject);
var
 latestVersion: Extended;
 str: string;
begin
  WriteLn('Getting update information, please wait.');
  WriteLn('This step may take a couple seconds!');
  str := GetPage('http://villavu.com/forum/showthread.php?t=105062');
  latestVersion := StrToFloatDef(Between('autoupdate', 'abcdef', str), -1);
  case (latestVersion > -1) of
    True:
    begin
      WriteLn('Current Version: ' + FloatToStr(VERSION) + ' | Latest Version: ' + FloatToStr(latestVersion));
      case (VERSION = latestVersion) of
        False:
        case (VERSION < latestVersion) of
          True:
          begin
            WriteLn('You dont have the latest version, you can download the latest version from the thread.');
            OpenWebPage('http://villavu.com/forum/showthread.php?t=105062');
          end;
          False: WriteLn('Looks like your version is newer than the latest version - YAY!');
        end;
        True: WriteLn('Your version is up to date!');
      end;
    end;
    False: WriteLn('Failed to check the latest version... Connection problems?');
  end;
end;

procedure error(ErrorS:string);
begin
  MessageBox(ErrorS, 'Error', 16);
end;

procedure SaveForm(sender: TObject);
begin
  FormData.fightForm.ModalResult := mrOk;
  Loot := FormData.CheckBoxes[0].CHECKED;
  debug := FormData.CheckBoxes[1].CHECKED;
  usecasket := FormData.CheckBoxes[2].CHECKED;
  usePrayer := FormData.CheckBoxes[3].CHECKED;
  keepPraying := FormData.CheckBoxes[4].CHECKED;
  usePots := FormData.CheckBoxes[5].CHECKED;
  keepPotting := FormData.CheckBoxes[6].CHECKED;
  useFood := FormData.CheckBoxes[7].CHECKED;
  t_username := FormData.Edits[0].TEXT;
  t_password := FormData.Edits[1].TEXT;
  if (FormData.TimeOutEdit.text <> 'Combat Timeout') then
    timeout := StrToInt(FormData.TimeOutEdit.text);
  if (FormData.TimeOutEdit.text = 'Combat Timeout') then
    timeout := 19000;
  if (FormData.ClickDelay.text <> 'Click delay after attack') then
    waitclick := StrToInt(FormData.ClickDelay.TEXT);
  if (FormData.ClickDelay.text = 'Click delay after attack') then
    waitClick := 1700;
  case FormData.PrayCombo.ITEMINDEX of
    0: PrayPotType := 'pray';
    1: PrayPotType := 'restore';
  end;
  pressed := true;
  FormData.FightForm.CLOSE;
end;

procedure UpdateInfo(Sender:TObject);
var
  i:Integer;
begin
  case sender of
    FormData.Options[0]:
    begin
      if (FormData.Options[0].itemindex > - 1) then
      begin
        FormData.FoodInfo[0].Caption := 'Heals: ' + ToStr(Food[FormData.Options[0].ItemIndex].heal);
        FormData.FoodInfo[1].Caption := 'Cost: ' + ToStr(Food[FormData.Options[0].ItemIndex].cost);
        FormData.FoodButtons[0].enabled := true;
      end;
    end;
    FormData.Options[1]:
    begin
      if (FormData.Options[1].itemindex > - 1) then
      begin
        FormData.PotionButtons[0].enabled := true
        FormData.PotionInfo[0].Caption := Pots[FormData.Options[1].ItemIndex].info;
        FormData.PotionInfo[1].Caption := 'Cost: ' + ToStr(Pots[FormData.Options[1].ItemIndex].cost);
      end;
    end;
    FormData.Options[2]:
    begin
      if (FormData.Options[2].itemindex > - 1) then
      begin
        FormData.NPCInfo[0].Caption := 'Combat Level:' + ToStr(NPC[FormData.Options[2].ItemIndex].Combat);
        FormData.NPCInfo[1].Caption := 'Health: ' + ToStr(NPC[FormData.Options[2].ItemIndex].Health);
        FormData.DropList.ITEMS.Clear;
        FormData.DropList.visible := true;
        FormData.NPCButtons[0].enabled := true;
        FormData.NPCLabels[2].visible := true;
        for i := 0 to high(NPC[FormData.Options[2].ItemIndex].drops) do
          FormData.DropList.ITEMS.Add(groundObject[NPC[FormData.Options[2].ItemIndex].Drops[i]].name);
      end;
    end;
    FormData.Options[3]:
    begin
      if (FormData.Options[3].itemindex > - 1) then
      begin
        FormData.LootButtons[0].enabled := true;
        FormData.LootInfo[0].Caption := groundObject[FormData.Options[3].ItemIndex].name;
        FormData.LootInfo[1].Caption := 'Value:' + groundObject[FormData.Options[3].ItemIndex].value;
        FormData.LootInfo[2].Caption := 'Rarity: ' + ToStr(groundObject[FormData.Options[3].ItemIndex].odds);
      end;
    end;
    FormData.Options[4]:
    begin
      if (FormData.Options[4].itemindex > - 1) then
      begin
        FormData.PrayButtons[0].enabled := true;
        FormData.PrayLabels[0].Caption := Prayer[FormData.options[4].ItemIndex].name;
        FormData.PrayLabels[1].Caption := 'Level: ' + toStr(Prayer[FormData.options[4].ItemIndex].level);
        FormData.PrayLabels[2].Caption := Prayer[FormData.options[4].ItemIndex].info;
      end;
    end;
  end;
end;

procedure Updatechosen(sender:TObject);
begin
  case sender of
    FormData.Chosen[0]:
    begin
    if (high(FoodUse) > -1) then
      FormData.FoodButtons[1].enabled := true;
    end;
     FormData.Chosen[1]:
     begin
    if (high(PotsUse) > -1) then
        FormData.PotionButtons[1].enabled := true;
    end;
    FormData.Chosen[2]:
    begin
      if (high(NPCKill) > -1) then
        FormData.NPCButtons[1].enabled := true;
    end;
     FormData.Chosen[3]:
    begin
    if (high(LootItem) > -1) then
      FormData.LootButtons[1].enabled := true;
    end;
    FormData.Chosen[4]:
    begin
    if (high(PrayUse) > -1) then
        FormData.PrayButtons[1].enabled := true;
    end;
  end;
end;

function Exception: Boolean;
var
  i, l:Integer;
begin
  for i := 0 to high(PrayUse) do
  begin
    for l := 0 to high(Prayer[PrayUse[i]].Exceptions) do
    begin
      if (FormData.Options[4].ItemIndex = Prayer[PrayUse[i]].Exceptions[l]) then
      begin
        error('You can not use ' + Prayer[FormData.Options[4].ItemIndex].name + ' and ' + Prayer[PrayUse[i]].name + ' at the same time!');
        result := true;
        exit;
      end;
    end;
  end;
end;

procedure UpdateLoot(sender:TObject);
var
  i:Integer;
begin
 case sender of
    FormData.LootButtons[0]:
    begin
      if not IntInArray(FormData.Options[3].ItemIndex, LootItem) then
      begin
        FormData.CheckBoxes[0].CHECKED := true;
        TIAAppend(LootItem, FormData.Options[3].ItemIndex);
        FormData.Chosen[3].items.clear;
        for
        i := 0 to high(LootItem) do
          FormData.Chosen[3].items.add(groundObject[LootItem[i]].name);
        if (FormData.Options[3].itemIndex < 0) then
          FormData.LootButtons[0].enabled := false;
      end else if IntInArray(FormData.Options[3].ItemIndex, LootItem) then
        Error('You already added that Loot!')
    end;
    FormData.LootButtons[1]:
    begin
      if (FormData.Options[3].ItemIndex > - 1) then
      begin
        TIADelete(LootItem, FormData.Chosen[3].ItemIndex);
        FormData.Chosen[3].items.clear;
        for i := 0 to high(LootItem) do
          FormData.Chosen[3].items.add(groundObject[LootItem[i]].name);
        FormData.LootButtons[1].enabled := false;
        if (length(LootItem) < 1) then
          FormData.CheckBoxes[0].CHECKED := false;
      end else if (FormData.Options[3].ItemIndex < - 1) then
        Error('No selected Loot to delete!');
    end;
  end;
end;

procedure UpdateFood(sender:TObject);
var
  i:Integer;
begin
  case sender of
    FormData.FoodButtons[0]:
    begin
      if not IntInArray(FormData.Options[0].ItemIndex, FoodUse) then
      begin
        FormData.CheckBoxes[7].CHECKED := true;
        TIAAppend(FoodUse, FormData.Options[0].ItemIndex);
        FormData.Chosen[0].items.clear;
        for
        i := 0 to high(FoodUse) do
          FormData.Chosen[0].items.add(Food[FoodUse[i]].name);
        if (FormData.Options[0].itemIndex < 0) then
          FormData.FoodButtons[0].enabled := false;
      end else if IntInArray(FormData.Options[0].ItemIndex, FoodUse) then
        Error('You already added that Food!')
    end;
    FormData.FoodButtons[1]:
    begin
      if (FormData.Options[0].ItemIndex > - 1) then
      begin
        TIADelete(FoodUse, FormData.Chosen[0].ItemIndex);
        FormData.Chosen[0].items.clear;
        for i := 0 to high(FoodUse) do
          FormData.Chosen[0].items.add(Food[FoodUse[i]].name);
        FormData.FoodButtons[1].enabled := false;
        if (length(FoodUse) < 1) then
          FormData.CheckBoxes[7].CHECKED := false;
      end else if (FormData.Options[0].ItemIndex < - 1) then
        Error('No selected Food to delete!');
    end;
  end;
end;

procedure UpdatePotions(sender:TObject);
var
  i:Integer;
begin
  case sender of
    FormData.PotionButtons[0]:
    begin
      if not IntInArray(FormData.Options[1].ItemIndex, PotsUse) then
      begin
        FormData.CheckBoxes[5].CHECKED := true;
        TIAAppend(PotsUse, FormData.Options[1].ItemIndex);
        FormData.Chosen[1].items.clear;
        for
        i := 0 to high(PotsUse) do
          FormData.Chosen[1].items.add(Pots[PotsUse[i]].name);
        if (FormData.Options[1].itemIndex < 0) then
          FormData.PotionButtons[0].enabled := false;
      end else if IntInArray(FormData.Options[1].ItemIndex, PotsUse) then
        Error('You already added that Potion!')
    end;
    FormData.PotionButtons[1]:
    begin
      if (FormData.Options[1].ItemIndex > - 1) then
      begin
        TIADelete(PotsUse, FormData.Chosen[1].ItemIndex);
        FormData.Chosen[1].items.clear;
        for i := 0 to high(PotsUse) do
          FormData.Chosen[1].items.add(Pots[PotsUse[i]].name);
        FormData.PotionButtons[1].enabled := false;
        if (length(PotsUse) < 1) then
          FormData.CheckBoxes[5].CHECKED := false;
      end else if (FormData.Options[1].ItemIndex < - 1) then
        Error('No selected Potion to delete!');
    end;
  end;
end;

procedure UpdatePrayerList(sender:TObject);
var
  i, l:Integer;
begin
  case sender of
    FormData.PrayButtons[0]:
    begin
      if not IntInArray(FormData.Options[4].ItemIndex, PrayUse) then
      begin
        if (not Exception) then
        begin
          FormData.CheckBoxes[3].CHECKED := true;
          TIAAppend(PrayUse, FormData.Options[4].ItemIndex);
          FormData.Chosen[4].ITEMS.Clear;
          for i := 0 to high(prayUse) do
            FormData.Chosen[4].ITEMS.Add(Prayer[PrayUse[i]].name);
        end;
      end else if IntInArray(FormData.Options[4].ItemIndex, PrayUse) then
      begin
        Error('You already added that prayer!');
      end;
    end;
    FormData.PrayButtons[1]:
    begin
    if (FormData.Options[4].ItemIndex > - 1) then
      begin
        TIADelete(PrayUse, FormData.chosen[4].ItemIndex);
        FormData.Chosen[4].items.clear;
        for i := 0 to high(PrayUse) do
          FormData.Chosen[4].items.add(Prayer[PrayUse[i]].name);
        FormData.PrayButtons[1].enabled := false;
        if (length(PotsUse) < 1) then
          FormData.CheckBoxes[3].CHECKED := false;
      end else if (FormData.Options[4].ItemIndex < - 1) then
        Error('No selected Prayer to delete!')
    end;
  end;
end;

procedure UpdateKillList(Sender:TObject);
var
  i, reply:Integer;
  strings:TStringArray;
begin
  case sender of
    FormData.NPCButtons[0]:
    begin
      if not IntInArray(FormData.Options[2].ItemIndex, NPCKill) then
      begin
        TIAAppend(NPCKill, FormData.Options[2].ItemIndex);
        FormData.Chosen[2].items.clear;
        for i := 0 to high(NPCKill) do
          FormData.Chosen[2].items.add(NPC[NPCKill[i]].name);
        if (FormData.Options[2].itemIndex < 0) then
          FormData.NPCButtons[0].enabled := false;
      end else if IntInArray(FormData.Options[2].ItemIndex, NPCKill) then
        Error('You already added that NPC!')
    end;
    FormData.NPCButtons[1]:
    begin
      if (FormData.Chosen[2].ItemIndex > - 1) then
      begin
        TIADelete(NPCKill, FormData.Chosen[2].ItemIndex);
        FormData.Chosen[2].items.clear;
        for i := 0 to high(NPCKill) do
          FormData.Chosen[2].items.add(NPC[NPCKill[i]].name);
        FormData.NPCButtons[1].enabled := false;
      end else if (FormData.Options[2].ItemIndex < - 1) then
        Error('No selected NPC to delete!');
    end;
    FormData.NPCButtons[2]:
    begin
      reply := Messagebox('Please fillout this information', 'Information', 1);
      if (reply = 1) then
      begin
        Strings := ['NPC Name', 'Health', 'Combat level', 'Drops', 'Screeny (link)[img][/img]'];
        for i := 0 to 4 do
          Writeln(Strings[i]);
        Writeln('**********Please post this information on the thread!');
        wait(2000);
        OpenWebPage('http://villavu.com/forum/showthread.php?t=105062');
      end;
    end;
  end;
end;

procedure Other(sender:TObject);
begin
  case sender of
    FormData.Buttons[0]:
    begin
      pressed := false;
      FormData.FightForm.CLOSE;
    end;
    formData.Buttons[1]: OpenWebPage('http://villavu.com/forum/showthread.php?t=105062');
    FormData.Buttons[2]: OpenWebPage('http://villavu.com/forum/private.php?do=newpm&u=63718');
  end;
end;

procedure loadForm;
var
  i:Integer;
  Strings:TStringArray;
  Positions, Sizes:TPointArray;
begin
  FormData.FightForm := TForm.Create(nil);
  with FormData.FightForm do
  begin
    Caption := 'Telos-Reborn Auto Fighter Version ' + Disp;
    top := 200;
    left := 200;
    width := 540;
    height := 310;
  end;
  Formdata.TPage := TPageControl.Create(FormData.FightForm);
  with Formdata.TPage do
  begin
    parent := FormData.FightForm
    width := 541;
    height := 311;
  end;
  Strings := ['General', 'Food settings', 'Potion settings', 'NPC settings', 'Loot settings', 'Prayer settings', 'Misc'];
  for i := 0 to high(FormData.tabs) do
  begin
    FormData.Tabs[i] := TTabSheet.Create(Formdata.FightForm);
    with FormData.Tabs[i] do
    begin
      Caption := Strings[i];
      Parent := Formdata.TPage;
    end;
  end;
  for i := 0 to high(FormData.Trim) do
  begin
    FormData.Trim[i] := TShape.Create(FormData.Tabs[i]);
    with FormData.Trim[i] do
    begin
      Parent := FormData.Tabs[i];
      top := 1;
      left := 0;
      width := 531;
      height := 281;
      pen.color := 5;
    end;
  end;
  for i := 0 to high(FormData.Labels) do
  begin
    FormData.Labels[i] := TLabel.Create(FormData.Tabs[i]);
    with FormData.Labels[i] do
    begin
      Caption := Strings[i];
      Parent := FormData.Tabs[i];
      left := 210;
      top := 2;
      if (i = 0) then
      begin
        left := 220;
        top := 25;
      end;
      if (i = 6) then
        left := 250;
      Font.size := 14;
    end;
  end;
  Positions := [Point(92, 140), Point(210, 97)];
  Sizes := [Point(240, 55), Point(330, 50)];
  for i := 0 to high(FormData.GPanels) do
  begin
    FormData.GPanels[i] := TPanel.Create(FormData.Tabs[0]);
    with FormData.GPanels[i] do
    begin
      Parent := FormData.Tabs[0];
      Top := Positions[i].x;
      Left := Positions[i].y;
      Width := Sizes[i].x;
      Height := Sizes[i].y;
      PARENTCOLOR := false;
      COLOR := 15790320;
      //font.color := 32768;
    end;
  end;
  for i := 0 to high(FormData.Edits) do
  begin
    FormData.Edits[i] := TEdit.Create(FormData.Tabs[0]);
    with FormData.Edits[i] do
    begin
      Parent := FormData.GPanels[0];
      top := 22;
      left := 9 + (i * 140);
      if (i = 0) then
        text := T_username;
    end;
  end;
  Strings := ['Username', 'Password'];
  for i := 0 to high(FormData.LoginLabels) do
  begin
    FormData.LoginLabels[i] := TLabel.Create(FormData.GPanels[0]);
    with FormData.LoginLabels[i] do
    begin
      Parent := FormData.GPanels[0];
      Caption := Strings[i];
      top := 5;
      left := 22 + (i * 140);
    end;
  end;
  Strings := ['Quit', 'Update', 'Help', 'Start'];
  for i := 0 to high(FormData.Buttons) do
  begin
    FormData.Buttons[i] := TButton.Create(FormData.GPanels[1]);
    with FormData.Buttons[i] do
    begin
      Parent := FormData.GPanels[1];
      Caption := Strings[i];
      top := 12;
      left := 12 + (i * 77);
      OnClick := @Other;
      if (i = 3) then
        Onclick := @SaveForm;
      if (i = 1) then
        Onclick := [MENTION=129311]Update[/MENTION];
    end;
  end;
  for i := 0 to high(FormData.Options) do
  begin
    FormData.Options[i] := TListBox.Create(FormData.Tabs[i+1]);
    with FormData.Options[i] do
    begin
      Parent := FormData.Tabs[i+1];
      visible := true;
      Left := 40;
      if (i = 4) then
        left := 5;
      Top := 60;
      Width := 105;
      if (i = 4) then
        Width := 140;
      Height := 150;
      PARENTCOLOR := false;
      FONT.Size := 11;
      font.name := 'Times new Roman';
      Onclick := [MENTION=129311]Update[/MENTION]Info;
    end;
  end;
  for i := 0 to high(FormData.Chosen) do
  begin
    FormData.Chosen[i] := TListBox.Create(FormData.Tabs[i+1]);
    with FormData.Chosen[i] do
    begin
      Parent := FormData.Tabs[i+1];
      visible := true;
      Left := 200;
      if (i = 4) then
        left:= 170;
      Top := 60;
      Width := 105;
      if (i = 4) then
        Width := 130;
      Height := 150;
      PARENTCOLOR := false;
      FONT.Size := 11;
      font.name := 'Times new Roman';
      Onclick := [MENTION=129311]Update[/MENTION]Chosen;
    end;
  end;
  Strings := ['Add Prayer', 'Delete Prayer'];
  for i := 0 to high(FormData.PrayButtons) do
  begin
    FormData.PrayButtons[i] := TButton.Create(FormData.GPanels[1]);
    with FormData.PrayButtons[i] do
    begin
      Parent := FormData.tabs[5];
      Caption := Strings[i];
      top := 230;
      left := 12 + (i * 150);
      width := 120;
      OnClick := [MENTION=129311]Update[/MENTION]PrayerList;
      Enabled := false;
    end;
  end;
  Strings := ['Food information', 'Potion information','NPC information','Loot information','Prayer information'];
  Positions := [Point(45, 355), Point(45, 355), Point(40, 380), Point(35, 390), Point(35, 365)];
  for i := 0 to high(FormData.InfoLabels) do
  begin
    FormData.InfoLabels[i] := TLabel.Create(FormData.Tabs[i + 1]);
    with FormData.InfoLabels[i] do
    begin
      Parent := FormData.Tabs[i + 1];
      top := Positions[i].x;
      left := Positions[i].y;
      font.size := 10;
      font.name := 'times new roman';
      Caption := Strings[i];
    end;
  end;
  Positions := [Point(80, 330), Point(70, 313), Point(60, 350), Point(60, 340), Point(70, 305)];
  Sizes := [Point(140, 90), Point(210, 130), Point(140, 180), Point(170, 140), Point(220, 140)];
  for i := 0 to high(FormData.Shapes) do
  begin
    FormData.Shapes[i] := TShape.Create(FormData.Tabs[i+1]);
    with FormData.Shapes[i] do
    begin
      Parent := FormData.Tabs[i+1];
      top := Positions[i].x;
      left := Positions[i].y;
      width := Sizes[i].x;
      height := Sizes[i].y;
      pen.color := 0;
    end;
  end;
  for i := 0 to high(FormData.FoodInfo) do
  begin
    FormData.FoodInfo[i] := TLabel.Create(FormData.Tabs[1]);
    with FormData.FoodInfo[i] do
    begin
      Parent := FormData.Tabs[1];
      top := 100 + (i * 20);
      left := 370;
      font.size := 11;
      font.name := 'times new roman';
    end;
  end;
  for i := 0 to high(FormData.PotionInfo) do
  begin
    FormData.PotionInfo[i] := TLabel.Create(FormData.Tabs[2]);
    with FormData.PotionInfo[i] do
    begin
      Parent := FormData.Tabs[2];
      top := 110 + (i * 30);
      left := 330;
      font.size := 11;
      font.name := 'times new roman';
    end;
  end;
  for i := 0 to high(FormData.NPCInfo) do
  begin
    FormData.NPCInfo[i] := TLabel.Create(FormData.Tabs[3]);
    with FormData.NPCInfo[i] do
    begin
      Parent := FormData.Tabs[3];
      top := 65 + (i * 20);
      left := 375;
      font.size := 11;
      font.name := 'times new roman';
    end;
  end;
  for i := 0 to high(FormData.LootInfo) do
  begin
    FormData.LootInfo[i] := TLabel.Create(FormData.Tabs[4]);
    with FormData.LootInfo[i] do
    begin
      Parent := FormData.Tabs[4];
      top := 80 + (i * 40);
      left := 360;
      font.size := 11;
    end;
  end;
  for i := 0 to high(FormData.PrayLabels) do
  begin
    FormData.PrayLabels[i] := TLabel.Create(FormData.Tabs[5]);
    with FormData.PrayLabels[i] do
    begin
      Parent := FormData.Tabs[5];
      top := 80 + (i * 40);
      left := 310;
      font.size := 10;
    end;
  end;
  FormData.DropList := TListBox.Create(FormData.Tabs[3]);
  with FormData.DropList do
  begin
    Parent := FormData.Tabs[3];
    top := 130;
    Left := 360;
    Width := 120;
    Height := 100;
    font.size := 10;
    Visible := false;
  end;
  Strings := ['Add NPC', 'Delete NPC', 'Suggest NPC'];
  for i := 0 to high(FormData.NPCButtons) do
  begin
    FormData.NPCButtons[i] := TButton.Create(FormData.Tabs[3]);
    with FormData.NPCButtons[i] do
    begin
      Parent := FormData.Tabs[3];
      Caption := Strings[i];
      enabled := false;
      left := 25 + (i * 100);
      top := 220;
      width := 90;
      Onclick := [MENTION=129311]Update[/MENTION]KillList;
      if (i = 2) then
        enabled := true;
    end;
  end;
  Strings := ['Add loot', 'Delete Loot', 'Suggest loot'];
  for i := 0 to high(FormData.LootButtons) do
  begin
    FormData.LootButtons[i] := TButton.Create(FormData.Tabs[4]);
    with FormData.LootButtons[i] do
    begin
      Parent := FormData.Tabs[4];
      left := 25 + (i * 105);
      top := 220;
      width := 95;
      Caption := Strings[i];
      Onclick := [MENTION=129311]Update[/MENTION]Loot;
      enabled := false;
      if (i = 2) then
        enabled := true;
    end;
  end;
  Strings := ['Add Potion', 'Delete Potion'];
  for i := 0 to high(FormData.PotionButtons) do
  begin
    FormData.PotionButtons[i] := TButton.Create(FormData.Tabs[2]);
    with FormData.PotionButtons[i] do
    begin
      Parent := FormData.Tabs[2];
      left := 60 + (i * 115);
      top := 225;
      width := 105;
      Caption := Strings[i];
      Onclick := [MENTION=129311]Update[/MENTION]Potions;
      enabled := false;
    end;
  end;
  Strings := ['Add Food', 'Delete Food'];
  for i := 0 to high(FormData.FoodButtons) do
  begin
    FormData.FoodButtons[i] := TButton.Create(FormData.Tabs[2]);
    with FormData.FoodButtons[i] do
    begin
      Parent := FormData.Tabs[1];
      left := 60 + (i * 115);
      top := 225;
      width := 105;
      Caption := Strings[i];
      Onclick := [MENTION=129311]Update[/MENTION]Food;
      enabled := false;
    end;
  end;
  Strings := ['NPCs', 'Kill list', 'Drops'];
  for i := 0 to high(FormData.NPCLabels) do
  begin
    FormData.NPCLabels[i] := TLabel.Create(FormData.Tabs[3]);
    with FormData.NPCLabels[i] do
    begin
      Parent := FormData.Tabs[3];
      top := 40;
      left := 70 + (i * 160);
      if (i = 2) then
      begin
        top := 110;
        left := 400;
        Visible := false;
      end;
      font.size := 11;
      Caption := Strings[i];
    end;
  end;
  Strings := ['Loot items', 'Debug mode', 'Use caskets', 'Use Prayer', 'Logout when out of prayer' , 'Use Potions', 'Log out when out of potions', 'Use food'];
  for i := 0 to 3 do
  begin
    FormData.checkBoxes[i] := TCheckBox.create(FormData.tabs[6]);
    with FormData.CheckBoxes[i] do
    begin
      Parent := FormData.Tabs[6];
      Caption := Strings[i];
      top := 50 + (i * 40);
      left := 120;
    end;
  end;
  for i := 4 to 7 do
  begin
    FormData.checkBoxes[i] := TCheckBox.create(FormData.tabs[6]);
    with FormData.CheckBoxes[i] do
    begin
      Parent := FormData.Tabs[6];
      Caption := Strings[i];
      top := 50 + ((i-4) * 40);
      left := 260;
    end;
  end;
  FormData.PrayCombo := TComboBox.Create(FormData.Tabs[6]);
  with FormData.PrayCombo do
  begin
    Parent := Formdata.Tabs[6];
    Items.Add('Prayer Pots');
    Items.Add('Restore Pots');
    text := 'Prayer restore Method';
    font.size := 8;
    width := 140;
    left := 20;
    top := 230;
  end;
  FormData.TimeOutEdit := TEdit.Create(FormData.Tabs[6]);
  with FormData.TimeOutEdit do
  begin
    Parent := FormData.Tabs[6];
    Text := 'Combat Timeout';
    left := 190;
    top := 230;
    width := 120;
  end;
  FormData.Clickdelay := TEdit.Create(FormData.Tabs[6]);
  with FormData.Clickdelay do
  begin
    Parent := FormData.Tabs[6];
    Text := 'Click delay after attack';
    left := 340;
    top := 230;
    width := 150;
  end;
  for i := 0 to high(Food) do
    FormData.Options[0].ITEMS.Add(Food[i].name);
  for i := 0 to high(Pots) do
    FormData.Options[1].ITEMS.Add(Pots[i].name);
  for i := 0 to high(NPC) do
    FormData.Options[2].ITEMS.Add(NPC[i].name);
  for i := 0 to high(groundObject) do
    FormData.Options[3].ITEMS.Add(groundObject[i].name);
  for i := 0 to high(Prayer) do
    FormData.Options[4].ITEMS.Add(Prayer[i].name);
end;
procedure SafeInitForm;
var
  v: TVariantArray;
begin
  SetLength(V, 0);
  ThreadSafeCall('loadForm', v);
end;

procedure ShowFormModal;
begin
  FormData.FightForm.ShowModal;
end;

procedure SafeShowFormModal;
var
  v: TVariantArray;
begin
  SetLength(V, 0);
  ThreadSafeCall('ShowFormModal', v);
end;

Procedure loadVars;
begin
  marktime(t);
  t_DeclarePlayers;
  mousespeed := 20;
  AddOnTerminate('freememory');
  CasketBMP := BitmapFromString(20, 12, 'meJzjsQlKjo9PS0zMSE7mdYjkdY' + 'rmdYkFIdd4PvdEPo9kPq80CKooKqoqKYEgoDhIjVN0Tno6BKFp4ff' + 'OgCLfLAiqLisDotqKCqAsxBagypL8fAiCaoEp5vfLQUZAXUBUX1UF' + 'sheo1ykaaBHQPRAnAaXQ1CMjoC4gaqypBukFetAhEqgXaBfETPx6B' + 'QLygBox9ULMBCK4Sundy6R2LJbaukBq01ygLgjCqhcuDlEjuXqGzO' + 'G1MkfXyRxaLb1/JRa9QP/C9QYWIOsF2gXUK3tio+zpLUBEmt4di+F' + '65S7skLu8C0UvJI5w6MWFBoNeAGrc6/c=');
  Writeln('Loaded ' + toStr(declareObjects) + ' ground items');
  Writeln('Loaded ' + toStr(declareNPCs) + ' NPCs');
  Writeln('Loaded ' + toStr(declarePots) + ' Potions');
  Writeln('Loaded ' + toStr(declareFood) + ' Food');
  Writeln('Loaded ' + toStr(declarePrayers) + ' Prayers');
  Writeln('Took ' + ToStr(TimeFromMark(t)) + ' ms to start up.');
end;

begin
  loadVars;
  if (useForm = true) then
  begin
    SafeInitForm;
    SafeShowFormModal;
  end;
  if (UseForm = true) and (pressed = false) then
    TerminateScript;
  wait(1500);
  activateclient;
  t_loginPlayer;
  MakeCompassNorth;
  if (usePrayer = true) then
    startPrayer;
  if (usePots = true) then
    PotUp;
  repeat
    if (not t_loggedin) then
    begin
      report('logging in');
      t_loginPlayer;
      t_SetangleHigh();
      MakeCompassNorth;
      if (usePrayer = true) then
        startPrayer;
    end;
    if (useCasket) then
      usecaskets;
    if (usePots = true) then
      PotUp;
    fightNPCs;
  until (IsKeydown(113));
end.