Results 1 to 6 of 6

Thread: First Script for a certain BlueStacks App

  1. #1
    Join Date
    Jun 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Post First Script for a certain BlueStacks App

    Hi everyone, this is my first script. If you would, please provide any constructive criticism that will help me grow as a new scripter.
    I have had intermediate experience with writing formulas in Excel for work related activities, the rest I've learned from this thread.
    Im extremely greatful and thankful for all of the tuts that helped me make this script, most notably Yohojo and Coh3n.

    Simba Code:
    program Replay;
    var
    Vmana, NetworkScreen, NetworkYes, OKbutton, Restartbutton, StartBattleScreen, NoMon1,
    x, y, Battlebutton, NoMon2, NoMon3, NoMon4, NoMon5:integer;
    nextround, clicked, Mon1, Mon2, Mon3, Mon4, Mon5:boolean;

    Procedure MonsterCheck;
    begin
     NoMon1 := DTMFromString('m6wAAAHic42ZgYKhnYmCQAtLdQPo5CwPDEyCuA7KFgWIXgHgWEL8G4jNA/BWIfYDYDYi9QHKMDAxzgXgaEO8B8vcB8W4gPgDEvT1VDJOLzBjaM10YVnWHMHgYyzJUJrky9OaaM/z79w+OfU1FGPABLjTMSAJGAgAxQB98');
     NoMon2 := DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2eaMDAyBQOwMxC5AbAvE3kD8BSjnDsTzgewHQPo9EPsAsTcQTwOKTQXio0D2ESDeBcQrgHglEC8D4p7+WoaSKCuGomBThuZUV4bufD+GQwsTgTiJYcOECIYtU8IY4rz0GGK99RicjBUYoj20wTQIMwP1k4sZKcBoAADozyEK');
     NoMon3 := DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2bsYGRguA/FRID4GxAeA+CIQfwHKuQPxfCD7AZB+D8Q+QOwNxNOAYlOB+BADBG8H4qVAvBKKe/prGUqirBiKgk0ZmlNdGbrz/RgOLUwE4iSGDRMiGLZMCWOI89JjiPXWY3AyVmCI9tAG0yDMDNRPLmakAKMBABwBJBQ=');
     NoMon4 := DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2V+AWICRgYEJiFmA+A+Qz80IEXcH4vlA9gMg/R6IfYDYG4inAcWmArEvEPsBsT0QGwOxCRCbA3FPfy1DSZQVQ1GwKUNzqitDd74fw6GFiUCcxLBhQgTDlilhDHFeegyx3noMTsYKDNEe2mAahJmB5pOLGSnAaAAALsgexg==');
     NoMon5 := DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2VWMDAyTgLgNiFuBuA6Ie4H4C1DOHYjnA9kPgPR7IPYBYm8gngYUmwrEgUDsB8T2QGwIxGZQ3NNfy1ASZcVQFGzK0JzqytCd78dwaGEiECcxbJgQwbBlShhDnJceQ6y3HoOTsQJDtIc2mAZhZqD55GJGCjAaAABOmx/c');
     If not (FindDTM(NoMon1, x, y, 0, 0, 1200, 700)) Then
     Wait(100);
     Mon1:=true;
     Wait(100);
     If not (FindDTM(NoMon2, x, y, 0, 0, 1200, 700)) Then;
     Wait(100);
     Mon2:=true;
     Wait(100);
     If not (FindDTM(NoMon3, x, y, 0, 0, 1200, 700)) Then;
     Wait(100);
     Mon3:=true;
     Wait(100);
     If not (FindDTM(NoMon4, x, y, 0, 0, 1200, 700)) Then;
     Wait(100);
     Mon4:=true;
     Wait(100);
     If not (FindDTM(NoMon5, x, y, 0, 0, 1200, 700)) Then;
     Wait(100);
     Mon5:=true;
     Wait(100);
    end;

    Procedure FindBattleScreen;
    begin
     StartbattleScreen := DTMFromString('m1gAAAHic42JgYKhjYmCQBNLPWBgY4oDsWij/KZCvBcS+QNwCxF+AYt5A7AvEbkA8j5GBYSoQTwHi+0D8AohfAnFPfy3DogZ7hr2zIxnaM10Y6pNdGfbOiWXYNSOK4ceFDIa/f/8ynF/my8AKNAMXZiQDIwAAekUcRQ==');
     Wait(500);
     WriteLn('Looking for Start Battle Screen');
     If (FindDTM(StartBattleScreen, x, y, 0, 0, 1200, 700)) Then;
     begin
      WriteLn('Start Battle Screen Found and We Have Enough Energy');
      WriteLn('Checking Monsters');
      repeat
      repeat
      repeat
      repeat
      repeat
      MonsterCheck;
      Until(Mon1=true)
      Until(Mon2=true)
      Until(Mon3=true)
      Until(Mon4=true)
      Until(Mon5=true)
     end;
     WriteLn('All Monsters in Place');
     Wait(75);
     Mon1:=false;
     Wait(75);
     Mon2:=false;
     Wait(75);
     Mon3:=false;
     Wait(75);
     Mon4:=false;
     Wait(75);
     Mon5:=false;
    end;

    Procedure NetScreen;
    var
    x2, y2:integer;
    begin
     NetworkScreen := DTMFromString('mFQEAAHic42VgYGhmYmDgAeJzjAwM74C0PjMDw0Mgfg7EE4B8SaC4ABC/BfLboPx0IN4OxXuAeDcQswPljgDN28kAodOAYslAzA8U5wBiGzUphh8v1zKcmm0Hpo/NcmQ4tDCRoS7Zg2H9rEqGygQ3hoXtMQwr+pMYurLdGfbPS2AAAWYG0gAjGRgFAABsJCIA');     If (FindDTM(NetworkScreen, x, y, 0, 0, 1200, 700)) Then;
     NetworkYes := DTMFromString('mVAEAAHicE2BgYBBkYmDgBGIuIBYGYn4gFgFiSSAWAuJDjAwM+4E4EsiOgao5CuRHQdmbgOz1QLwXqm4nFG8D4jVAPBWIzwPxNCC+DOWD9GwB4otA7KTBzBBhzcfgosXK8O7+EoYAcwEGR3UmhvQANQZ3XTaGJ6cbGba36DCcX+LFsL5KnuH+rkSG80u9GA5MMmfY3KDKwAz0AyWYkUKMDgDNPCNH');
     If (FindDTM(NetworkScreen, x, y, 0, 0, 1250, 700)) Then
     WriteLn('Unstable Network Connection Screen Found');
     repeat
     begin
      If (FindDTM(NetworkYes, x2, y2, 0, 0, 1250, 700)) Then;
      Wait(100+ Random(150));
      MoveMouse(x2, y2);
      Wait(100+ Random(150));
      ClickMouse(x2, y2, 1);
      Wait(200);
      If not (FindDTM(NetworkScreen, x2, y2, 0, 0, 1250, 700)) Then
      Wait(200);
      WriteLn('Clicked Yes button');
      Wait(100);
      Clicked:=true;
     end;
     Wait(100);
     until(clicked = true)
     Wait(100);
     Clicked:=false;
    end;

    Procedure StartBattle;
    var
    x1, y1:integer;
    begin
     Battlebutton := DTMFromString('mAAEAAHic42FgYLBnYWCwBGI3JLwAiB2A+BYzA8MlZgh7JhAvBGIeJgYGdiAWAGJeIBYG4kuMDAzngfgyEKsA+dpArAlVF2XDy/D5yQqG9AA1hh8v1zLcPjeT4cwCd4YHe9MZHu5NZdjZqsuwtVGdYVOtMsOBieYMQOtIwowkYmQAAMh7HTE=');
     WriteLn('Searching for Battle Button');
     If (FindDTM(Battlebutton, x1, y1, 0, 0, 1250, 700)) Then
     WriteLn('Found Battle Button, Attempting to Click');
     repeat
     begin
      Wait(100+ Random(197));
      MoveMouse(x1, y1);
      Wait(100+ Random(150));
      ClickMouse(x1, y1, 1);
      Wait(500);
      If not (FindDTM(Battlebutton, x1, y1, 117, 168, 1250, 700)) Then
      Wait(500);
      Clicked:=true;
     end;
     until(Clicked = true);
     Wait(100);
     WriteLn('Clicked Sart Battle button');
     Wait(100);
     Clicked:=false;
     Wait(2000+random(374));
    end;

    Procedure FindVmana;
    var
    a, b, i:integer;
     begin
      a := random(300+random(900));
      b := random(300+random(400));
      Vmana := DTMFromString('mlwAAAHicY2dgYPBmZGAwBeIwIE6E0vZAbAPE2UCcB8SBQJwOxLVQ+SYgdlv7icFhwweG5IM3GbhDZzEImaQzxJ67y8AVt5oBH2DEg6EAAJInD48=');
      WriteLn('Waiting for Battle to End');
      repeat
      Wait(1000+random(6241));
      If (FindDTM(Vmana, x, y, 289, 329, 358, 391)) Then
       begin
        nextround:=true;
        i := 0;
        Wait(100);
        WriteLn('Battle is Over');
        repeat
        i := i+1;
        Wait(100+ Random(150));
        MoveMouse(a, b);
        Wait(100+ Random(150));
        ClickMouse(a, b, 1);
        Wait(200);
        WriteLn('Advanced Screen');
        until(i = 2)
       end;
      until(nextround = true)
      Wait(100);
      nextround:=false;
      Wait(300);
     end;

    Procedure ClickOKbutton;
     begin
      OKbutton := DTMFromString('mwQAAAHic42RgYGhkYmAwAGI9ID4DxCeBOA+Ie4G4GYhrgVgLiDmB2AmI3aFsTSDWAGIFINYH4mALAYaL8xwYNuQpMazNVWQ4Nc2C4cvTlQxteQ4Mr27NB+IFDMxA+whhRiIwHAAAhXsVAA==');
      begin
      Wait(300+ Random(150))
      WriteLn('Looking For OK button');
      If (FindDTM(OKbutton, x, y, 117, 168, 1200, 700)) Then
      repeat
       begin
       WriteLn('Found OK button');
       Wait(100+ Random(150));
       MoveMouse(x, y);
       Wait(100+ Random(150));
       ClickMouse(x, y, 1);
       Wait(200);
       If not (FindDTM(OKbutton, x, y, 117, 168, 1200, 700)) Then
       WriteLn('Clicked OK button');
       Clicked:=true;
      end;
      until(Clicked = true);
      Clicked:=false;
      Wait(300);
     end;
    end;

    Procedure RestartRun;
    var
    x2, y2:integer;
     begin
      begin
       Restartbutton := DTMFromString('mVAEAAHicE2BgYOhkZGAIhuJyRggfhJcB8UkgfgzFD4FqfZkYGBYB2QFAvA8q3wrEtUDcDcSTgbgXiGuAuAeIG6HiHUCcBMRxQBwNxLlQ3AfEP16uxYm/nUtj+P5iDRiLcnMxiHHxMkS6GTI46IgCsRjDiW4tBkoBI4UYHQAAyS4uag==');
       Wait(100+ Random(150))
       WriteLn('Looking for Replay button')
       If (FindDTM(Restartbutton, x2, y2, 0, 0, 1200, 700)) Then
       WriteLn('Found Replay button');
       repeat
       Wait(100+ Random(150));
       MoveMouse(x2, y2);
       Wait(100+ Random(150));
       ClickMouse(x2, y2, 1);
       Wait(200);
       If not (FindDTM(Restartbutton, x2, y2, 117, 168, 1200, 700)) Then
       WriteLn('Clicked Replay button');
       Clicked:=true;
       until(Clicked = true)
       Clicked:=false;
     end;
    end;

    Procedure FreeDTMs;
    begin
     if DTMExists(OKbutton) = true then
     FreeDTM(OKbutton);
     if DTMExists(Vmana) = true then
     FreeDTM(Vmana);
     if DTMExists(Restartbutton) = true then
     FreeDTM(Restartbutton);
     if DTMExists(NetworkScreen) = true then
     FreeDTM(NetworkScreen);
     if DTMExists(NetworkYes) = true then
     FreeDTM(NetworkYes);
     if DTMExists(StartBattleScreen) = true then
     FreeDTM(StartBattleScreen);
     if DTMExists(Battlebutton) = true then
     FreeDTM(Battlebutton);
     if DTMExists(NoMon1) = true then
     FreeDTM(NoMon1);
     if DTMExists(NoMon2) = true then
     FreeDTM(NoMon2);
     if DTMExists(NoMon3) = true then
     FreeDTM(NoMon3);
     if DTMExists(NoMon4) = true then
     FreeDTM(NoMon4);
     if DTMExists(NoMon5) = true then
     FreeDTM(NoMon5);
     if DTMExists(StartbattleScreen) = true then
     FreeDTM(StartbattleScreen);
    end;

    begin
     Addonterminate('FreeDTMs');
     repeat
     begin
      repeat
      begin
       Wait(299+ Random(5150));
       StartBattle;
       NetScreen;
       FindVmana;
       ClickOKbutton;
       RestartRun;
       Wait(100+random(30))
       FreeDTMs;
      end;
      until(Clicked = true)
     end;
     until (IsKeyDown (114));  //F3 to Stop
    End.

    I feel like I definitely overdid some of the Waits. So I could improve there.
    Also I wanted to use else statements several times but couldn't get them to work for the life of me .
    *Edit: Updated to improve FreeDTM efficiency.
    Last edited by ProJoe; 02-15-2016 at 07:40 AM.

  2. #2
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    Quote Originally Posted by projoe1989 View Post
    Hi everyone, this is my first script. If you would, please provide any constructive criticism that will help me grow as a new scripter.
    I have had intermediate experience with writing formulas in Excel for work related activities, the rest I've learned from this thread.
    Im extremely greatful and thankful for all of the tuts that helped me make this script, most notably Yohojo and Coh3n.

    I feel like I definitely overdid some of the Waits. So I could improve there.
    Also I wanted to use else statements several times but couldn't get them to work for the life of me .
    *Edit: Updated to improve FreeDTM efficiency.
    I changed some stuff around. Basically load your DTMs on start and free them all on terminate. You currently load them and free them all every iteration.

    Simba Code:
    program Replay;

    var
      DTMs: Array[0..11] of Integer;

    type
      Enum_DTM = (NMon1, NMon2, NMon3, NMon4, NMon5, StartBattle, NetworkScrn,
                  NetworkYes, BattleBtn, VMana, OKBtn, RestartBtn);

    procedure LoadDTMs();
    begin
      DTMs[Ord(NMon1)] := DTMFromString('m6wAAAHic42ZgYKhnYmCQAtLdQPo5CwPDEyCuA7KFgWIXgHgWEL8G4jNA/BWIfYDYDYi9QHKMDAxzgXgaEO8B8vcB8W4gPgDEvT1VDJOLzBjaM10YVnWHMHgYyzJUJrky9OaaM/z79w+OfU1FGPABLjTMSAJGAgAxQB98');
      DTMs[Ord(NMon2)] := DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2eaMDAyBQOwMxC5AbAvE3kD8BSjnDsTzgewHQPo9EPsAsTcQTwOKTQXio0D2ESDeBcQrgHglEC8D4p7+WoaSKCuGomBThuZUV4bufD+GQwsTgTiJYcOECIYtU8IY4rz0GGK99RicjBUYoj20wTQIMwP1k4sZKcBoAADozyEK');
      DTMs[Ord(NMon3)] := DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2bsYGRguA/FRID4GxAeA+CIQfwHKuQPxfCD7AZB+D8Q+QOwNxNOAYlOB+BADBG8H4qVAvBKKe/prGUqirBiKgk0ZmlNdGbrz/RgOLUwE4iSGDRMiGLZMCWOI89JjiPXWY3AyVmCI9tAG0yDMDNRPLmakAKMBABwBJBQ=');
      DTMs[Ord(NMon4)] := DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2V+AWICRgYEJiFmA+A+Qz80IEXcH4vlA9gMg/R6IfYDYG4inAcWmArEvEPsBsT0QGwOxCRCbA3FPfy1DSZQVQ1GwKUNzqitDd74fw6GFiUCcxLBhQgTDlilhDHFeegyx3noMTsYKDNEe2mAahJmB5pOLGSnAaAAALsgexg==');
      DTMs[Ord(NMon5)] := DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2VWMDAyTgLgNiFuBuA6Ie4H4C1DOHYjnA9kPgPR7IPYBYm8gngYUmwrEgUDsB8T2QGwIxGZQ3NNfy1ASZcVQFGzK0JzqytCd78dwaGEiECcxbJgQwbBlShhDnJceQ6y3HoOTsQJDtIc2mAZhZqD55GJGCjAaAABOmx/c');
      DTMs[Ord(StartBattle)] := DTMFromString('m1gAAAHic42JgYKhjYmCQBNLPWBgY4oDsWij/KZCvBcS+QNwCxF+AYt5A7AvEbkA8j5GBYSoQTwHi+0D8AohfAnFPfy3DogZ7hr2zIxnaM10Y6pNdGfbOiWXYNSOK4ceFDIa/f/8ynF/my8AKNAMXZiQDIwAAekUcRQ==');
      DTMs[Ord(NetworkScrn)] := DTMFromString('mFQEAAHic42VgYGhmYmDgAeJzjAwM74C0PjMDw0Mgfg7EE4B8SaC4ABC/BfLboPx0IN4OxXuAeDcQswPljgDN28kAodOAYslAzA8U5wBiGzUphh8v1zKcmm0Hpo/NcmQ4tDCRoS7Zg2H9rEqGygQ3hoXtMQwr+pMYurLdGfbPS2AAAWYG0gAjGRgFAABsJCIA');
      DTMs[Ord(NetworkYes)] := DTMFromString('mVAEAAHicE2BgYBBkYmDgBGIuIBYGYn4gFgFiSSAWAuJDjAwM+4E4EsiOgao5CuRHQdmbgOz1QLwXqm4nFG8D4jVAPBWIzwPxNCC+DOWD9GwB4otA7KTBzBBhzcfgosXK8O7+EoYAcwEGR3UmhvQANQZ3XTaGJ6cbGba36DCcX+LFsL5KnuH+rkSG80u9GA5MMmfY3KDKwAz0AyWYkUKMDgDNPCNH');
      DTMs[Ord(BattleBtn)] := DTMFromString('mAAEAAHic42FgYLBnYWCwBGI3JLwAiB2A+BYzA8MlZgh7JhAvBGIeJgYGdiAWAGJeIBYG4kuMDAzngfgyEKsA+dpArAlVF2XDy/D5yQqG9AA1hh8v1zLcPjeT4cwCd4YHe9MZHu5NZdjZqsuwtVGdYVOtMsOBieYMQOtIwowkYmQAAMh7HTE=');
      DTMs[Ord(VMana)] := DTMFromString('mlwAAAHicY2dgYPBmZGAwBeIwIE6E0vZAbAPE2UCcB8SBQJwOxLVQ+SYgdlv7icFhwweG5IM3GbhDZzEImaQzxJ67y8AVt5oBH2DEg6EAAJInD48=');
      DTMs[Ord(OKBtn)] := DTMFromString('mwQAAAHic42RgYGhkYmAwAGI9ID4DxCeBOA+Ie4G4GYhrgVgLiDmB2AmI3aFsTSDWAGIFINYH4mALAYaL8xwYNuQpMazNVWQ4Nc2C4cvTlQxteQ4Mr27NB+IFDMxA+whhRiIwHAAAhXsVAA==');
      DTMs[Ord(RestartBtn)] := DTMFromString('mVAEAAHicE2BgYOhkZGAIhuJyRggfhJcB8UkgfgzFD4FqfZkYGBYB2QFAvA8q3wrEtUDcDcSTgbgXiGuAuAeIG6HiHUCcBMRxQBwNxLlQ3AfEP16uxYm/nUtj+P5iDRiLcnMxiHHxMkS6GTI46IgCsRjDiW4tBkoBI4UYHQAAyS4uag==');
    end;

    function MonsterCheck(): Boolean;
    var
      x, y: Integer;
    begin
      Result := FindDTM(DTMs[Ord(NMon1)], x, y, 0, 0, 1200, 700) and
                FindDTM(DTMs[Ord(NMon2)], x, y, 0, 0, 1200, 700) and
                FindDTM(DTMs[Ord(NMon3)], x, y, 0, 0, 1200, 700) and
                FindDTM(DTMs[Ord(NMon4)], x, y, 0, 0, 1200, 700) and
                FindDTM(DTMs[Ord(NMon5)], x, y, 0, 0, 1200, 700);
    end;

    procedure FindBattleScreen();
    var
      x, y: Integer;
    begin
      WriteLn('Looking for Start Battle Screen');

      if FindDTM(DTMs[Ord(StartBattle)], x, y, 0, 0, 1200, 700) then
      begin
        WriteLn('Start Battle Screen Found and We Have Enough Energy');
        WriteLn('Checking Monsters');

        repeat
          Wait(100);
        until MonsterCheck();

        WriteLn('All Monsters in Place');
      end;
    end;

    procedure NetScreen();
    var
      x, y: Integer;
    begin

      if FindDTM(DTMs[Ord(NetworkScrn)], x, y, 0, 0, 1250, 700) then
      begin
        WriteLn('Unstable Network Connection Screen Found');

        repeat
          if FindDTM(DTMs[Ord(NetworkYes)], x, y, 0, 0, 1250, 700) then
          begin
            Wait(100+ Random(150));
            MoveMouse(x, y);
            Wait(100+ Random(150));
            ClickMouse(x, y, 1);
            Wait(500);
          end;
        until (not FindDTM(DTMs[Ord(NetworkScrn)], x, y, 0, 0, 1250, 700));

        WriteLn('Clicked Yes button');
      end;

    end;

    procedure StartTheBattle();
    var
      x, y: Integer;
    begin
      WriteLn('Searching for Battle Button');

      if FindDTM(DTMs[Ord(BattleBtn)], x, y, 0, 0, 1250, 700) then
      begin
        WriteLn('Found Battle Button, Attempting to Click');

        repeat
          Wait(100+ Random(150));
          MoveMouse(x, y);
          Wait(100+ Random(150));
          ClickMouse(x, y, 1);
          Wait(500);
        until (not FindDTM(DTMs[Ord(BattleBtn)], x, y, 117, 168, 1250, 700));

        WriteLn('Clicked Start Battle button');
      end;

    end;

    procedure FindVMana();
    var
      i, x, y, a, b: Integer;
    begin
      a := random(300+random(900));
      b := random(300+random(400));

      WriteLn('Waiting for Battle to End');

      repeat
        Wait(1000+random(6241));
      until FindDTM(DTMs[Ord(VMana)], x, y, 289, 329, 358, 391);

      WriteLn('Battle is Over');

      for i := 0 to 2 do
      begin
        Wait(100+ Random(150));
        MoveMouse(a, b);
        Wait(100+ Random(150));
        ClickMouse(a, b, 1);
        Wait(200);
        WriteLn('Advanced Screen');
      end;

    end;

    procedure ClickOKbutton();
    var
      x, y: Integer;
    begin
      WriteLn('Looking For OK button');

      if FindDTM(DTMs[Ord(OKBtn)], x, y, 117, 168, 1200, 700) then
      repeat
        WriteLn('Found OK button');
        Wait(100+ Random(150));
        MoveMouse(x, y);
        Wait(100+ Random(150));
        ClickMouse(x, y, 1);
        Wait(200);
      until (not FindDTM(DTMs[Ord(OKBtn)], x, y, 117, 168, 1200, 700));

      WriteLn('Clicked OK button');
    end;

    procedure RestartRun();
    var
      x, y: Integer;
    begin
      WriteLn('Looking for Replay button')

      if FindDTM(DTMs[Ord(RestartBtn)], x, y, 0, 0, 1200, 700) then
      begin
        WriteLn('Found Replay button');

        repeat
          Wait(100+ Random(150));
          MoveMouse(x, y);
          Wait(100+ Random(150));
          ClickMouse(x, y, 1);
          Wait(200);
        until (not FindDTM(DTMs[Ord(RestartBtn)], x, y, 0, 0, 1200, 700));

        WriteLn('Clicked Replay button');
      end;

    end;

    procedure FreeDTMs();
    var
      i: Integer;
    begin
      for i := 0 to High(DTMs) do
        FreeDTM(DTMs[i]);
    end;

    begin
      LoadDTMs();
      AddOnTerminate('FreeDTMs');

      repeat
        Wait(299+ Random(5150));
        StartTheBattle();
        NetScreen();
        FindVMana();
        ClickOKbutton();
        RestartRun();
      until (IsKeyDown (114));  //F3 to Stop
    end.

  3. #3
    Join Date
    Oct 2015
    Location
    Nowhere
    Posts
    134
    Mentioned
    2 Post(s)
    Quoted
    64 Post(s)

    Default

    Waits are definitely overkill. You don't need to wait after assigning a variable for example, only when you want to improve performance or actually wait for something. If you do wait for something, try to dynamically wait, rather than a hard wait. e.g..

    Simba Code:
    while(not(condition))do
        wait(250);

    Here's some more issues I do see:

    • You have far more lines than is necessary, and make no use of arrays
    • The formatting is difficult to read. (for me)
    • You're missing lots of semicolons
    • You're unnecessarily initializing variables more than once
    • When doing a monster check, you're saying to wait only if the findDTM returns false. Did you mean to have it set Mon if false?
    • You're not using functions
    • You don't need begin & end, right inside of repeat..until (NetScreen)
    • Also inside of NetScreen: You're writing a line after finding a DTM.. Instead of running the loop, which I assume was you're intention. You need a begin & end after an if..then statement, otherwise only the very next line will execute.
    • You need to make procedures and functions to prevent typing the same code multiple times. e.g.. A new mouse procedure, and a 'click button' function


    I changed it the script quite a lot before I got bored:

    Simba Code:
    program Replay;
    var
    Vmana, NetworkScreen, NetworkYes, OKbutton, Restartbutton, StartBattleScreen,
    x, y, Battlebutton:integer;
    nextround, clicked:boolean;
    NoMon:TIntegerArray;
    Mon:array of Boolean;
    DTMArray:TIntegerArray;

    procedure initDTMs();
    begin
      NoMon := [DTMFromString('m6wAAAHic42ZgYKhnYmCQAtLdQPo5CwPDEyCuA7KFgWIXgHgWEL8G4jNA/BWIfYDYDYi9QHKMDAxzgXgaEO8B8vcB8W4gPgDEvT1VDJOLzBjaM10YVnWHMHgYyzJUJrky9OaaM/z79w+OfU1FGPABLjTMSAJGAgAxQB98'),
                DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2eaMDAyBQOwMxC5AbAvE3kD8BSjnDsTzgewHQPo9EPsAsTcQTwOKTQXio0D2ESDeBcQrgHglEC8D4p7+WoaSKCuGomBThuZUV4bufD+GQwsTgTiJYcOECIYtU8IY4rz0GGK99RicjBUYoj20wTQIMwP1k4sZKcBoAADozyEK'),
                DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2bsYGRguA/FRID4GxAeA+CIQfwHKuQPxfCD7AZB+D8Q+QOwNxNOAYlOB+BADBG8H4qVAvBKKe/prGUqirBiKgk0ZmlNdGbrz/RgOLUwE4iSGDRMiGLZMCWOI89JjiPXWY3AyVmCI9tAG0yDMDNRPLmakAKMBABwBJBQ='),
                DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2V+AWICRgYEJiFmA+A+Qz80IEXcH4vlA9gMg/R6IfYDYG4inAcWmArEvEPsBsT0QGwOxCRCbA3FPfy1DSZQVQ1GwKUNzqitDd74fw6GFiUCcxLBhQgTDlilhDHFeegyx3noMTsYKDNEe2mAahJmB5pOLGSnAaAAALsgexg=='),
                DTMFromString('mPwEAAHic42dgYKhjYmAoBeJyIBYA8t+xMDCIAunnQPoJEEsA2VWMDAyTgLgNiFuBuA6Ie4H4C1DOHYjnA9kPgPR7IPYBYm8gngYUmwrEgUDsB8T2QGwIxGZQ3NNfy1ASZcVQFGzK0JzqytCd78dwaGEiECcxbJgQwbBlShhDnJceQ6y3HoOTsQJDtIc2mAZhZqD55GJGCjAaAABOmx/c')];

      setLength(Mon, length(NoMon));

      StartbattleScreen := DTMFromString('m1gAAAHic42JgYKhjYmCQBNLPWBgY4oDsWij/KZCvBcS+QNwCxF+AYt5A7AvEbkA8j5GBYSoQTwHi+0D8AohfAnFPfy3DogZ7hr2zIxnaM10Y6pNdGfbOiWXYNSOK4ceFDIa/f/8ynF/my8AKNAMXZiQDIwAAekUcRQ==');
      NetworkScreen := DTMFromString('mFQEAAHic42VgYGhmYmDgAeJzjAwM74C0PjMDw0Mgfg7EE4B8SaC4ABC/BfLboPx0IN4OxXuAeDcQswPljgDN28kAodOAYslAzA8U5wBiGzUphh8v1zKcmm0Hpo/NcmQ4tDCRoS7Zg2H9rEqGygQ3hoXtMQwr+pMYurLdGfbPS2AAAWYG0gAjGRgFAABsJCIA');     If (FindDTM(NetworkScreen, x, y, 0, 0, 1200, 700)) Then;
      NetworkYes := DTMFromString('mVAEAAHicE2BgYBBkYmDgBGIuIBYGYn4gFgFiSSAWAuJDjAwM+4E4EsiOgao5CuRHQdmbgOz1QLwXqm4nFG8D4jVAPBWIzwPxNCC+DOWD9GwB4otA7KTBzBBhzcfgosXK8O7+EoYAcwEGR3UmhvQANQZ3XTaGJ6cbGba36DCcX+LFsL5KnuH+rkSG80u9GA5MMmfY3KDKwAz0AyWYkUKMDgDNPCNH');
      Battlebutton := DTMFromString('mAAEAAHic42FgYLBnYWCwBGI3JLwAiB2A+BYzA8MlZgh7JhAvBGIeJgYGdiAWAGJeIBYG4kuMDAzngfgyEKsA+dpArAlVF2XDy/D5yQqG9AA1hh8v1zLcPjeT4cwCd4YHe9MZHu5NZdjZqsuwtVGdYVOtMsOBieYMQOtIwowkYmQAAMh7HTE=');
      Vmana := DTMFromString('mlwAAAHicY2dgYPBmZGAwBeIwIE6E0vZAbAPE2UCcB8SBQJwOxLVQ+SYgdlv7icFhwweG5IM3GbhDZzEImaQzxJ67y8AVt5oBH2DEg6EAAJInD48=');
      OKbutton := DTMFromString('mwQAAAHic42RgYGhkYmAwAGI9ID4DxCeBOA+Ie4G4GYhrgVgLiDmB2AmI3aFsTSDWAGIFINYH4mALAYaL8xwYNuQpMazNVWQ4Nc2C4cvTlQxteQ4Mr27NB+IFDMxA+whhRiIwHAAAhXsVAA==');
      Restartbutton := DTMFromString('mVAEAAHicE2BgYOhkZGAIhuJyRggfhJcB8UkgfgzFD4FqfZkYGBYB2QFAvA8q3wrEtUDcDcSTgbgXiGuAuAeIG6HiHUCcBMRxQBwNxLlQ3AfEP16uxYm/nUtj+P5iDRiLcnMxiHHxMkS6GTI46IgCsRjDiW4tBkoBI4UYHQAAyS4uag==');

      DTMArray := [NoMon[0], NoMon[1], NoMon[2], NoMon[3], NoMon[4], StartbattleScreen, NetworkScreen, NetworkYes, Battlebutton, Vmana, OKbutton, Restartbutton];
    end;

    procedure mouse(p:TPoint; clickType:Integer);
    begin
      moveMouse(p.x, p.y);
      case clickType of
        0: clickMouse(p.x, p.y, 0);
        1: clickMouse(p.x, p.y, 1);
      end;
    end;

    function clickButton(dtm:Integer):Boolean;
    begin
      Result := false;

      while(findDTM(DTM, x, y, 0, 0, 1200, 700))do
      begin
        mouse(x, y, 1);
        wait(1000);
      end;

      Result := true;
    end;

    function MonsterCheck():Boolean;
    var
      i:Integer;
    begin
      Result := false;

      for i := 0 to High(Mon) do
        if(FindDTM(NoMon[i], x, y, 0, 0, 1200, 700))then
          exit(false);

      Result := true;
    end;

    procedure FindBattleScreen();
    begin
      if(FindDTM(StartBattleScreen, x, y, 0, 0, 1200, 700))then;
      begin
        while(not(MonsterCheck()))do
          wait(250);
        Mon := [false, false, false, false, false];
      end;
    end;

    procedure NetScreen();
    var
    x2, y2:integer;
    begin
      if(FindDTM(NetworkScreen, x, y, 0, 0, 1250, 700))then
        clickButton(networkYes);
    end;

    procedure StartBattle();
    var
    x1, y1:integer;
    begin
      if(FindDTM(Battlebutton, x1, y1, 0, 0, 1250, 700))then
        clickButton(battleButton);
      Wait(2000+random(374)); //I assume you need this wait, shoudl be dynamic though
    end;

    procedure FindVmana();
    var
    a, b, i:integer;
    begin
      a := random(300+random(900));
      b := random(300+random(400));
      WriteLn('Waiting for Battle to End');
      repeat
        Wait(1000+random(6241)); //make dynmatic if there needs to be a wait here
        if(FindDTM(Vmana, x, y, 289, 329, 358, 391))then
        begin
          i := 0;
          WriteLn('Battle is Over');
          repeat
            Inc(i);
            mouse(a, b, 1);
            WriteLn('Advanced Screen');
            wait(500); //wait so mouse isn't spammy/too fast
          until(i = 2)
        end;
      until(FindDTM(Vmana, x, y, 289, 329, 358, 391));
    end;

    procedure ClickOKbutton();
    begin
      if(FindDTM(OKbutton, x, y, 117, 168, 1200, 700))then
        clickButton(OKbutton);
    end;

    procedure RestartRun();
    var
    x2, y2:integer;
    begin
      if(FindDTM(Restartbutton, x2, y2, 0, 0, 1200, 700))then
        clickButton(RestartButton);
    end;

    procedure FreeDTMs();
    begin
     for i := 0 to high(DTMArray) do
      if(DTMExists(DTMArray[i]))then
        FreeDTM(DTMArray[i]);
    end;

    begin
      initDTMs()
      Addonterminate('FreeDTMs');

      repeat
         Wait(299+ Random(5150));
         StartBattle;
         NetScreen;
         FindVmana;
         ClickOKbutton;
         RestartRun;
         Wait(100+random(30));
      until (IsKeyDown (114));  //F3 to Stop

      FreeDTMs;
    end.

  4. #4
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Piggy backing off of what @TSN; said loading all of the DTMs in one place makes it much more easy, you're making this much harder than it has to be

    A few things I noticed were that some of the blocks were not completed, so I don't think your script is working how you want it to work. Lots of things that I think you wanted to be executed on a certain condition but would be executed no matter what. Also included a else example


    Block Example:
    Simba Code:
    program blockExample;

    procedure doSomething;
    begin
      writeln('Called procedure doSomething;');
    end;

    procedure test;
    var
      someBoolean:boolean;
    begin
      {
        by defualt someBoolean is false. There is nothing wrong with setting it so false though
        at the start of the procedure, this is good practice because most programming languages
        require you to initialize the variable
      }

      someBoolean := true; // here we set this to true

      {
        Here I'm going to demonstrate what happens when you don't use a block
      }

      if (someBoolean = false) then
        doSomething(); // it is only going to execute this line if someBoolean is false
        writeln('we did something!'); // this is going to be executed no matter what
      {
        no matter what, it is going to print "we did something!" because there is no block!
        The interpreter will only execute the next line after a if then statement
      }


      {
        now here, we add a block, so now it will not print "we did something!"
        because someBoolean is true. It will execute everything inbetween begin and end if
        someBoolean is false
      }

      if (someBoolean = false) then
      begin
        doSomething();
        writeln('we did something!');
      end;
    end;

    begin
      test;
    end.


    Else example:

    Simba Code:
    program elseExample;

    procedure test;
    var
      someBoolean:boolean;
    begin
      someBoolean := true;

      {
        now here is how if then else works
      }



      {
        The interpreter will check if someBoolean is true, if it is then it will print the line below,
        otherwise it will go to the 'else' statement
      }

      if (someBoolean = true) then
        writeln('someBoolean is true!') // do not add a ; when you have a else statement so the
        // interpreter knows to look for else
      else
        writeln('someBoolean is false!');
    end;

    begin
      test;
    end.


    Block and else combined now:

    Simba Code:
    program block_and_else_example;

    procedure doSomething;
    begin
      writeln('Called procedure doSomething;');
    end;

    procedure test;
    var
      someBoolean:boolean;
    begin
      someBoolean := true;

      {
        now we are going to combine blocks and a if then else statement

        The interpreter will check if someBoolean is true, if it is then it will print the line below,
        otherwise it will go to the 'else' statement
      }

      if (someBoolean = true) then
      begin
        doSomething();
        writeln('someBoolean is true!'); {notice how there is no ; in the statement before the else}
      end else
        writeln('someBoolean is false!');
    end;

    begin
      test;
    end.


    Hope this helped, obviously if you can keep up with the variables in the script as you have(seriously this script is pretty complicated to read lol) you can learn to write code more efficiently, just takes practice

  5. #5
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    @rj;

    don't do this;
    Simba Code:
    if (someBoolean = true) then
    just do this;
    Simba Code:
    if (someBoolean) then   // or
      if (not someBoolean) then

    I don't know how lape deals with this but it's comparing bool to bool. When the expression is a bool in lape you don't need to compare in this case.
    Your code looks like if (true = true) then, the other code is if (true) then.

  6. #6
    Join Date
    Jun 2007
    Posts
    11
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Thanks for all of the replies. I will definitely be improving the script much more and will try to implement everyone's suggestions. Every decent improvement, I will post an update here.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •