Results 1 to 5 of 5

Thread: [Aerolib] Useful functions

  1. #1
    Join Date
    Jan 2012
    Location
    Sydney, Australia
    Posts
    877
    Mentioned
    12 Post(s)
    Quoted
    368 Post(s)

    Default [Aerolib] Useful functions

    Hi all.

    After some positive feedback from budding color scripters, I have decided to make a tutorial that explains some useful functionality that is built into Aerolib. This tutorial will be an on-going thing as I find content within Aerolib that I believe is useful to new scripters, and of course, that relates to frequently asked questions.

    This tutorial will require some basic knowledge of scripting so you can test out these functions.

    Table of contents:
    1. Mouse and keyboard functions
    2. Global variables
    3. Timing functions
    4. Mini map orbs
    5. Walking



    Before we begin
    When testing our functions, I have always found it best to create a separate script. This allows to test how a function works, and explore its potential without ruining your scripts.
    One thing I will highly recommend is to change your default starting script as this:
    Simba Code:
    program new;
    {$i AeroLib/AeroLib.Simba}

    var


    begin
      InitAL;

    end.
    To do this, copy the above code into a new Simba page, overwriting everything that is already there. Once you have done that, go to file > Save as default.
    What this does is saves this template as your default starting script. Click on the New button and it should create a new tab with this template populated.

    Some of the functions I am going to explain have one or more Overload; functions associated with them. This means that the function can have a variety of different parameters associated, but still have the same function name (ie: HumanMMouse);

    For example:
    Simba Code:
    function WriteThisText(txt: string):boolean;
    begin
      Writeln(txt);
    end;

    function WriteThisText(txt: string; Number: integer):boolean; Overload;
    begin
      writeln(txt);
      writeln(Number);
    end;
    As you can see, both functions share the same function name (WriteThisText), but they output different results. The first function outputs the user-defined text. The second function outputs the user-defined text AND the user-defined number. I will show Aerolib examples throughout this tutorial.

    Mouse and Keyboard Functions
    Ok so lets get into it!
    Aerolib has many input functions included by default. There are different types of mouse movements that target different types of points (tpoints, tboxes etc) and have things like Uptext recognition included.

    I will go through some of the more prominent functions, and how they can be used in your scripts.

    HumanMMouse
    This is one of the core mouse movement functions in Aerolib. It makes a human-like mouse movement to your target tpoint, and allows for randomization o the x & y axis of the point.
    Simba Code:
    function humanMMouse(Pnt: TPoint; ranX, ranY: Integer): Boolean;
    Since this is a function, it is going to output a result to us. This is easily identified by the very last part of the function, the :Boolean. This means that once the function triggers, it will return a true value. If it is unable to trigger, it will return a false value.

    Lets run through the variables required to make this whole.

    • Pnt: Tpoint; - This is the co-ordinates for the mouse to move to. It can be fed into the mouse directly like: Point(120, 130), or it can be in the form of a Tpoint variable (Mypoint := 120, 130, then enter Mypoint into the first arg).
    • ranX, ranY: integer; - These values are to randomize the destination point. If our point was Point(100, 100), and we set ranX and ranY to 5, this means the mouse will move to any tpoint between Point(95, 95) to Point(105, 105). Think of it as a square (because it is).


    Ok now that we know how to fill out the function, lets work on the Runescape world applications of it; how it can be used in game.

    Say we wanted to click on our first inventory slot. The co-ordinates for that slot are 579, 228. Since the area around the point is about 15x15, we can add a bit of randomness on our x and y axis, like so:
    Simba Code:
    HumanMMouse(Point(579, 229), 8, 8);
    This function will move the mouse, all human like, to the first inventory slot with a +/- 8 pixel randomness on the x and y axis. This means it could end up on (575, 223), or (578, 225). Adds more human-like randomness to it.

    Notice the Point(579, 229) where the Tpoint is supposed to go? ToPoint is a function that converts 2 integers into a tpoint. if you were to put the 2 numbers without the Point() function, it would return as invalid: too many parameters, since each comma separates the parameter.
    The same is applicable for ToBox(x1, y1, x2, y2) - converts 4 integers into a Tbox.

    HumanMMouseTxt
    This little gem works exactly the same as HumanMMouse, but has the added benefit of a txt arg. This means that the mouse will move to the predefined point and check the uptext, via an uptext array.
    Lets look at the function.
    Simba Code:
    Function humanMMouseTxt(Pnt: TPoint; ranX, ranY: Integer; TxtArr: TStringArray): Boolean;
    So the args that we need to input are identical to the HumanMMouse function, except for the TxtArr, which I will go through now.

    The TxtArr is a TStringArray. This is an array if different string variables. Think of a book as a TStringArray, and each of the pages is a string. All of the strings are inside of the book, and each of them have a unique number associated to identify what part of the book (array) they are in.
    I will give you a visual example of a TStringArray:
    Simba Code:
    program new;
    {$i AeroLib/AeroLib.Simba}

    var
      MyStringArray:tstringarray;
      NormalString:string;

    begin
      InitAL;
      MyStringArray := ['This', 'is', '5', 'different', 'strings'];
      NormalString  := 'This is only 1 string';

      writeln(MyStringArray);
      writeln(NormalString);

    end.

    Outputs:
    Code:
    [This, is, 5, different, strings]
    This is only 1 string
    Notice the square brackets next to the script and the output? This is required when working with any array (integer, string, tbox, tpoint), as it symbolizes an array.

    Lets see what sort of manipulation we can do with the array:
    Simba Code:
    program new;
    {$i AeroLib/AeroLib.Simba}

    var
      MyStringArray:tstringarray;

    begin
      InitAL;
      MyStringArray := ['This', 'is', '5', 'different', 'strings'];
      writeln(MyStringArray[0]);
      writeln(MyStringArray[1]);
      writeln(MyStringArray[2]);
      writeln(MyStringArray[3]);
      writeln(MyStringArray[4]);

    end.

    Outputs:
    Code:
    This
    is
    5
    different
    strings
    As you can see, I have put a square bracket with a number next to each MyStringArray. This represents the strings place in the array, starting from position 0.

    What this all means is searching for uptext using a string array allows for more accuracy, as you aren't only searching for 1 word, or 1 string of words. You are searching for multiple strings. So lets put this into practice.

    Simba Code:
    HumanMMouseTxt(Point(579, 229), 8, 8, ['Bank', 'ank', 'ooth', 'chest', 'ank booth']);
    This will move the mouse to the randomized point and check the uptext for any of the words I listed between the apostrophes. If at least 1 of them is found, it will return true.

    MissMouse
    This is probably one of my favorite mouse functions. It moves quickly towards the point, not on a trajectory that will land it on the point, but rather above, below or behind, and then quickly move itself to the point.

    This replicates, in my opinion, real human mouse movement when the mouse is traveling a great distance. I use this for a lot of my private scripts as I do a have my scripts move the mouse off of the screen when I don't need to interact with the client.

    This has the exact same arguments as HumanMMouse (pnt, ranX, ranY). Lets see it in action:
    Simba Code:
    MissMouse(Point(579, 229), 8, 8);

    There isn't too much else to explain about MissMouse as we have covered everything you need to know in HumanMMouse.

    FastClick
    There isn't too much to say about this function, only that it is the best function to use when clicking.
    It has a realistic click pattern (based on its wait times etc). It can be used simply as follows:
    Simba Code:
    FastClick(MOUSE_LEFT);
    FastClick(MOUSE_RIGHT);
    That's all there is to it. It won't move your mouse. It won't do anything except for left or right clicking.

    There is another function called FastClickAmount(Amount: integer, which will left click the number of times = to the integer.

    MouseBox
    Mousebox is a great mouse input method for dealing with things like inventories, equipment slots, prayer slots, spell slots etc. Anything with a TBox.
    What Mousebox does is pick a random point within a nominated TBox, move the mouse to the point and then: Stop, left click or right click.

    There are two MouseBox() functions, one being an Overload; function.

    Lets have a look at them.
    Simba Code:
    Procedure mouseBox(x1, y1, x2, y2: Integer; Dist, ClickType: Integer);
    var
      Pnt : TPoint;
    begin
      getMousePos(Pnt.x,Pnt.y);
      Pnt := randomPointBoxEx(Pnt,toBox(x1,y1,x2,y2),Dist);
      missMouse(Pnt, 0, 0);
      wait(randomRange(100,150));
      fastClick(ClickType);
    end;

    Procedure mouseBox(B: TBox; ClickType: Integer); overload;
    var
      Pnt : TPoint;
    begin
      getMousePos(Pnt.x,Pnt.y);
      gaussBox(Pnt.x, Pnt.y, B.X1, B.Y1, B.X2, B.Y2);
      //Pnt := randomPointBoxEx(Pnt,toBox(x1,y1,x2,y2),Dist);
      brakeMMouse(Pnt, 0, 0, True);
      wait(randomRange(100,150));
      fastClick(ClickType);
    end;

    Lets delve into the parameters of the first MouseBox function.

    • x1, y1, x2, y2 - This is the values for our TBox. This counts as 4 individual parameters, as fields require integers, not a TBox type.
    • Dist - Since the function uses randomPointBoxEx to get its point, it needs the leniency on distance. For example, if the mouse is moving from the left of the box, the closest point will be the same y axis as the mouse is currently on, but with a varied x axis. If the closest point of the box is 500, 100, then the distance allows for that 500 to be increased, to click within the box. A good value for this is 10.
    • Clicktype - The click function of the mouse once it has moved. MOUSE_LEFT & MOUSE_RIGHT. MOUSE_MOVE will do nothing after the mouse finishes moving.


    Ok so lets key some values into the function and have a look.
    Simba Code:
    MouseBox(563, 213, 594, 244, 10, MOUSE_LEFT);
    This will pick a random spot, up to 10 pixels within the box, for us to move our mouse and left click.

    It is also noteworthy that this function uses MissMouse to do the mouse movement.

    Now lets look at the Overload Mousebox.
    Simba Code:
    Procedure mouseBox(B: TBox; ClickType: Integer); overload;
    I prefer this function is it s bit simpler, but the mouse movement function it uses is the BreakMMouse function, which is slower than the other functions.
    Lets look at the parameters:
    Simba Code:
    Procedure brakeMMouse(Pnt: TPoint; ranX, ranY: Integer; double: Boolean);
    • b: TBox - The TBox area that we want to click within. You can use a predefined area like InvBox(1), which will return the Tbox of inventory slot 1, or you can use ToBox(563, 213, 594, 244) which will convert the 4 integers into a single TBox type.
    • Clicktype - The click function of the mouse once it has moved. MOUSE_LEFT & MOUSE_RIGHT. MOUSE_MOVE will do nothing after the mouse finishes moving.


    mouseInBox
    This neat little function will check to see if the mouse exists in a specified box. For example, I want to click on inventory slot 1, but I first want to check if my mouse is already in the TBox (or the mouse will move to another point in that box which looks bot like).
    Simba Code:
    if mouseInBox(InvBox(1)) then
      fastclick(MOUSE_LEFT)
    else
      MouseBox(InvBox(1), MOUSE_LEFT);
    This function essentially checks to see if our mouse is in slot 1 (as InvBox(1) returns the Tbox co-ordinates for slot 1), and if so, just simply clicks, and if not, moves the mouse to the box and clicks.

    Keyboard functions
    I will list through these quite simply as they are not a complex thing.
    Simba Code:
    Procedure typeSend(Text: String; Send: Boolean = True);
    This allows you to write messages etc. For example, if you wanted to write in the chat bar, you would type something like.
    Simba Code:
    Procedure typeSend('Hello World', true);
    This will type hello world in the chatbox and send it.

    These next ones aren't Aerolib, but they are helpful.
    Simba Code:
    procedure KeyDown(key: Word);
    procedure KeyUp(key: Word);
    procedure PressKey(key: Word);
    function isKeyDown(key: Word): boolean;

    They act as they sound. Keydown holds a key down, key up unpresses a key, Press key simply presses the key once, IsKeyDown returns true if a specified key is down.

    The key: Word type is actually a number that corresponds to a key. For example 16 = SHIFT. 41 = A. Lets look at an example of checking to see if the shift key is being held down, and if not, hold it down.
    Simba Code:
    if not IsKeyDown(16) then
        KeyDown(16);

    A list of keys can be found here.

    Global variables
    Global variables are variables that have been put into the include by default. These variables include main screen positions, mini map related positions and directions, Tab information etc. Lets go through some common ones and look at how we can implement them into our scripts.

    Main Screen
    The main screen has a few global variables that can be used in your scripts. I will list them below.
    Main Screen Edge Points: MSX1, MSY1, MSX2, MSY2
    Main Screen Centre Point: MSCX, MSCY
    Main Screen Area: Area_MS
    Main Screen Centre Point (Tpoint): MSCP

    The above global variables are pre-defined positions on our screen that represent parts of the main screen. MSX1, MSY1 is the top left point of our interface (4, 4), which MSX2, MSY2 is our bottom right point (515, 337). Here is an example of this used in a function.
    Simba Code:
    if MouseInBox([MSX1, MSY1, MSX2, MSY2]) then
      writeln('Our mouse is in the main screen');

    Another global variable that exists for the main screen is the area_MS TBox. This is exactly the same as MSX1, MSY1, MSX2, MSY2, except that it is a TBox instead of an integer.
    Lets look at the same example below:
    Simba Code:
    if MouseInBox(area_MS) then
      writeln('Our mouse is in the main screen');

    Other constants

    There are other global variables that have been programmed in including:
    • Minimap Edge points (MMX1, MMY1, MMX2, MMY2)
    • Minimap centre point (MMCX, MMCY)
    • Minimap TBox (area_MM)
    • Minimap centre point (MMCP)
    • Inventoy edge points (MIX1, MIY1, MIX2, MIY2)
    • Chat box edge points (MCX1, MCY1, MCX2, MCY2)
    • Bank edge points (MBX1, MBY1, MBX2, MBY2)
    • etc..

    You can find the list of variables in Constants.simba (found in Simba\Includes\AeroLib\core).

    Other constants exist in the file, including tab numbers (that are used with with the GameTab function), minimap directions (N, E, S, W) etc.
    Have a read through the include; there are a heap of useful constants.

    Timing functions
    Timing in scripts is very important. There are lots of ways to keep track of time cycles, some easier and more reliable than others. Aerolib includes a few time keeping functions that you can use locally in a function/procedure, or globally throughout your script.

    waitFunc
    waitFunc is a function that is designed to run another function, wait for it to finish running, and return the result. If the result isn't true, it will try and run it again, until it gets a true boolean, or it runs out of time. This function will only work on functions that return a boolean, where as waitFuncEx will return booleans, strings and integers.

    Let's look at the function:
    Simba Code:
    function WaitFunc(Func: Function: Boolean; WaitPerLoop, MaxTime: Integer): Boolean;
    Let's break down the variables:
    • Func: Function: Boolean - This is the function that we will be running within the waitFunc function.
    • WaitPeLoop: integer - This is the amount of times we wait until we run the function again.
    • MaxTime: integer - This is the maximum time we attempt to get a true result before we return a false result.
    • :Boolean - the result of the waitFunc function.

    Here is an example of the function being used:
    Simba Code:
    Procedure OpenBank;
    begin
      HumanMMouse(BankPoint, 0, 0);
      Fastclick(MOUSE_LEFT);
      if waitfunc(IsBankOpen, 300, 3000) then
        writeln('Our bank screen is open')
      else
        writeln('Our bank screen isnt open');
    end;
    As you can see, when we click the bank point, we execute the waitFunc function in an attempt to see if the bank screen is open (IsBankOpen function). We check ever 300ms, for a maximum time of 3000ms. If isBankOpen returns a true result, waitFunc matches that result and we proceed with the script. If the waitFunc maxtime is exceeded, it will return a false result.

    waitFindDTMEx
    This one is pretty self explanatory; it attempts to find a DTM in the area specified, until it runs out of time. It also returns the co-ordinates of the DTM. Let's look at the function:
    Simba Code:
    function waitFindDTM(DTM: integer; var x, y: integer; Area: TBox; WaitPerLoop, MaxTime: integer): boolean;
    The variables:
    • DTM:integer - The DTM that you are attempting to find.
    • Var x, y: integer - the co-ordinates that the function will store the DTM location into, if it is found.
    • Area: TBox - the area that we will be searching for the DTM in.
    • WaitPerLoop: integer - The length of time we spend trying to find the DTM befor we try again.
    • MaxTime: integer - the maximum amount of time that we spend trying to find the DTM, returning a false boolean on a failed result.
    • :boolean - the true/false result of the function.

    Lets look at a proper example;
    Simba Code:
    Procedure FindTheThing;
    var
      x, y: integer;
    begin
      if WaitFindDTM(SymbolDTM, x, y, Area_MS, 300, 3000) then
        writeln('Found that dan symbol!')
      else
        writeln('Didnt find the symbol.');
    end;
    Just to quickly break it down, we are attempting to find our SymbolDTM in the main screen, giving the function 300ms to run each time, for a maximum of 3000ms. If the DTM is found, the function returns true. If it is not found in time (in this case 3000ms), it will return false

    Timer
    The timer is actually a type, as opposed to a function, although it does have a few functions that it uses. It works similarly to items, where you can create multiple timers and manage them individually. Lets look at the Type and functions below.
    Simba Code:
    type Timer = record
      Time, Paused, PausedFor: Int64;
    end;

    Procedure Timer.start();
    Begin
      Self.Time := getSystemTime();
      Self.Paused := 0;
      Self.PausedFor := 0;
    End;

    Procedure Timer.pause();
    begin
      Self.Paused := getSystemTime() - Self.Time;
    end;

    Procedure Timer.Resume();
    begin
      Self.PausedFor := (getSystemTime() - self.Time) - Self.Paused;
    end;

    Function Timer.timeElapsed(): Integer;
    Begin
      Result := (getSystemTime() - Self.Time) - Self.PausedFor;
    End;
    As you can see, the Timer is a type, and the functions are: start, pause, resume, timeElapsed.

    The first thing you to do use a timer is to create a timer variable, just like you would a TItem. Lets call ours OverloadTimer.
    Simba Code:
    var
      OverloadTimer:Timer;
    We then need to tell our timer to start counting.
    Simba Code:
    begin
      InitAL;
      OverloadTimer.start();
    end.
    From here, we can pause it, resume it or check what it's count is at. Let's write a function that reacts when it reaches a certain count.
    Keep in mind that the timer keeps time in milliseconds, like most of Simba.
    Simba Code:
    while (Overloadtimer.TimeElapsed < 10000) do
        wait(100);
    We have create a loop that waits until the timer exceeds 10 seconds (10,000 ms) and then continues.

    Using the function OverloadTimer.Start, after the timer has already started, will reset the timer to 0 and start it again.

    More to come...
    Last edited by Dan the man; 12-20-2017 at 12:02 AM.

  2. #2
    Join Date
    Feb 2012
    Posts
    438
    Mentioned
    1 Post(s)
    Quoted
    16 Post(s)

    Default

    Was just about to read through the whole include to refresh, but it seems you're reading my mind Great write up. Really appreciate it.
    Ski-U-Mah

  3. #3
    Join Date
    Oct 2011
    Location
    England
    Posts
    401
    Mentioned
    10 Post(s)
    Quoted
    176 Post(s)

    Default

    This is great @Dan the man, on a roll!
    Yer a wizard, 'oopi

  4. #4
    Join Date
    Jul 2017
    Posts
    21
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    looks great! Will check this out soon

  5. #5
    Join Date
    Sep 2019
    Posts
    5
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks for the fucntion info, its very helpful in writing scripts

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
  •