Results 1 to 6 of 6

Thread: First Script: Draynor Shrimp Fish/Bank

  1. #1
    Join Date
    Jun 2015
    Posts
    29
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default First Script: Draynor Shrimp Fish/Bank

    Hey everyone! I just wrote my first script today and wanted some feedback! My script uses dtm to fish and bank shrimp in Draynor. It uses srl6 and sps.

    Simba Code:
    //    This Script is designed to fish and bank shrimp in Draynor.
    // However, it can easily be adapted to fish anywhere by changing
    // the mouse click option, and the walking coordinates.
    // Programmed by geekborgel, 21 June 2015



    program DraynorScript;

    {$DEFINE SMART}              // Always have this to load smart
    {$I SRL-6/SRL.simba}         // To load the SRL include files
    {$I SPS/lib/SPS-RS3.Simba}   // To load the SPS include files


    var
      shrimpLoads : Integer;

    procedure walkToFish();
    var
      pathToTrees : TPointArray;
    begin
      if (not isLoggedIn()) then
        exit;

      pathToTrees := [Point(155, 197), Point(150, 181), Point(129, 181), Point(119, 208), Point(125, 229), Point(123, 255)];

      if SPS.walkPath(pathToTrees)  then
         minimap.waitPlayerMoving()
      else
        writeLn('Failed to walk to trees.');
    end;

    procedure walkToBank();
    var
      pathToBank : TPointArray;
    begin
      if (not isLoggedIn()) then
        exit;

      pathToBank := [Point(123, 255), Point(125, 229), Point(119, 208), Point(129, 181), Point(150, 181), Point(155, 197)];

      if SPS.walkPath(pathToBank)  then
         minimap.waitPlayerMoving()
      else
        writeLn('Failed to walk to bank.');
    end;

    procedure findFishSpot();
    var
      dtm, x, y, t: integer;
    begin
      if (not isLoggedIn()) then
        exit;
      dtm := DTMFromString('mQwAAAHicY2ZgYLBlZGD4DqSvAOlcIC4A4mggvvbwDUNU9UGGFYt0GfiB8pJQzAXEIkBsxAAGAH+yCYo=');
      t = 0;
      while (not findDTM(dtm, x, y, mainScreen.getBounds())) do
      begin
        if (not isLoggedIn()) then
          exit;
        if (t > 60) then
          exit;
        Wait(250 + random(50));
      end;
      mouse(x, y, 2, 2, MOUSE_MOVE);
      if (not isMouseOverText(['spot'])) then
        mouse(x, y, 7, 7, MOUSE_MOVE);
      if isMouseOverText(['spot']) then
      begin
        fastClick(MOUSE_RIGHT);
        Wait(300 + random(100));
        chooseOption.select(['Net']); // Change to what you would like to fish!
      end;
      Wait(3000 + random(1000));
      freeDTM(dtm);
    end;

    procedure findBanker();
    var
      dtm, x, y: integer;
    begin
      if (not isLoggedIn()) then
        exit;
      dtm := DTMFromString('mbQAAAHicY2VgYChkZGDIBOIMIK4A4h4grgbiJiAuA+JyIG4A4iBnGQZ9TSUw3r5xH0NGhBUDP1A/OmbEgsEAAKkjCdU=');
      if findDTM(dtm, x, y, mainScreen.getBounds()) then
      begin
        mouse(x, y, 2, 2, MOUSE_MOVE);
        if isMouseOverText(['Bank', 'Banker']) then
        begin
          fastClick(MOUSE_RIGHT);
          if chooseOption.select(['Bank']) then
          begin
            Wait(1000 + random(500));
            bankScreen.quickDeposit(QUICK_DEPOSIT_INVENTORY);
            Wait(1000 + random(500));
            bankScreen.close();
          end;
        end;
      end else
      begin
        writeLn('Failed to find banker.');
        freeDTM(dtm);
        exit;
      end;
      freeDTM(dtm);
    end;

    procedure goFishing()
    var
      count: integer;
    begin
      findFishSpot();
      while (not tabBackPack.isFull()) do
      begin
        count := tabBackpack.count();
        wait(7000 + random(3000));
        if (count = tabBackpack.count()) then
          findFishSpot();
        if (not isLoggedIn()) then
          exit;
      end;
    end;

    procedure declarePlayers();
    begin
      setLength(players, 1);
      with players[0] do
      begin
        loginName := 'name';
        password := 'pass';
        isActive := true;
        isMember := false;
      end
      currentPlayer := 0;
    end;


    // main loop
    begin
      clearDebug();               // Clear the debug box
      smartEnableDrawing := true; // So we can draw on SMART
      disableSRLDebug := false;
      smartEnableDrawing := true;
      setupSRL();                   // Load the SRL include files
      SPS.setup('Draynor', RUNESCAPE_SURFACE);  // Setup our map
      declarePlayers();             // Set up your username/pass

      if not isLoggedIn() then             // If player isn't logged in then
      begin
        players[currentPlayer].login();   // Log them in
        exitTreasure();            // Exit treasure hunter
        mainScreen.setZoom(true);
        minimap.clickCompass(false);
        mainScreen.setAngle(MS_ANGLE_HIGH);
      end;

      shrimpLoads := 0;
      while (isLoggedIn()) do
      begin
        walkToBank();
        findBanker();
        walkToFish();
        goFishing();
        shrimpLoads := shrimpLoads + 1;
      end;
      writeLn('Shrimp fished: ',  shrimpLoads * 28, '.');
    end.
    Draynor.png
    Last edited by geek borgel; 06-22-2015 at 03:34 AM.

  2. #2
    Join Date
    Apr 2015
    Location
    FireFox
    Posts
    528
    Mentioned
    10 Post(s)
    Quoted
    227 Post(s)

    Default

    Nice work, will look through later when I can.
    Scripting with ogLib

  3. #3
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Your username and password is still in the script, I'd advise you get that out ASAP.
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  4. #4
    Join Date
    Aug 2014
    Location
    Australia
    Posts
    932
    Mentioned
    53 Post(s)
    Quoted
    495 Post(s)

    Default

    Congrats on writing your first script!


    Feedback:

    As I said in IRC, your code format standards are really up to point, it makes reading your code so much easier.

    What happens here if findFishingSpot() fails for some reason?

    Simba Code:
    procedure goFishing()
    var
      count: integer;
    begin
      findFishSpot();
      while (not tabBackPack.isFull()) do
      begin
        count := tabBackpack.count();
        wait(7000 + random(3000));
        if (count = tabBackpack.count()) then
          findFishSpot();
        if (not isLoggedIn()) then
          exit;
      end;
    end;

    At present, it would still enter the while loop, and since the condition is that the backpack isn't full yet, it's going to repeat forever. There are two fail safes you could use here, but combining them both would be even better:

    1. Turn findFishSpot into a boolean function
    2. Use a timer

    ... like so:

    Simba Code:
    function findFishSpot(): boolean; // Function that returns a boolean
    var
      dtm, x, y, t: integer;
    begin
      if (not isLoggedIn()) then
        exit;
      dtm := DTMFromString('mQwAAAHicY2ZgYLBlZGD4DqSvAOlcIC4A4mggvvbwDUNU9UGGFYt0GfiB8pJQzAXEIkBsxAAGAH+yCYo=');
      t = 0;
      while (not findDTM(dtm, x, y, mainScreen.getBounds())) do
      begin
        if (not isLoggedIn()) then
          exit;
        if (t > 60) then
          exit;
        Wait(250 + random(50));
      end;
      mouse(x, y, 2, 2, MOUSE_MOVE);
      if (not isMouseOverText(['spot'])) then
        mouse(x, y, 7, 7, MOUSE_MOVE);
      if isMouseOverText(['spot']) then
      begin
        fastClick(MOUSE_RIGHT);
        Wait(300 + random(100));
        chooseOption.select(['Net']); // Change to what you would like to fish!
        result := true; // Return a boolean as true
      end else
        result := false; // Return a boolean as false
      Wait(3000 + random(1000));
      freeDTM(dtm);
    end;

    Now that findFishSpot() is a function, we can use it to test whether we should even goFishing() or not, like so:

    Simba Code:
    procedure goFishing()
    var
      count: integer;
    begin
      if findFishSpot() then // Use findFishSpot() to test first, then fish if we can!
      begin
        while (not tabBackPack.isFull()) do
        begin
          count := tabBackpack.count();
          wait(7000 + random(3000));
          if (count = tabBackpack.count()) then
            findFishSpot();
          if (not isLoggedIn()) then
            exit;
      end else
      begin
        writeLn('We failed to find the fishing spot');
        // handle this failure somehow
      end;
    end;

    Finally, in the case that we did find a fishing spot, but the while loop to fish fails for some reason, we want to implement a timer so that the script won't repeat indefinitely:

    Simba Code:
    procedure goFishing()
    var
      count: integer;
      fishTimer: TTimeMarker
    begin
      if findFishSpot() then // Use findFishSpot() to test first, then fish if we can!
      begin
        fishTimer.start();
        while (not tabBackPack.isFull() and fishTimer.getTime() > 10000) do // 10,000ms being 10 seconds, change this to whatever suits best
        begin
          count := tabBackpack.count();
          wait(7000 + random(3000));
          if (count = tabBackpack.count()) then
            findFishSpot();
          if (not isLoggedIn()) then
            exit;
      end else
      begin
        writeLn('We failed to find the fishing spot');
        // handle this failure somehow
      end;
    end;

    Viola!

    After speaking in IRC, I'm sure you'll understand all of that instantly, so I gave a bit more detail for new(er) code writers reading this who might need the ideas.
    Last edited by Incurable; 06-22-2015 at 03:57 AM.



    New to scripting? Procedures & Functions for Beginners
    Do you use your computer at night? Just get f.lux

  5. #5
    Join Date
    Jun 2015
    Posts
    29
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    Your username and password is still in the script, I'd advise you get that out ASAP.
    Oops........fixed Thanks

  6. #6
    Join Date
    Apr 2015
    Location
    FireFox
    Posts
    528
    Mentioned
    10 Post(s)
    Quoted
    227 Post(s)

    Default

    Quote Originally Posted by KeepBotting View Post
    Your username and password is still in the script, I'd advise you get that out ASAP.
    One of the advantages to using a player form
    Scripting with ogLib

Thread Information

Users Browsing this Thread

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

Posting Permissions

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