Results 1 to 4 of 4

Thread: [AeroLib] Grand Exchange

  1. #1
    Join Date
    Dec 2014
    Posts
    70
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default [AeroLib] Grand Exchange

    I made my own.
    Hopefully someone gets some use from this.
    Any questions or feedback, drop them below

    Code:
    {
    ========
    grandExchange
    ========
    AUTHOR: Jayden C
    }
    
    {* Todo; Store slot trades (slot, item, type) for later recall *}
    
    Var
      prMaxLength : Integer := 144;
      zeroPrCol : Integer := 1975338;
      prCol1 : Integer := 1664168;
      prCol2 : Integer := 2130136;
      finCol1 : Integer := 18944;
      finCol2 : Integer := 24320;
      abortCol1 : Integer := 923512;
      abortCol2 : Integer := 143;
      ge_sl1_text : TBox := intToBox(59, 85, 113, 106);
      ge_sl2_text : TBox := intToBox(177, 85, 226, 106);
      ge_sl3_text : TBox := intToBox(294, 85, 344, 106);
      ge_sl4_text : TBox := intToBox(410, 85, 460, 106);
      ge_sl5_text : TBox := intToBox(59, 206, 107, 226);
      ge_sl6_text : TBox := intToBox(177, 206, 226, 226);
      ge_sl7_text : TBox := intToBox(294, 206, 344, 226);
      ge_sl8_text : TBox := intToBox(410, 206, 460, 226);
      ge_sl1 : TBox := intToBox(34, 92, 134, 186);
      ge_sl2 : TBox := intToBox(151, 92, 250, 184);
      ge_sl3 : TBox := intToBox(269, 93, 367, 183);
      ge_sl4 : TBox := intToBox(386, 92, 483, 181);
      ge_sl5 : TBox := intToBox(35, 213, 132, 301);
      ge_sl6 : TBox := intToBox(152, 215, 249, 300);
      ge_sl7 : TBox := intToBox(269, 212, 364, 300);
      ge_sl8 : TBox := intToBox(385, 213, 484, 301);
      ge_sl1_b : TBox := intToBox(44, 131, 70, 166);
      ge_sl2_b : TBox := intToBox(162, 131, 186, 166);
      ge_sl3_b : TBox := intToBox(279, 131, 302, 166);
      ge_sl4_b : TBox := intToBox(396, 131, 419, 166);
      ge_sl5_b : TBox := intToBox(44, 253, 70, 286);
      ge_sl6_b : TBox := intToBox(162, 253, 186, 286);
      ge_sl7_b : TBox := intToBox(279, 253, 302, 286);
      ge_sl8_b : TBox := intToBox(396, 253, 419, 286);
      ge_sl1_pr : TPoint := [32, 163];
      ge_sl2_pr : TPoint := [149, 163];
      ge_sl3_pr : TPoint := [266, 163];
      ge_sl4_pr : TPoint := [383, 163];
      ge_sl5_pr : TPoint := [32, 284];
      ge_sl6_pr : TPoint := [149, 284];
      ge_sl7_pr : TPoint := [266, 284];
      ge_sl8_pr : TPoint := [383, 284];
      ge_coll_all : TBox := intToBox(419, 62, 488, 77);
      ge_coll_i1 : TBox := intToBox(399, 273, 423, 298);
      ge_coll_i2 : TBox := intToBox(452, 276, 476, 297);
      ge_o_all : TBox := intToBox(179, 204, 205, 220);
      ge_o_searchBox : Tbox := intToBox(10, 367, 489, 397);
      ge_o_itemWaitText : TBox := intToBox(191, 61, 360, 83);
      ge_o_custq : TBox := intToBox(222, 204, 248, 221);
      ge_o_custp : TBox := intToBox(378, 203, 403, 220);
      ge_o_minus5 : TBox := intToBox(279, 204, 305, 221);
      ge_o_plus5 : TBox := intToBox(435, 205, 462, 221);
      ge_o_confirm : TBox := intToBox(190, 274, 327, 302);
      ge_o_abort : TBox := intToBox(352, 271, 364, 282);
    
    
    {* == Description ==
      Returns text tbox for the input slot
    *}
    function slotToBox(slot: integer): TBox;
    begin
      if slot = 1 then
        result := ge_sl1_text;
    
      if slot = 2 then
        result := ge_sl2_text;
    
      if slot = 3 then
        result := ge_sl3_text;
    
      if slot = 4 then
        result := ge_sl4_text;
    
      if slot = 5 then
        result := ge_sl5_text;
    
      if slot = 6 then
        result := ge_sl6_text;
    
      if slot = 7 then
        result := ge_sl7_text;
    
      if slot = 8 then
        result := ge_sl8_text;
    end;
    
    
    {* == Description ==
      Returns buy tbox for the input slot
    *}
    function slotToOffer(slot: integer): TBox;
    begin
      if slot = 1 then
        result := ge_sl1_b;
    
      if slot = 2 then
        result := ge_sl2_b;
    
      if slot = 3 then
        result := ge_sl3_b;
    
      if slot = 4 then
        result := ge_sl4_b;
    
      if slot = 5 then
        result := ge_sl5_b;
    
      if slot = 6 then
        result := ge_sl6_b;
    
      if slot = 7 then
        result := ge_sl7_b;
    
      if slot = 8 then
        result := ge_sl8_b;
    end;
    
    
    {* == Description ==
      Returns slot tbox for the input slot
    *}
    function slotToSlot(slot: integer): TBox;
    begin
      if slot = 1 then
        result := ge_sl1;
    
      if slot = 2 then
        result := ge_sl2;
    
      if slot = 3 then
        result := ge_sl3;
    
      if slot = 4 then
        result := ge_sl4;
    
      if slot = 5 then
        result := ge_sl5;
    
      if slot = 6 then
        result := ge_sl6;
    
      if slot = 7 then
        result := ge_sl7;
    
      if slot = 8 then
        result := ge_sl8;
    end;
    
    
    {* == Description ==
      Determines whether a slot is free in the grand exchange and opens an offer if openOffer true.
      To sell an item, set openOffer false and offer item directly from the inventory.
      Use as "isSlotFree(1)". Valid slots: 1-8
    *}
    function isSlotFree(slot: integer): boolean;
    var
      X, Y : integer;
    begin
      if findText(X, Y, 'Empty', 'UpChars07', slotToBox(slot)) then
        result := true;
    end;
    
    
    {* == Description ==
      Returns the total number of free slots
    *}
    function getFreeSlots(): integer
    var
      freeSlots : integer;
    begin
      if isSlotFree(1) then
        freeSlots += 1;
    
      if isSlotFree(2) then
        freeSlots += 1;
    
      if isSlotFree(3) then
        freeSlots += 1;
    
      if isSlotFree(4) then
        freeSlots += 1;
    
      if isSlotFree(5) then
        freeSlots += 1;
    
      if isSlotFree(6) then
        freeSlots += 1;
    
      if isSlotFree(7) then
        freeSlots += 1;
    
      if isSlotFree(8) then
        freeSlots += 1;
    
      result := freeSlots;
    end;
    
    
    {* == Description ==
      Returns true if offer screen is open
    *}
    function offerOpen(): Boolean;
    begin
      result := Interfaces[GEOFFERSCREEN].isVisible();
    end;
    
    
    {* == Description ==
      Returns true if exchange mainscreen is open
    *}
    function exchangeOpen(): Boolean;
    begin
      result := Interfaces[GEMAINSCREEN].isVisible();
    end;
    
    
    {* == Description ==
      Returns true if the 'What would you like to buy?' screen is open
    *}
    function findSearch(): boolean;
    var
      X, Y : integer;
    begin
      result := findColorTolerance(X, Y, 3952988, 502, 466, 504, 468, 10);
    end;
    
    
    {* == Description ==
      Returns true if the item has loaded into to offer screen
    *}
    function itemLoaded(item: string): boolean;
    var
      X, Y : integer;
    begin
      result := findText(X, Y, item, 'UpChars07', ge_o_itemWaitText);
    end;
    
    
    {* == Description ==
      Returns true if the custom price/quantity box has loaded
    *}
    function customLoaded(): boolean;
    var
      X, Y : integer;
    begin
      result := not findColorTolerance(X, Y, 3952989, 504, 427, 506, 429, 10);
    end;
    
    
    {* == Description ==
      Returns true if DTM found in searchbox and clicks it (for ge buy)
    *}
    function findIDTM(dtm: integer): boolean;
    var
      X, Y : integer;
      tempB : TBox;
    begin
      if findDTM(dtm, X, Y, ge_o_searchBox.X1, ge_o_searchBox.Y1, ge_o_searchBox.X2, ge_o_searchBox.Y2) then
      begin
        result := true;
        tempB := intToBox(X-5, Y-5, X+5, Y+5);
        wait(randomRange(500, 1000));
        mouseBox(tempB, MOUSE_LEFT);
      end;
    end;
    
    
    {* == Description ==
      Returns true if DTM found in inventory and clicks it (for ge sell)
    *}
    function findSDTM(dtm: integer): boolean;
    var
      X, Y : integer;
      tempB : TBox;
    begin
      if findDTM(dtm, X, Y, AREA_INV.X1, AREA_INV.Y1, AREA_INV.X2, AREA_INV.Y2) then
      begin
        result := true;
        tempB := intToBox(X-5, Y-5, X+5, Y+5);
        wait(randomRange(500, 1000));
        mouseBox(tempB, MOUSE_LEFT);
      end;
    end;
    
    
    {* == Description ==
      Returns the quantity in the current offer
    *}
    function getCurrentQ(): integer;
    var
      X, Y : integer;
      s : string;
    begin
       s := getTextAtEx(94, 179, 216, 197, 0, 1, 1, 4176127, 0, 'StatChars07');
       result := strToIntDef(GetNumbers(S), 1);
    end;
    
    
    {* == Description ==
      Procedure to sell items to exchange.
      Prices; 'minus5', 'minus10', 'plus5', 'plus10' or 'cust'
      Quantities; 'ALL' or '1'
    *}
    procedure sellItem(item: string; dtm: integer; quantity: string; price: string; custprice: integer);
    var
      X, Y, slot : integer;
    begin
      if (not isLoggedIn) then
        exit;
    
      if getFreeSlots = 0 then
        writeln('No free slots');
    
      if getFreeSlots > 0 then
      begin
        repeat
          wait(100);
        until findSDTM(dtm) or (not isLoggedIn);
    
        repeat
          wait(100);
        until itemLoaded(item) or (not isLoggedIn);
    
        if itemLoaded(item) then
        begin
          if (quantity = '1') and (getCurrentQ > 1) then
          begin
            mouseBox(ge_o_custq, MOUSE_LEFT);
    
            repeat
              wait(100);
            until customLoaded or (not isLoggedIn);
    
            if customLoaded then
              typeSend(quantity, true);
          end;
    
          if (quantity = 'ALL') then
            mouseBox(ge_o_all, MOUSE_LEFT);
    
          if (price = 'minus5') or (price = 'minus10') then
          begin
            if price = 'minus5' then
              mouseBox(ge_o_minus5, MOUSE_LEFT);
    
            if price = 'minus10' then
            begin
              mouseBox(ge_o_minus5, MOUSE_LEFT);
              wait(randomRange(250, 1000));
              mouseBox(ge_o_minus5, MOUSE_LEFT);
            end;
          end;
    
          if (price = 'plus5') or (price = 'plus10') then
          begin
            if price = 'plus5' then
              mouseBox(ge_o_plus5, MOUSE_LEFT);
    
            if price = 'plus10' then
              begin
              mouseBox(ge_o_plus5, MOUSE_LEFT);
              wait(randomRange(250, 1000));
              mouseBox(ge_o_plus5, MOUSE_LEFT);
            end;
          end;
    
          if price = 'cust' then
          begin
            mouseBox(ge_o_custp, MOUSE_LEFT);
    
            repeat
              wait(100);
            until customLoaded or (not isLoggedIn);
    
            if customLoaded then
              typeSend(toStr(custprice), true);
          end;
    
          wait(randomRange(1500, 2500));
          mouseBox(ge_o_confirm, MOUSE_LEFT);
    
          repeat
            wait(100);
          until exchangeOpen or (not isLoggedIn);
        end;
      end;
    end;
    
    
    {* == Description ==
      Procedure to buy items from exchange.
      Prices; 'minus5', 'minus10', 'plus5', 'plus10' or 'cust'
    *}
    procedure buyItem(item: string; dtm: integer; quantity: integer; price: string; custprice: integer);
    var
      X, Y, slot : integer;
    begin
      if (not isLoggedIn) then
        exit;
    
      slot := 1;
    
      if getFreeSlots = 0 then
        writeln('No free slots');
    
      if getFreeSlots > 0 then
      begin
        repeat
          if (not findText(X, Y, 'Empty', 'UpChars07', slotToBox(slot))) then
            inc(slot);
    
          if findText(X, Y, 'Empty', 'UpChars07', slotToBox(slot)) then
          begin
            mouseBox(slotToOffer(slot), MOUSE_LEFT);
    
            repeat
              wait(100);
            until offerOpen or (not isLoggedIn);
          end;
        until offerOpen or (not isLoggedIn);
    
        if offerOpen then
        begin
          repeat
            wait(100);
          until findSearch or (not isLoggedIn);
    
          if findSearch then
          begin
            typeSend(item, false);
    
            repeat
              wait(100);
            until findIDTM(dtm) or (not isLoggedIn);
    
            repeat
              wait(100);
            until itemLoaded(item) or (not isLoggedIn);
    
            if itemLoaded(item) then
            begin
              if quantity > 1 then
              begin
                mouseBox(ge_o_custq, MOUSE_LEFT);
    
                repeat
                  wait(100);
                until customLoaded or (not isLoggedIn);
    
                if customLoaded then
                  typeSend(toStr(quantity), true);
              end;
    
              if (price = 'minus5') or (price = 'minus10') then
              begin
                if price = 'minus5' then
                  mouseBox(ge_o_minus5, MOUSE_LEFT);
    
                if price = 'minus10' then
                begin
                  mouseBox(ge_o_minus5, MOUSE_LEFT);
                  wait(randomRange(250, 1000));
                  mouseBox(ge_o_minus5, MOUSE_LEFT);
                end;
              end;
    
              if (price = 'plus5') or (price = 'plus10') then
              begin
                if price = 'plus5' then
                  mouseBox(ge_o_plus5, MOUSE_LEFT);
    
                if price = 'plus10' then
                begin
                  mouseBox(ge_o_plus5, MOUSE_LEFT);
                  wait(randomRange(250, 1000));
                  mouseBox(ge_o_plus5, MOUSE_LEFT);
                end;
              end;
    
              if price = 'cust' then
              begin
                mouseBox(ge_o_custp, MOUSE_LEFT);
    
                repeat
                  wait(100);
                until customLoaded or (not isLoggedIn);
    
                if customLoaded then
                  typeSend(toStr(custprice), true);
              end;
    
              wait(randomRange(1500, 2500));
              mouseBox(ge_o_confirm, MOUSE_LEFT);
    
              repeat
                wait(100);
              until exchangeOpen or (not isLoggedIn);
            end;
          end;
        end;
      end;
    end;
    
    
    {* == Description ==
      Returns true if collect box 2 is empty
    *}
    function i2empty(): boolean;
    var
      X, Y : integer;
    begin
      result := findColorTolerance(X, Y, 2831936, 464, 286, 466, 288, 5);
    end;
    
    
    {* == Description ==
      Returns true if the offer has been successfully aborted
    *}
    function offerAborted(): boolean;
    var
      X, Y : integer;
    begin
      result := findColorTolerance(X, Y, abortCol2, 359, 306, 361, 308, 10);
    end;
    
    
    {* == Description ==
      Returns true is the abort button colour is found
    *}
    function foundAbort(): boolean;
    var
      X, Y : integer;
    begin
      result := findColorTolerance(X, Y, abortCol1, 358, 268, 360, 270, 10);
    end;
    
    
    {* == Description ==
      Collects items from offer. Use '9' as slot to collect all from ge mainscreen.
    *}
    procedure collectItems(slot: integer; openOffer: boolean);
    var
      X, Y : integer;
    begin
      if slot = 9 then
      begin
        mouseBox(ge_coll_all, MOUSE_LEFT);
        exit;
      end;
    
      if openOffer then
      begin
        mouseBox(slotToSlot(slot), MOUSE_LEFT);
    
        repeat
          wait(100);
        until foundAbort or (not isLoggedIn);
      end;
    
      if (not i2empty) then
      begin
        mouseBox(ge_coll_i2, MOUSE_LEFT);
        moveMouse((X - 50) + random(100), Y - (30 + random(50)));
    
        repeat
          wait(100);
        until i2empty or (not isLoggedIn);
      end;
    
      mouseBox(ge_coll_i1, MOUSE_LEFT);
    
      repeat
        wait(100);
      until exchangeOpen or (not isLoggedIn);
    end;
    
    
    {* == Description ==
      Aborts offer of the slot input
    *}
    procedure abortOffer(slot: integer);
    begin
      mouseBox(slotToSlot(slot), MOUSE_LEFT);
    
      repeat
        wait(100);
      until foundAbort or (not isLoggedIn);
    
      if foundAbort then
      begin
        mouseBox(ge_o_abort, MOUSE_LEFT);
    
        repeat
          wait(100);
        until offerAborted or (not isLoggedIn);
      end;
    
      collectItems(slot, false);
    end;
    
    
    {* == Description ==
      Returns the progress tpoint for the input slot
    *}
    function slotToPr(slot: integer): Tpoint;
    begin
      if slot = 1 then
        result := ge_sl1_pr;
    
      if slot = 2 then
        result := ge_sl2_pr;
    
      if slot = 3 then
        result := ge_sl3_pr;
    
      if slot = 4 then
        result := ge_sl4_pr;
    
      if slot = 5 then
        result := ge_sl5_pr;
    
      if slot = 6 then
        result := ge_sl6_pr;
    
      if slot = 7 then
        result := ge_sl7_pr;
    
      if slot = 8 then
        result := ge_sl8_pr;
    end;
    
    
    {* == Description ==
      Returns true if 'slot' trade is completed
    *}
    function offerCompleted(slot : integer): boolean;
    begin
      if (getColor(slotToPr(slot).X + 50, slotToPr(slot).Y) = finCol1) or (getColor(slotToPr(slot).X + 50, slotToPr(slot).Y) = finCol2) then
        result := true;
    end;
    
    
    {* == Description ==
      Gets the completed % of 'slot' trade
    *}
    function getPercentDone(slot: integer): extended;
    var
      slide : integer;
    begin
      if offerCompleted(slot) then
      begin
        result := 100.0;
        exit;
      end;
    
      if (getColor(slotToPr(slot).X, slotToPr(slot).Y) = zeroPrCol) then
      begin
        result := 0.0;
        exit;
      end;
    
      repeat
        if (getColor(slotToPr(slot).X + slide, slotToPr(slot).Y) = prCol1) or (getColor(slotToPr(slot).X + slide, slotToPr(slot).Y) = prCol2) then
          inc(slide);
      until (getColor(slotToPr(slot).X + slide, slotToPr(slot).Y) <> prCol1) and (getColor(slotToPr(slot).X + slide, slotToPr(slot).Y) <> prCol2) or (slide > 144) or (not isLoggedIn);
    
      if slide > 144 then
        result := 100.0
      else
        result := slide * 0.6944;
    end;

  2. #2
    Join Date
    Sep 2014
    Location
    C:\Simba\
    Posts
    565
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    Man you could've made this with so much less effort if using arrays and some methods like grid and stuff for constant boundaries, oh well nice job nonetheless
    Feel free to ask me any questions, I will do my best to answer them!

    Previously known as YouPee.

  3. #3
    Join Date
    Dec 2014
    Posts
    70
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by Joopi View Post
    Man you could've made this with so much less effort if using arrays and some methods like grid and stuff for constant boundaries, oh well nice job nonetheless
    If only I wasn't noob
    Could you give me an example?

  4. #4
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    I wrote an GrandExchange unit for OSR using SRL 1-2 years ago https://github.com/SRL/SRL/blob/mast...randexch.simba - You might be able to take some from there [even just ideas] - it's fairly simple, but it's using SRL quite extensively so might not be that easy to reuse much of it. Still works tho, might need some tweaks, never really completed it - just did that raw work.

    As for not hard-coding boxes, and instead split some large box into smaller ones.. not really many places in GE where that actually simplifies anything. Pretty much just the main-page (the 4x2 exchange-boxes) that can be simplified with a grid.
    Last edited by slacky; 07-03-2017 at 09:23 AM.
    !No priv. messages please

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
  •