Results 1 to 6 of 6

Thread: Understanding Lape and the SRL-6 Include

  1. #1
    Join Date
    Sep 2015
    Posts
    65
    Mentioned
    7 Post(s)
    Quoted
    20 Post(s)

    Default Understanding Lape and the SRL-6 Include

    I have been browsing through the include as I look to try to make myself a better script writer. I happened to stumble across a couple of lines of code that I do not completely understand. I would love some clarification on what they do and how I could use something similar to them in scripts that I write.

    I was looking through the backpack file and found this guy:

    Simba Code:
    (*
    waitSlotPixelChange
    -------------------

    .. code-block:: pascal

        function TRSTabBackPack.waitSlotPixelChange(slot, waitTime: integer): boolean;

    Returns true if the pixels change in backpack **slot** within **waitTime** . For
    example, a raw fish changing to a cooked fish, or an item being consumed.

    .. note::

        - by Olly & Ashaman88
        - Last Updated: 03 January 2013 by Ashaman88 & Olly

    Example:

    .. code-block:: pascal

       if tabBackpack.waitSlotPixelChange(28, 5000) then
         writeln('Last backpack slot has changed, we''re done!');

    *)

    function TRSTabBackpack.waitSlotPixelChange(slot, waitTime: integer): boolean;
    var
      b: Tbox;
      bmp, bmp1: Integer;
      t: LongWord;
    begin
      if (not self.open()) or (not self.isSlotValid(slot))then
        exit(false);

      b := self.getSlotBox(slot);
      t := (getSystemTime() + waitTime);

      bmp := bitmapFromClient(b);
      bmp1 := createBitmap(b.getWidth(), b.getHeight());

      while (not result) and (t > getSystemTime()) do
      begin
        copyClientToBitmap(bmp1, b.x1, b.y1, b.x2, b.y2);
        result := (calculatePixelShift(bmp, bmp1, [0, 0, (b.getWidth() - 1), (b.getHeight() - 1)]) > 0);

        if result then
          break;

        if (SRL_Events[EVENT_ANTIBAN] <> nil) then
          SRL_Events[EVENT_ANTIBAN]();

        if (not self.open()) then
          break;

        wait(50 + random(50));
      end;

      freeBitmaps([bmp, bmp1]);
    end;

    The parts of this code that I am curious about are:

    Simba Code:
    self._______

    When I see self.open() or anything that involves 'self.' I get a bit confused. I cannot find anything in the include that has anything do to with the word self other than this:

    Simba Code:
    {*
    __init
    ------

    .. code-block:: pascal

        procedure TRSTabBackpack.__init();

    Initializes the TRSTabBackpack.

    .. note::

        - by Olly
        - Last Updated: 15 November 2014 by Mayor

    Example:

    .. code-block:: pascal

        tabBackpack.__init();

    *}

    {$IFNDEF CODEINSIGHT}
    procedure TRSTabBackpack.__init();
    begin
      with self do
      begin
        name := 'RS Backpack tab';
        ID := ID_INTERFACE_TAB_BACKPACK;
        tabIndex := TAB_BACKPACK;
        parentID := -1;
        static := true;
        setBounds(gameTabs.tabArea);

        __slots[0] := grid(5, 6, 33, 31, 42, 36, point(gameTabs.tabArea.x1 + 25, gameTabs.tabArea.y1 + 22));
        __slots[1] := grid(5, 6, 33, 31, 42, 36, point(gameTabs.tabArea.x1 + 25, gameTabs.tabArea.y1 + 50));
      end;
    end;
    {$ENDIF}

    I am assuming that this little snippet declares what 'self' does. Am I right with assuming that?


    Another part that gets me is this:
    Simba Code:
    bmp := bitmapFromClient(b);
      bmp1 := createBitmap(b.getWidth(), b.getHeight());

    What is bitmapFromClient? When I try to open it in SIMBA, it takes me to a 404 error page in my browser.

    And finally:
    Simba Code:
    if (SRL_Events[EVENT_ANTIBAN] <> nil) then
          SRL_Events[EVENT_ANTIBAN]();

    I understand the majority of these two lines but the confusing part is the 'nil'. Does that mean
    'if SRL_Events[EVENT_ANTIBAN] does not equal nothing then..'?

    And it also makes me wonder what SRL_Events is because that is not available in the include (or at least the side search in SIMBA).


    All clarification is greatly appreciated!

  2. #2
    Join Date
    Jun 2014
    Location
    Oklahoma
    Posts
    336
    Mentioned
    22 Post(s)
    Quoted
    231 Post(s)

    Default

    Simba Code:
    if (SRL_Events[EVENT_ANTIBAN] <> nil) then
          SRL_Events[EVENT_ANTIBAN]();

    EVENT_ANTIBAN is a procedure called throughout the include. I believe it is called during Minimap.waitPlayerMoving while its waiting for the player to stop. There are different types of events which are called around the place.

    SRL_Events is an array of procedures. When it compares it to nil its basically seeing if that procedure (SRL_Events[EVENT_ANTIBAN]) exists. By default it does not. So to make it exist we can give it an address of an actual procedure (one you write) so the SRL include can call it for you.

    Long story short:
    Simba Code:
    SRL_Events[EVENT_ANTIBAN] := @WalkingAntiban;
    WalkingAntiban is a procedure in the script I copied this from. The @ symbol gets the address of the WalkingAntiban procedure so SRL_Events[EVENT_ANTIBAN] just points directly to WalkingAntiban anytime its called.

    If you want to know more about function pointers look at this tutorial Kevin made

    What is bitmapFromClient? When I try to open it in SIMBA, it takes me to a 404 error page in my browser.
    BitmapFromClient makes your current client a bitmap. For example if you have smart open that is your client. I'm not sure what you mean about opening it in simba.. or the 404 page. You could try DebugBitmap(BMP); to make it show. IF that is what your trying. You could also look at the bitmap reference for simba you might find something there.

    Then for the self.______ thing

    Simba Code:
    TRSTabBackpack.waitSlotPixelChange(....)
    Notice the TRSTabBackpack. part. Self refers to the TRSTabBackpack. Its like a special word. Like continue; or Exit;.

    So Self.open(); basically means TRSTabBackpack.open(). Self is referring to itself.

    Here is a snippet I made that might help you understand what self is
    Simba Code:
    program a;

    type Rectangle = record
      h : integer;
      w : integer;
    end;

    function Rectangle.Perimeter() : integer  // think i spelled that wrong
    begin
      Result := (Self.h * 2) + (Self.w * 2);
    end;

    var
      rect : Rectangle;

    begin

      rect.h := 2;
      rect.w := 1;

      writeLn(rect.Perimeter());
    end.

    And I think this https://villavu.com/forum/showthread.php?t=113227 is pretty relevant.

    I might have explained some of these poorly. And I might have used some terminology wrong or got something slightly off as I don't 100% understand everything about Lape. But this should answer your questions for scripting purposes at least

  3. #3
    Join Date
    Sep 2014
    Location
    Netherlands
    Posts
    264
    Mentioned
    11 Post(s)
    Quoted
    130 Post(s)

    Default

    Camel, this is a great answer with some helpful links! Thanks, even though I didn't ask the question.

  4. #4
    Join Date
    Sep 2015
    Posts
    65
    Mentioned
    7 Post(s)
    Quoted
    20 Post(s)

    Default

    Quote Originally Posted by Camel View Post
    ...
    Thanks man! It all makes sense! To clarify, the 404 error is what you get in your browser when trying to open up bitmapFromClient in the FunctionsList on the left side of SIMBA:


  5. #5
    Join Date
    Mar 2013
    Posts
    1,010
    Mentioned
    35 Post(s)
    Quoted
    620 Post(s)

    Default

    Quote Originally Posted by SHIELD View Post
    Thanks man! It all makes sense! To clarify, the 404 error is what you get in your browser when trying to open up bitmapFromClient in the FunctionsList on the left side of SIMBA:

    http://docs.villavu.com/simba/script...tmapfromclient
    The URL simba gives has "bitmap" not "bitmaps" for some reason.
    #slack4admin2016
    <slacky> I will build a wall
    <slacky> I will ban reflection and OGL hooking until we know what the hell is going on

  6. #6
    Join Date
    Sep 2015
    Posts
    65
    Mentioned
    7 Post(s)
    Quoted
    20 Post(s)

    Default

    Quote Originally Posted by Hawker View Post
    http://docs.villavu.com/simba/script...tmapfromclient
    The URL simba gives has "bitmap" not "bitmaps" for some reason.
    Thanks! I shoulda checked that out.

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
  •