Results 1 to 6 of 6

Thread: A few Grand Exchange things

  1. #1
    Join Date
    Dec 2007
    Location
    Middle of Here and There
    Posts
    417
    Mentioned
    6 Post(s)
    Quoted
    25 Post(s)

    Default A few Grand Exchange things

    I was looking through my pastebin and I found somethings I wrote a long, long time ago (like, 200 days ago. ROFL). I was going to make a perpetual clay softener at the GE, where it would buy more once it got done. I really only got some of the GE things done before I got bored and quit. But, these functions are pretty good!

    Tell me what you think.

    GESlotToTBox

    SCAR Code:
    {*******************************************************************************
    function GESlotToTBox(Slot: Integer): TBox;
    by: ProphesyOfWolf
    Description: Returns a TBox of the Grand Exchange slot "Slot"
    *******************************************************************************}


    function GESlotToTBox(Slot: Integer): TBox;
    var
      I: Integer;
      InitS: TBox;
    begin
      with InitS do
      begin
        x1 := 34;
        y1 := 84;
        x2 := 173;
        y2 := 193;
      end;
      If(Slot = 1) then I := 0;
      If((Slot > 1) and (Slot < 4)) then I := 1;
      If((Slot > 3) and (Slot < 7)) then
      begin
        I := 2;
        with InitS do
        begin
          x1 := 34;
          y1 := 204;
          x2 := 173;
          y2 := 313;
        end;
        If(Slot = 4) then I := 0;
      end;
      If(Slot > 6) then Exit;
      case I of
        0:  begin
              Result.x1 := InitS.x1;
              Result.y1 := InitS.y1;
              Result.x2 := InitS.x2;
              Result.y2 := InitS.y2;
              Exit;
            end;
        1:  begin
              Result.x1 := (InitS.x1 + (Slot - 1) * 156);
              Result.y1 := InitS.y1;
              Result.x2 := (InitS.x2 + (Slot - 1) * 156);
              Result.y2 := InitS.y2;
              Exit;
            end;
        2:  begin
              Result.x1 := (InitS.x1 + (Slot - 4) * 156);
              Result.y1 := InitS.y1;
              Result.x2 := (InitS.x2 + (Slot - 4) * 156);
              Result.y2 := InitS.y2;
              Exit;
            end;
      end;
    end;



    ReturnGESlotState

    SCAR Code:
    function ReturnGESlotState(Slot: Integer): String;  //Returns whether Slot is empty, buying, or selling.
    var
      CTS, I: Integer;
      Opt: String;
      STBox: TBox;
      TPA, TTPA, Matches: TPointArray;
    begin
      for I := 0 to 2 do
      begin
        case I of
          0:  Opt := 'mpty';
          1:  Opt := 'uy';
          2:  Opt := 'ell';
        end;
        TTPA := CreateTPAFromText(Opt, UpChars);
        CTS := GetColorToleranceSpeed;
        STBox := GESlotToTBox(Slot);
        ColorToleranceSpeed(1);
        FindColorsTolerance(TPA, 39372, STBox.x1, STBox.y1, STBox.x2, STBox.y2, 8);
        ColorToleranceSpeed(CTS);
        If FindTPAinTPA(TTPA , TPA, Matches) then
        begin
          If(I = 0) then Result := 'Empty';
          If(I = 1) then Result := 'Buy';
          If(I = 2) then Result := 'Sell';
          Exit;
        end;
      end;
      Result := 'Null';
    end;



    FindFirstEmptyGESlot and ReturnAllGESlots

    SCAR Code:
    function FindFirstEmptyGESlot: Integer;
    var
      I: Integer;
    begin
      for I := 1 to 6 do
      begin
        If (ReturnGESlotState(I) = 'Empty') then
        begin
          Result := I;
          Exit;
        end;
      end;
    end;

    function ReturnAllGESlots: TStringArray;
    var
      I: Integer;
      SArr: TStringArray;
    begin
      SetArrayLength(SArr, 6);
      for I := 0 to 5 do
      begin
        SArr[I] := ReturnGESlotState(I + 1);
      end;
      Result := SArr;
    end;



    DebugWithTheWindow

    SCAR Code:
    {The following procedure was created only for debugging my coordinates with GESlotToTBox. But, it's
    pretty! =D}


    procedure DebugWithTheWindow(TheLength: Integer);
    var
      C, I, DX, DY: Integer;
      TheArrays : Array of TBox;
      TheBox : TBox;
    begin
      DisplayDebugImgWindow((MSX2 - MSX1 + 50), (MSY2 - MSX1 + 50));
      SetArrayLength(TheArrays, TheLength + 1);
      for I := 0 to TheLength do
      begin
        TheBox := GESlotToTBox(I + 1);
        theArrays[I].x1 := TheBox.x1;
        theArrays[I].y1 := TheBox.y1;
        theArrays[I].x2 := TheBox.x2;
        theArrays[I].y2 := TheBox.y2;
      end;
      for I := 0 to High(theArrays) do
      begin
        C := BitmapFromString(1, 1, IntToStr(randomrange(100000, 1000000)));
        GetBitmapSize(C, DX, DY);
        CopyCanvas(GetBitmapCanvas(C), GetDebugCanvas, 0, 0, DX, DY, theArrays[I].x1, theArrays[I].y1, theArrays[I].x2, theArrays[I].y2);
      end;
    end;


    Then I made one for counting things in the bank. It's certainly.. Creative?


    ITEMCOUNTINBANK

    SCAR Code:
    {*******************************************************************************
    function ItemCountInBank(Item: Integer): Integer;
    by: ProphesyOfWolf (number grabbing by munk)
    Description: Finds an object in the bank using a DTM (Item). Once it finds it, it compares
    it with a TBox of all the bank slots to find which one it's in. From there, it counts the number
    of the item in that slot.
    *******************************************************************************}


    function ItemCountInBank(Item: Integer): Integer;
    var
      cx, cy, I: Integer;
      Slot, TextBox: TBox;
      Cols : TIntegerArray;
      TPA : TPointArray;
      Str: String;
    begin
      If(not(LoggedIn)) then Exit;
      If(not(BankScreen)) then Exit;
      If(not(DTMRotated(Item, cx, cy, MSX1, MSY1, MSX2, MSY2))) then
      begin
        Result := 0;
        WriteLN('ItemCountInBank could not find the DTM of the item. Either it was invalid or there are none~');
        FreeDTM(Item);
        Exit;
      end;
      If(DTMRotated(Item, cx, cy, MSX1, MSY1, MSX2, MSY2)) then
      begin
        FreeDTM(Item);
        for I := 1 to 50 do
        begin
          If(not(BankScreen)) then Exit;
          If(not(LoggedIn)) then Exit;
          Slot := BankIndexToMSBox(I);
          If(IntInBox(cx, cy, Slot)) then
          begin
            TheSlot := I;
            Break;
          end;
        end;
        Cols:=[65535,16777215,8453888];
        Slot := BankIndexToMSBox(TheSlot);
        for I := Low(Cols) to High(Cols) do
        begin
          FindColorsTolerance(TPA, Cols[i], Slot.x1, Slot.y1, Slot.x2, Slot.y2, 0);
          if (Length(TPA) < 1) then continue;
          TextBox := GetTPABounds(TPA);
          Str := Trim(GetTextAtEx(TextBox.x1-2, TextBox.y1-2, 0, StatChars, False, False, 0, 2, Cols[i], 7, True, tr_AlphaNumericChars));
          If Str<>'' then
          begin
            case Uppercase(GetLetters(Str)) of
              'K': Result := StrToInt(TrimLetters(Str)) * 1000;
              'M': Result:= StrToInt(TrimLetters(Str)) * 1000000;
              else Result:= StrToInt(Str);
            end;
          end;
        end;
        If(Str = '') then Result := 1;
        Exit;
      end;
    end;

  2. #2
    Join Date
    May 2007
    Location
    UK
    Posts
    4,007
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    good to see you contributing to srl already.
    I will look through tje code in the morning.
    well done.

    T~M

  3. #3
    Join Date
    Mar 2007
    Location
    <3
    Posts
    2,683
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Look in /SRL/Misc/GrandExchange.scar

    Already been made, But +1 for trying.

  4. #4
    Join Date
    Dec 2007
    Location
    Middle of Here and There
    Posts
    417
    Mentioned
    6 Post(s)
    Quoted
    25 Post(s)

    Default

    'tis what I get for not checking before posting =P. Anyways, this code it rather old, so it's not very crushing =D.

  5. #5
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    I've looked through your functions, the only one with a slightly different use is GetSlotState, however

    // * Function GEIsSpotFree(spot: integer):boolean; // * by Rasta Magician
    // * Function GEFinishedAt(spot: integer): boolean; // * by Rasta Magician

    Can you think of any particular reason for which it'd make a difference to know if you're buying or selling?

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  6. #6
    Join Date
    Dec 2007
    Location
    Middle of Here and There
    Posts
    417
    Mentioned
    6 Post(s)
    Quoted
    25 Post(s)

    Default

    @Rasta: If you were waiting for a hard-to-sell item to sell, or if something just isn't selling at the moment. Knowing the difference between whether a slot is selling or not could be useful.

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
  •