Results 1 to 11 of 11

Thread: BuySell.scar

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

    Default BuySell.scar

    Before I start, Wouldn't it be more logical to have BuySell.scar in misc?
    I don't see the logic in having it in Skill

    Added
    • ShopItemCoords
    • ExistsShopItem


    Re-did/Modified
    • BuyCoords
    • BuyAmount
    • BuyColor
    • SellCoords
    • Sell (Small edit).


    Deleted
    • Nothing


    This will not outdated anything... afaik BuySell.scar was outdated.

    New BuySell.scar
    SCAR Code:
    //-----------------------------------------------------------------//
    //--               Scar Standard Resource Library                --//
    //--                Buying and Selling routines                  --//
    //-----------------------------------------------------------------//
    //
    // * Function ShopItemCoords(I: Integer): TPoint;                                         // * by N1ke!
    // * Function ExistsShopItem(i: Integer): Boolean;                                        // * by N1ke!
    // * Function BuyCoords(x, y, Amount: Integer): Boolean;                                  // * by RSN re-done by N1ke!
    // * Function BuyAmount(i, Amount: Integer): Boolean;                                     // * by RSN modified by N1ke!
    // * Function BuyColor(UpText: String; Color, Tol, Amount: Integer): Boolean;             // * by RSN Modified by N1ke!
    // * Function SellCoords(x, y, Amount: Integer): boolean;                                 // * by RSN redone by N1ke!
    // * Function Sell(i, Amount: Integer): Boolean;                                          // * RSN small edit by N1ke!
    // * Function  FindItems(color, tol: Integer; text: string; num: Integer): TPointArray;   // * by RSN
    // * Procedure SellItems(Color, Tol, Num, Amount: Integer; Text: string);                 // * by RSN


    {*******************************************************************************
    Function ShopItemCoords(I: Integer): TPoint;
    By: N1ke!
    Description: Results the coords for shop item. (Left to right).
    *******************************************************************************}

    Function ShopItemCoords(I: Integer): TPoint;
    var
      row, col: Integer;
    begin
      row := i div 10;
      col := i - (row * 10) - 1;
      if (col < 0) then
      begin
        col := 9;
        row := row - 1;
      end;
      Result := Point(78+(col * 39), 107+(row * 55));
    end;

    {*******************************************************************************
    Function ExistsShopItem(i: Integer): Boolean;
    By: N1ke!
    Description: Checks if the shop item exists. (Left to right).
    *******************************************************************************}

    function ExistsShopItem(i: Integer): Boolean;
    var
      Cords: TPoint;
      X, Y: Integer;
    begin
      Result := False;
      If Not ShopScreen then
        Exit;
      Cords := ShopItemCoords(I);
      Result := FindColor(X, Y, 65536, Cords.X-20, Cords.Y-20, Cords.X+20, Cords.Y+20);
    end;

    {*******************************************************************************
    Function BuyCoords(x, y, Amount: Integer): Boolean;
    By: RSN re-done by N1ke!
    Description: Buys the specified amout of the Item at x, y
    *******************************************************************************}

    Function BuyCoords(x, y, Amount: Integer): Boolean;
    var
      AmountLeft, xz, yz, iTime: Integer;
      S: String;
    begin
      Result := False;
      If Not ShopScreen then Exit;

      If Amount < 1 then
      begin
        srl_Warn('BuyCoords', 'Invalid amount parameter', warn_Warning);
        Exit;
      end;
      AmountLeft := Amount;

      While AmountLeft > 0 do
      begin
        MMouse(x, y, 5, 5);
        If Not WaitUpText('alue', 300)then
          Exit;
        GetMousePos(xz, yz);
        Mouse(xz, yz, 0, 0, False);

        Case AmountLeft of
          1: S := '1';
          5: S := '5';
          10: S := '10';
          else S := 'Buy X';
        end;
        If Not WaitOption(S, 400)then
          Exit;

        If (S = 'Buy X') then
        begin
          iTime := GetSystemTime + 7000;
          While Not (CountColor(0, 211, 392, 307, 410) > 200) do
            Wait(150+Random(100));

          If AmountLeft > 49999 then
            S := '50000' else S := IntToStr(AmountLeft);

          TypeSend(S);
        end;

        AmountLeft := AmountLeft - StrToInt(S);
      end;
      Result := True;
    end;

    {*******************************************************************************
    Function BuyAmount(i, Amount: Integer): Boolean;
    By: RSN modified by N1ke!
    Description: Buys the specified amount of the Item at assigned row and column
    *******************************************************************************}

    Function BuyAmount(i, Amount: Integer): Boolean;
    var
      Cords: TPoint;
    begin
      Result := False;
      If Not ExistsShopItem(i) then
        Exit;
      Cords := ShopItemCoords(I);
      Result := BuyCoords(Cords.X, Cords.Y, Amount);
    end;

    {*******************************************************************************
    Function BuyColor(UpText: String; Color, Amount: Integer): Boolean;
    By: RSN Modified by N1ke!
    Description: Buys all items with that color
    *******************************************************************************}

    Function BuyColor(UpText: String; Color, Tol, Amount: Integer): Boolean;
    var
      x, y: Integer;
    begin
      Result := False;
      If Not(FindItem(x, y, 'color', Color, 19, 27, 499, 325, [Tol, 4]))then
        Exit;

      Result := BuyCoords(X, Y, Amount);
    end;

    {*******************************************************************************
    Function SellCoords(x, y, Amount: Integer): boolean;
    By: RSN redone by N1ke!
    Description: Sells Item at x, y
    *******************************************************************************}

    Function SellCoords(x, y, Amount: Integer): boolean;
    var
      AmountLeft, xz, yz: Integer;
      S: String;
    begin
      Result := False;
      If Not ShopScreen then Exit;

      If Amount < 1 then
      begin
        srl_Warn('SellCoords', 'Invalid amount parameter', warn_Warning);
        Exit;
      end;
      AmountLeft := Amount;

      While AmountLeft > 0 do
      begin
        MMouse(x, y, 5, 5);
        If Not WaitUpText('alue', 300)then
          Exit;
        GetMousePos(xz, yz);
        Mouse(xz, yz, 0, 0, False);

        Case AmountLeft of
          1..4: S := '1';
          5..9: S := '5';
          10..49: S := '10';
          else
          If (Random(20) = 0)then
            S := '10' else
            S := '50';
        end;
        If Not WaitOption(S, 400)then
          Exit;

        AmountLeft := AmountLeft - StrToInt(S);
      end;
      Result := True;
    end;

    {*******************************************************************************
    Function Sell(i, Amount: Integer): Boolean;
    By: RSN small edit by N1ke!
    Description: Sells Items at specified Inv Slot
    *******************************************************************************}

    Function Sell(i, Amount: Integer): Boolean;
    var
      ItemPoint: TPoint;
    begin
      Result := False;
      if Not (ExistsItem(i)) then
        Exit;
      ItemPoint := ItemCoords(i);
      Result := SellCoords(ItemPoint.x, ItemPoint.y, Amount);
    end;

    {*******************************************************************************
    function FindItemsArray(color, tol: Integer; Text: String; num: Integer): TPointArray;
    By: RSN
    Description: Returns Array of all Coords of that Item
    *******************************************************************************}


    function FindItemsArray(color, tol: Integer; Text: string; num: Integer)
      : TPointArray;
    var
      xi, yi, tx, ty, Used: Integer;
      x, y: Integer;
    begin
      GameTab(4);
      SetArrayLength(Result, 0);
      if (num = 0) then
        num := -1;
      ty := 190;
      tx := 548;
      repeat
        yi := yi + 1;
        ty := ty + 37;
        xi := 0;
        repeat
          xi := xi + 1;
          tx := tx + 41;
          if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
            tol) and (Text <> '')) then
          begin
            MMouse(tx, ty, 2, 2)
              Wait(250);
            if (IsUpText(Text)) then
            begin
              Used := Used + 1;
              SetArrayLength(Result, Used);
              GetMousePos(Result[Used - 1].x, Result[Used - 1].y);
              Wait(150);
            end;
          end
          else
            if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
              tol)) then
            begin
              Used := Used + 1;
              SetArrayLength(Result, Used);
              Result[Used - 1].x := tx;
              Result[Used - 1].y := ty;
            end;
        until (xi = 4) or (Used = num);
        tx := 544;
      until (yi = 7) or (Used = num);
    end;

    {*******************************************************************************
    function FindItems(color, tol: Integer; text: String; num: Integer): TPointArray;
    By: Mutant Squirrle
    Description: Finds Items with color and up text.
    *******************************************************************************}


    function FindItems(color, tol: Integer; text: string; num: Integer):
      TPointArray;
    var
      xi, yi, tx, ty, Used: Integer;
      x, y: Integer;
    begin
      GameTab(4);
      SetArrayLength(Result, 0);
      if (num = 0) then
        num := -1;
      ty := 190;
      tx := 548;
      repeat
        yi := yi + 1;
        ty := ty + 37;
        xi := 0;
        repeat
          xi := xi + 1;
          tx := tx + 41;
          if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
            tol)) then
          begin
            MMouse(tx, ty, 2, 2);
            Wait(250);
            if (IsUpText(text)) then
            begin
              Used := Used + 1;
              SetArrayLength(Result, Used);
              GetMousePos(Result[Used - 1].x, Result[Used - 1].y)
                Wait(150);
            end;
          end;
        until ((xi = 4) or (Used = num));
        tx := 544;
      until ((yi = 7) or (Used = num));
    end;

    {*******************************************************************************
    procedure SellItems(Color, Tol, Num, Amount: Integer; Text: String);
    By: RSN
    Description: Sells items with that color, UpText and Tolerance by
    Amount Specified
    *******************************************************************************}

    procedure SellItems(Color, tol, Num, Amount: Integer; Text: string);
    var
      TP: TPointArray;
      i: Integer;
    begin
      TP := FindItems(Color, tol, Text, Num);
      for i := 0 to GetArrayLength(TP) - 1 do
        SellCoords(TP[i].x, TP[i].y, Amount);
    end;

    Old BuySell.scar
    SCAR Code:
    //-----------------------------------------------------------------//
    //--               Scar Standard Resource Library                --//
    //--                Buying and Selling routines                  --//
    //-----------------------------------------------------------------//

    // * procedure BuyCoords(x, y, amount: Integer);                                          // * by RSN
    // * procedure Buy(i, amount: Integer);                                                   // * by RSN
    // * procedure BuyColor(Color,Amount: Integer);                                           // * by RSN
    // * procedure SellCoords(x, y, amount: Integer);                                         // * by RSN
    // * procedure Sell(i, amount: Integer);                                                  // * by RSN
    // * function  FindItems(color, tol: Integer; text: string; num: Integer): TPointArray;   // * by RSN
    // * procedure SellItems(Color, Tol, Num, Amount: Integer; Text: string);                 // * by RSN

    {*******************************************************************************
    procedure BuyCoords(x, y, amount: Integer);
    By: RSN
    Description: Buys the specified amout of the Item at x, y
    *******************************************************************************}


    procedure BuyCoords(x, y, Amount: Integer); // By RSN
    var
      ix, iy: Integer;
      ToBuy: array[1..3] of Integer;
      Done: array[1..3] of Integer;
    begin
      ix := x;
      iy := y;
      ToBuy[1] := Amount div 10;
      ToBuy[2] := (Amount mod 10) div 5;
      ToBuy[3] := (Amount mod 10) mod 5;
      while (done[1] < tobuy[1]) do
      begin
        Mouse(ix, iy, 3, 3, False);
        Wait(450);
        if (ChooseOption('Buy 10')) then
          Done[1] := done[1] + 1
        else
          Exit;
        Wait(300);
      end;
      while (done[2] < tobuy[2]) do
      begin
        Mouse(ix, iy, 3, 3, False);
        Wait(450);
        if (ChooseOption('Buy 5')) then
          Done[2] := done[2] + 1
        else
          Exit;
        Wait(300);
      end;
      while (done[3] < tobuy[3]) do
      begin
        Mouse(ix, iy, 3, 3, False);
        Wait(450);
        if (ChooseOption('Buy 1')) then
          Done[3] := done[3] + 1
        else
          Exit;
        Wait(300);
      end;
    end;

    {*******************************************************************************
    procedure BuyAmount(i, amount: Integer);
    By: RSN
    Description: Buys the specified amount of the Item at assigned row and column
    *******************************************************************************}


    procedure BuyAmount(i, Amount: Integer);
    var
      ix, iy, row, col: Integer;
    begin
      row := i div 8;
      col := i - (row * 8) - 1;
      if (col < 0) then
      begin
        col := 7;
        row := row - 1;
      end;
      ix := 88 + (col * 47) + Random(7);
      iy := 76 + (row * 47) + Random(7);
      BuyCoords(ix, iy, Amount);
    end;

    {*******************************************************************************
    procedure BuyColor(Color, Amount: Integer);
    By: RSN
    Description: Buys all items with that color
    *******************************************************************************}


    procedure BuyColor(Color, Amount: Integer); // by RSN
    var
      x, y: Integer;
    begin
      while (FindColorSpiral(x, y, Color, 16, 53, 501, 321)) do
        BuyCoords(x, y, Amount);
    end;

    {*******************************************************************************
    procedure SellCoords(x, y, amount: Integer);
    By: RSN
    Description: Sells Item at x, y
    *******************************************************************************}


    procedure SellCoords(x, y, Amount: Integer);
    var
      ix, iy: Integer;
      ToSell: array[1..3] of Integer;
      Done: array[1..3] of Integer;
    begin
      ix := x;
      iy := y;
      ToSell[1] := Amount div 10;
      ToSell[2] := (Amount mod 10) div 5;
      ToSell[3] := (Amount mod 10) mod 5;
      while (done[1] < toSell[1]) do
      begin
        Mouse(ix, iy, 3, 3, False);
        Wait(450);
        if (ChooseOption('Sell 10')) then
          Done[1] := done[1] + 1
        else
          Exit;
        Wait(300);
      end;
      while (done[2] < toSell[2]) do
      begin
        Mouse(ix, iy, 3, 3, False);
        Wait(450);
        if (ChooseOption('Sell 5')) then
          Done[2] := done[2] + 1
        else
          Exit;
        Wait(300);
      end;
      while (done[3] < toSell[3]) do
      begin
        Mouse(ix, iy, 3, 3, False);
        Wait(450);
        if (ChooseOption('Sell 1')) then
          Done[3] := done[3] + 1
        else
          Exit;
      end;
    end;

    {*******************************************************************************
    procedure Sell(i, amount: Integer);
    By: RSN
    Description: Sells Items at specified Inv Slot
    *******************************************************************************}


    procedure Sell(i, Amount: Integer); // by RSN
    var
      ItemPoint: TPoint;
    begin
      if (ExistsItem(i)) then
      begin
        ItemPoint := ItemCoords(i);
        SellCoords(ItemPoint.x, ItemPoint.y, Amount);
      end;
    end;

    {*******************************************************************************
    function FindItemsArray(color, tol: Integer; Text: String; num: Integer): TPointArray;
    By: RSN
    Description: Returns Array of all Coords of that Item
    *******************************************************************************}


    function FindItemsArray(color, tol: Integer; Text: string; num: Integer)
      : TPointArray;
    var
      xi, yi, tx, ty, Used: Integer;
      x, y: Integer;
    begin
      GameTab(4);
      SetArrayLength(Result, 0);
      if (num = 0) then
        num := -1;
      ty := 190;
      tx := 548;
      repeat
        yi := yi + 1;
        ty := ty + 37;
        xi := 0;
        repeat
          xi := xi + 1;
          tx := tx + 41;
          if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
            tol) and (Text <> '')) then
          begin
            MMouse(tx, ty, 2, 2)
              Wait(250);
            if (IsUpText(Text)) then
            begin
              Used := Used + 1;
              SetArrayLength(Result, Used);
              GetMousePos(Result[Used - 1].x, Result[Used - 1].y);
              Wait(150);
            end;
          end
          else
            if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
              tol)) then
            begin
              Used := Used + 1;
              SetArrayLength(Result, Used);
              Result[Used - 1].x := tx;
              Result[Used - 1].y := ty;
            end;
        until (xi = 4) or (Used = num);
        tx := 544;
      until (yi = 7) or (Used = num);
    end;

    {*******************************************************************************
    function FindItems(color, tol: Integer; text: String; num: Integer): TPointArray;
    By: Mutant Squirrle
    Description: Finds Items with color and up text.
    *******************************************************************************}


    function FindItems(color, tol: Integer; text: string; num: Integer):
      TPointArray;
    var
      xi, yi, tx, ty, Used: Integer;
      x, y: Integer;
    begin
      GameTab(4);
      SetArrayLength(Result, 0);
      if (num = 0) then
        num := -1;
      ty := 190;
      tx := 548;
      repeat
        yi := yi + 1;
        ty := ty + 37;
        xi := 0;
        repeat
          xi := xi + 1;
          tx := tx + 41;
          if (FindColorTolerance(x, y, color, tx - 13, ty - 13, tx + 13, ty + 13,
            tol)) then
          begin
            MMouse(tx, ty, 2, 2);
            Wait(250);
            if (IsUpText(text)) then
            begin
              Used := Used + 1;
              SetArrayLength(Result, Used);
              GetMousePos(Result[Used - 1].x, Result[Used - 1].y)
                Wait(150);
            end;
          end;
        until ((xi = 4) or (Used = num));
        tx := 544;
      until ((yi = 7) or (Used = num));
    end;

    {*******************************************************************************
    procedure SellItems(Color, Tol, Num, Amount: Integer; Text: String);
    By: RSN
    Description: Sells items with that color, UpText and Tolerance by
    Amount Specified
    *******************************************************************************}


    procedure SellItems(Color, tol, Num, Amount: Integer; Text: string);
    var
      TP: TPointArray;
      i: Integer;
    begin
      TP := FindItems(Color, tol, Text, Num);
      for i := 0 to GetArrayLength(TP) - 1 do
        SellCoords(TP[i].x, TP[i].y, Amount);
    end;
    Last edited by Naike; 06-30-2009 at 06:53 AM.

  2. #2
    Join Date
    May 2007
    Location
    Sydney, Australia (Faggot Region)
    Posts
    1,465
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    OMG WTF LOL

    Good to see some new stuff


  3. #3
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    I'm like 99 % sure that this will get in SRL ..
    And by the way What's wrong with you with all these updates

    Good job matey!

    ~Home

  4. #4
    Join Date
    Feb 2007
    Location
    Estonia.
    Posts
    1,938
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Home View Post
    I'm like 99 % sure that this will get in SRL ..
    And by the way What's wrong with you with all these updates

    Good job matey!

    ~Home
    SRL dev maybe? ^^
    Really nice job, though.
    ~Eerik~

  5. #5
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Great work N1ke!
    I really like that you contribute as much as you do
    Good scripts too!

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

    Default

    *cough*SRL Dev*cough*
    But really great work

    T~M

  7. #7
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    N1ke, one more thing I forgot to tell you -- please only post the functions and procedures you edited, instead of posting the whole include.

    For readability's sake.

  8. #8
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Or post both, I get lazy sometimes.

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

    Default

    I've been told to post the new/old one so you can use a diff program afterwards?.
    My bad, I do it even more clear next time.

  10. #10
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by N1ke! View Post
    I've been told to post the new/old one so you can use a diff program afterwards?.
    My bad, I do it even more clear next time.
    Its easy to see what you've done when we add it but for other people just looking at the thread it might not be.

  11. #11
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Added.

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
  •