Results 1 to 10 of 10

Thread: Trade functions

  1. #1
    Join Date
    Feb 2006
    Posts
    920
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Trade functions

    I was to make a merchanter like stupid3ooo but i got bored, and i have no time to do that, but hey i thought why not give you guys the procedures then:

    note I do not guarantee that all of these procedures work, but the biggest part should

    Trading.scar :

    Code:
    var
      BMPAccept, BMPDecline, MoneyAmount, SellForWhat, SellFor,
      BuyFor, BuyForWhat: Integer;
      Coin, Item: TPoint;
      MarkTimer: array[0..4]of Integer;
      tmpUsername, BuyString, SellString, TradeItem: string;
      Selling, StopTimers: Boolean;
      
    procedure SetupItem(Name: string);
    begin
      TradeItem:= Name;
    end;
      
    procedure SetupBuyPrice(Amount, Mark: Integer);
    begin
      BuyFor:= Amount;
      BuyForWhat:= Mark;
    end;
      
    procedure SetupSellPrice(Amount, Mark: Integer);
    begin
      SellFor:= Amount;
      SellForWhat:= Mark;
    end;
      
    procedure UserTerminateScript;
    begin
      if(IsFunctionKeyDown(1))and
      (IsFunctionKeyDown(3))then
      begin
        WriteLn('User terminated script');
        TerminateScript;
      end;
      SetTimeOut(1, 'UserTerminateScript');
    end;
      
    procedure SetBuyString(Text: string);
    begin
      BuyString:= Text;
    end;
    
    procedure SetSellString(Text: string);
    begin
      SellString:= Text;
    end;
    
    procedure TypeIn2(Text: string);
    var
      i, i2, RandNum: Integer;
      Mistake: Boolean;
    begin
      for i:= 1 to Length(Text) do
      begin
        if(i = Length(Text) div 2)then
          Mistake:= False;
    
        RandNum:= Random(50);
        if(RandNum = 14)and(Mistake <> true)then
        begin
          RandNum:= Random(2);
          Mistake:= true;
    
          if(RandNum = 0)then
          begin
            case Text[i] of
              '`': Text[i]:= '`';
              '1': Text[i]:= '`';
              '2': Text[i]:= '1';
              '3': Text[i]:= '2';
              '4': Text[i]:= '3';
              '5': Text[i]:= '4';
              '6': Text[i]:= '5';
              '7': Text[i]:= '6';
              '8': Text[i]:= '7';
              '9': Text[i]:= '8';
              '0': Text[i]:= '9';
              '-': Text[i]:= '0';
              '=': Text[i]:= '-';
              '~': Text[i]:= '~';
              '!': Text[i]:= '~';
              '@': Text[i]:= '!';
              '#': Text[i]:= '@';
              '$': Text[i]:= '#';
              '%': Text[i]:= '$';
              '^': Text[i]:= '%';
              '&': Text[i]:= '^';
              '*': Text[i]:= '&';
              '(': Text[i]:= '*';
              ')': Text[i]:= '(';
              '_': Text[i]:= ')';
              '+': Text[i]:= '_';
              'q': Text[i]:= 'q';
              'w': Text[i]:= 'q';
              'e': Text[i]:= 'w';
              'r': Text[i]:= 'e';
              't': Text[i]:= 'r';
              'y': Text[i]:= 't';
              'u': Text[i]:= 'y';
              'i': Text[i]:= 'u';
              'o': Text[i]:= 'i';
              'p': Text[i]:= 'o';
              '[': Text[i]:= 'p';
              '{': Text[i]:= 'p';
              ']': Text[i]:= '[';
              '}': Text[i]:= '{';
              '\': Text[i]:= ']';
              '|': Text[i]:= '}';
              'a': Text[i]:= 'a';
              's': Text[i]:= 'a';
              'd': Text[i]:= 's';
              'f': Text[i]:= 'd';
              'g': Text[i]:= 'f';
              'h': Text[i]:= 'g';
              'j': Text[i]:= 'h';
              'k': Text[i]:= 'j';
              'l': Text[i]:= 'k';
              ';': Text[i]:= 'l';
              ':': Text[i]:= 'L';
              chr(39): Text[i]:= ';';
              '"': Text[i]:= ':';
              'z': Text[i]:= 'z';
              'x': Text[i]:= 'z';
              'c': Text[i]:= 'x';
              'v': Text[i]:= 'c';
              'b': Text[i]:= 'v';
              'n': Text[i]:= 'b';
              'm': Text[i]:= 'n';
              ',': Text[i]:= 'm';
              '<': Text[i]:= 'M';
              '.': Text[i]:= ',';
              '>': Text[i]:= '<';
              '/': Text[i]:= '.';
              '?': Text[i]:= '>';
            end;
          end;
          if(RandNum = 1)then
          begin
            case Text[i] of
              '`': Text[i]:= '1';
              '1': Text[i]:= '2';
              '2': Text[i]:= '3';
              '3': Text[i]:= '4';
              '4': Text[i]:= '5';
              '5': Text[i]:= '6';
              '6': Text[i]:= '7';
              '7': Text[i]:= '8';
              '8': Text[i]:= '9';
              '9': Text[i]:= '0';
              '0': Text[i]:= '-';
              '-': Text[i]:= '=';
              '=': Text[i]:= '=';
              '~': Text[i]:= '!';
              '!': Text[i]:= '@';
              '@': Text[i]:= '#';
              '#': Text[i]:= '$';
              '$': Text[i]:= '%';
              '%': Text[i]:= '^';
              '^': Text[i]:= '&';
              '&': Text[i]:= '*';
              '*': Text[i]:= '(';
              '(': Text[i]:= ')';
              ')': Text[i]:= '_';
              '_': Text[i]:= '+';
              '+': Text[i]:= '+';
              'q': Text[i]:= 'w';
              'w': Text[i]:= 'e';
              'e': Text[i]:= 'r';
              'r': Text[i]:= 't';
              't': Text[i]:= 'y';
              'y': Text[i]:= 'u';
              'u': Text[i]:= 'i';
              'i': Text[i]:= 'o';
              'o': Text[i]:= 'p';
              'p': Text[i]:= '[';
              '[': Text[i]:= ']';
              '{': Text[i]:= '}';
              ']': Text[i]:= '\';
              '}': Text[i]:= '|';
              '\': Text[i]:= '\';
              '|': Text[i]:= '|';
              'a': Text[i]:= 's';
              's': Text[i]:= 'd';
              'd': Text[i]:= 'f';
              'f': Text[i]:= 'g';
              'g': Text[i]:= 'h';
              'h': Text[i]:= 'j';
              'j': Text[i]:= 'k';
              'k': Text[i]:= 'l';
              'l': Text[i]:= ';';
              ';': Text[i]:= Chr(39);
              ':': Text[i]:= '"';
              Chr(39): Text[i]:= Chr(39);
              '"': Text[i]:= '"';
              'z': Text[i]:= 'x';
              'x': Text[i]:= 'c';
              'c': Text[i]:= 'v';
              'v': Text[i]:= 'b';
              'b': Text[i]:= 'n';
              'n': Text[i]:= 'm';
              'm': Text[i]:= ',';
              ',': Text[i]:= '.';
              '<': Text[i]:= '>';
              '.': Text[i]:= '/';
              '>': Text[i]:= '?';
              '/': Text[i]:= '/';
              '?': Text[i]:= '?';
            end;
          end;
        end;
    
        case Text[i] of
          '§', '!', '#', '¤', '%', '&', '/', '(', ')', '=',
          '?', ';', ':', '_', '*', '>':
            begin
              SendKeys(Text[i]);
              Wait(100 + Random(50) + Random(50));
            end;
          else
            begin
              KeyDown(GetKeyCode(Text[i]));
              for i2:= 1 to random(4) do
              begin
                Wait(3);
              end;
              KeyUp(GetKeyCode(Text[i]));
              Wait(100 + Random(50) + Random(50));
            end;
        end;
      end;
    end;
    
    function SimilarStrings(TextA, TextB: string; Tol: Integer): Boolean;
    var
      i, trues: Integer;
      Temp: Extended;
    begin
      for i:= 1 to Min(Length(TextA), Length(TextB)) do
      begin
        if TextA[i] = TextB[i] then
          trues:= trues + 1;
      end;
    
      Temp:= trues div Length(TextA);
      Temp:= Temp * 100;
      if(Temp >= Tol)then
        result:= true;
    end;
    
    function IsUpText9(Text: string; Tol: Integer): Boolean;
    var
      s, s2, text2: string;
      temp: extended;
    begin
      s:= getTextAtEx(7, 7, 75, UpChars, True, False, 0, 2, -1, 20, true, tr_NormalChars);
      Text:= Lowercase(Text);
      s:= Lowercase(s);
    
      Text2:= Text;
      repeat
        s2:= s;
        repeat
          if SimilarStrings(Text2, s2, Tol) then
            result:= true;
          delete(s2, 1, 1);
        until(Length(s2) = 1)or(result);
        delete(Text2, 1, 1);
    
        temp:= Length(Text2) div Length(Text);
        temp:= temp * 100;
      until(temp < 30)or(result);
    end;
    
    function IsUpText2(TextA, TextB: string; Tol: Integer): Integer;
    var
      s, s2, text2A, text2B: string;
      temp: extended;
    begin
      s:= getTextAtEx(7, 7, 75, UpChars, True, False, 0, 2, -1, 20, true, tr_NormalChars);
      TextA:= Lowercase(TextA);
      TextB:= Lowercase(TextB);
      s:= Lowercase(s);
    
      Text2A:= TextA;
      repeat
        s2:= s;
        repeat
          if SimilarStrings(Text2A, s2, Tol) then
            result:= 1;
          delete(s2, 1, 1);
        until(Length(s2) = 1)or(result = 1);
        delete(Text2A, 1, 1);
    
        temp:= Length(Text2A) div Length(TextA);
        temp:= temp * 100;
      until(temp < 30)or(result = 1);
      if(result = 1)then
        Exit;
    
      Text2B:= TextB;
      repeat
        s2:= s;
        repeat
          if SimilarStrings(Text2B, s2, Tol) then
            result:= 2;
          delete(s2, 1, 1);
        until(Length(s2) = 1)or(result = 2);
        delete(Text2B, 1, 1);
    
        temp:= Length(Text2B) div Length(TextB);
        temp:= temp * 100;
      until(temp < 30)or(result = 2);
    end;
    
    procedure TypeSellTime;
    begin
      if(not StopTimers)then
      begin
        TypeIn2(SellString + chr(13));
        SetTimeOut(4 + Random(3), 'TypeSellTime');
      end else
        StopTimers:= false;
    end;
    
    procedure TypeBuyTime;
    begin
      if(not StopTimers)then
      begin
        TypeIn2(BuyString + chr(13));
        SetTimeOut(4 + Random(3), 'TypeBuyTime');
      end else
        StopTimers:= false;
    end;
    
    function get2ItemPos(Name, Name2: string; var Col, Row: Integer): Integer;
    var
      ix, iy, tmpx, tmpy, tmpval: Integer;
    begin
      for Row:= 0 to 6 do
      begin
        for Col:= 0 to 3 do
        begin
          if(FindColor(ix, iy, 65536, 565 + 42 * Col, 210 + 36 * Row, 607 + 42 * Col, 246 + 36 * Row))then
          begin
            ix:= 585 + 43 * Col;
            iy:= 220 + 36 * Row;
            MMouse(ix, iy, 5, 5);
            Wait(500 + Random(150));
            tmpval:= 0;
            tmpval:= IsUpText2(Name, Name2, 70);
            if(tmpval = 1)then
            begin
              result:= 1;
              Exit;
            end;
            if(tmpval = 2)then
            begin
              result:= 2;
              tmpx:= Col;
              tmpy:= Row;
            end;
          end;
        end;
      end;
      if(result = 2)then
      begin
        Col:= tmpx;
        Row:= tmpy;
      end;
    end;
    
    function CheckChatForTrade: Boolean;
    begin
      result:= FindColor(x, y, 8388736 {pink}, 20, 360, 230, 430);
      Wait(20);
    end;
    
    function getChatMessage(Number: Integer): string;
    {*edited from RSCI*}
    begin
      x:= 20;
      y:= 429 - (14 * Number);
    
      result:= Trim(GetTextAtEx(x, y, 45, SmallChars, False, False, 0, 2, -1, 40, True, tr_NormalChars));
      Wait(100);
    end;
    
    function AcceptTrade: Boolean;
    var
      x, y: Integer;
    begin
      result:= FindBitmapIn(BMPAccept, x, y, 215, 173, 292, 206);
      Wait(20);
      if(result)then
        Mouse(x, y, 2, 2, true);
    end;
    
    function DeclineTrade: Boolean;
    var
      x, y: Integer;
    begin
      result:= FindBitmapIn(BMPDecline, x, y, 234, 253, 284, 277);
      Wait(20);
      if(result)then
        Mouse(x, y, 2, 2, true);
    end;
    
    function TradeScreen: Boolean;
    var
      x, y: Integer;
    begin
      result:= FindBitmapIn(BMPDecline, x, y, 234, 253, 284, 277);
    end;
    
    function FindInText(TextA, TextB: string): Boolean;
    begin
      result:= (pos(TextB, TextA) > 0);
    end;
    
    function CheckTrades: Boolean;
    var
      i: Integer;
      s: string;
    begin
      if(CheckChatForTrade = true)then
      begin
        for i:= 1 to 5 do
        begin
          s:= getChatMessage(i);
          if(FindInText(s, 'wishes to trade'))then
          begin
            result:= true;
            StopTimers:= true;
            Mouse(100, 438 - (14 * i), 20, 2, true);
            repeat
              Wait(100);
            until(TradeScreen);
            Exit;
          end;
        end;
      end;
    end;
    
    function getMoneyAmount2: Integer;
    var
      s: string;
    begin
      s:= GetTextAtEx(325, 71, 70, StatChars, True, False, 0, 2, -1, 20, True, tr_NormalChars);
    
      if(s = '')then
      begin
        result:= 0;
        Exit;
      end;
    
      repeat
        if FindInText(s, ' ') then
          delete(s, pos(' ', s), 1);
      until(not FindInText(s, ' '));
    
      if FindInText(s, 'k') then
      begin
        delete(s, pos('k', s), 1);
        result:= StrToInt(s);
        result:= result * 1000;
        Exit;
      end;
      if FindInText(s, 'M') then
      begin
        delete(s, pos('M', s), 1);
        result:= StrToInt(s);
        result:= result * 1000000;
        Exit;
      end;
      result:= StrToInt(s);
    end;
    
    procedure MarkTime2(Number: Integer);
    begin
      MarkTimer[Number]:= GetSystemTime div 1000;
    end;
    
    function CheckTime2(Number: Integer): Integer;
    begin
      result:= (GetSystemTime div 1000) - MarkTimer[Number];
    end;
    
    function getOffer: Boolean;
    var
      tmpMoney, MyMoney: Integer;
    begin
      if(not Selling)then
      begin
        case SellForWhat of
          1: MyMoney:= 1;
          2: MyMoney:= 1000;
          3: MyMoney:= 1000000;
        end;
        MyMoney:= MyMoney * BuyFor;
        MarkTime2(0);
        SetTimeOut(20, 'TypeSellTime');
        StopTimers:= true;
        repeat
          tmpMoney:= GetMoneyAmount2;
          Wait(100 + Random(30));
        until(tmpMoney <> 0)or
        (CheckTime2(0) >= 40);
        if(CheckTime2(0) >= 40)then
          DeclineTrade;
        if(tmpMoney >= MyMoney)then
          result:= true;
      end;
    end;
    
    function getMoneyAmount(Tx, Ty: Integer): Integer;
    var
      s: string;
    begin
      s:= GetTextAtEx(570 + (Tx * 42), 212 + (Ty * 36), 70, StatChars, True, False, 0, 2, -1, 20, True, tr_NormalChars);
    
      if(s = '')then
      begin
        WriteLn('Coudn''t retrieve cash amount');
        TerminateScript;
      end;
    
      repeat
        if FindInText(s, ' ') then
          delete(s, pos(' ', s), 1);
      until(not FindInText(s, ' '));
    
      if FindInText(s, 'k') then
      begin
        delete(s, pos('k', s), 1);
        result:= StrToInt(s);
        result:= result * 1000;
        Exit;
      end;
      if FindInText(s, 'M') then
      begin
        delete(s, pos('M', s), 1);
        result:= StrToInt(s);
        result:= result * 1000000;
        Exit;
      end;
      result:= StrToInt(s);
    end;
    
    function getUsername: string;
    {*edited from RSCI*}
    var
      s: string;
      i: Integer;
    begin
      s:= Trim(GetTextAtEx(20, 435, 45, SmallChars, False, False, 0, 2, -1, 20, True, tr_NormalChars));
    
      for i:= 1 to Length(s) do
      begin
        if(s[i] <> ':')then
          result:= result + s[i]
        else
          Exit;
      end;
    end;
    
    procedure LoadTradeBMPS;
    begin
      BMPAccept := BitmapFromString(37, 14, 'z78DA33304006CE48E4700' +
           '2CE44880C3F5F388FFA6ED0FB0E3F6940842EDAA9A1C434671AE4' +
           '474AD4385355E5A8EF68E73BE2D3DBF088BB81F51DAD4B15672A9' +
           '51543A5B41F7E6DA751DF8D74DF010039F94DA0');
      BMPDecline := BitmapFromString(38, 10, 'z78DA733600016724923E' +
           '6060ED721E017EA48F1B46A61F9D078D1F9D89CEBFF8553A93E83' +
           '64A6C74A6389C29773F7E11678ADD36F8FD6840773F3A93A5973E' +
           '7EA45D5A3518C4F1486AEC90179B94E429CACB43080900505CB29' +
           'D');
    end;
    
    procedure SellOrBuy;
    var
      tmpx, tmpy, tmpval: Integer;
    begin
      tmpval:= get2ItemPos(TradeItem, 'Coins', tmpx, tmpy);
      if(tmpval = 1)then
      begin
        Item.x:= tmpx;
        Item.y:= tmpy;
        Selling:= true;
      end
      if(tmpval = 2)then
      begin
        Coin.x:= tmpx;
        Coin.y:= tmpy;
        MoneyAmount:= getMoneyAmount(Coin.x, Coin.y);
        WriteLn('You have this amount of cash:' + IntToStr(MoneyAmount));
        Selling:= false;
      end;
      if(tmpval = 0)then
      begin
        WriteLn('You neither have the selected item or cash,');
        WriteLn('how are you supposed to sell anything?');
        Logout;
        TerminateScript;
      end;
    end;
    
    procedure SetupSRLTrading;
    begin
      LoadTradeBMPS;
      tmpUsername:= getUsername;
      WriteLn('Username "' + tmpUsername + '" fetched');
      Mouse(487, 426, 3, 3, true);
      UserTerminateScript;
    end;

  2. #2
    Join Date
    Feb 2006
    Location
    California-Foster City
    Posts
    742
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    wow, nice lorax uhh... lorax, ur a developer
    The Welcoming Party
    Don't be a Fakawi! Get 25 hours of sleep a day!

  3. #3
    Join Date
    Feb 2006
    Posts
    920
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hehe finally anyway thanks..

  4. #4
    Join Date
    Feb 2006
    Location
    Australia
    Posts
    628
    Mentioned
    15 Post(s)
    Quoted
    105 Post(s)

    Default

    This is great work lorax ^_^

  5. #5
    Join Date
    Feb 2006
    Posts
    920
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thank you, enjoy .. note the GetMoneyAmount2 needs to be fixed and Get2ItemPos could be used for that, also GetOffer won't work with any other than cash

  6. #6
    Join Date
    Feb 2006
    Location
    Australia, NSW.
    Posts
    1,461
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    I remember getting those bitmaps for you, lol.

    They are all excellent <3

  7. #7
    Join Date
    Feb 2006
    Posts
    920
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    hehe yea credit for the bitmaps goes to Kane

  8. #8
    Join Date
    Feb 2006
    Location
    Australia, NSW.
    Posts
    1,461
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Lorax
    hehe yea credit for the bitmaps goes to Kane
    *feels special*..

    I had to force someone to trade me Then i pretended i lagged, ah, funny. <3

  9. #9
    Join Date
    Feb 2006
    Posts
    920
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Haha yea I needed to do something similare a couple of times ..

  10. #10
    Join Date
    Feb 2006
    Location
    New Zealand
    Posts
    485
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice lorax =P

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Lets Trade!
    By Trifonius in forum The Bashing Club / BBQ Pit
    Replies: 1
    Last Post: 01-29-2008, 10:58 PM
  2. Best way to trade?
    By Opal Tasty in forum Bot Information and Spottings
    Replies: 4
    Last Post: 05-30-2007, 10:38 AM
  3. Trade Screen
    By aznrx in forum RS has been updated.
    Replies: 2
    Last Post: 09-05-2006, 04:10 AM

Posting Permissions

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