Results 1 to 11 of 11

Thread: DTMs, Bitmap and Color ~ Naum

  1. #1
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default DTMs, Bitmap and Color ~ Naum

    A tutorial on DTMs, Bitmaps and Color


    Table Of Contents


    I - Intro

    II - DTMs (Search ID: DTM1)
    .....-> How to Make a Unique DTM.
    .....-> How to Make a Static DTM.
    .....-> Using your DTM.

    III - Bitmaps (Search ID: Bit2)
    .....-> How to Make a Bitmap.
    .....-> Using your Bitmap.

    IV - Color (Search ID: Col3)
    .....-> Usage Of Color.
    .....-> Color Constants.
    .....-> Count Color.

    V - End Note.




    I - Intro

    Hello all and welcome to my tutorial on DTMs (Deformable Template Model's), Bitmaps and Color. For DTMs I will cover every thing about them, how they are made and used, how they can be processed.
    For Bitmap's I will cover everything, as with DTMs.
    For Color I will explain the functions: GetColor();, FindColor(Tolerance/Spiral/SpiralTolerance), the color constants clGreen and color counting functions CountColor(); and how they are used .
    So let's begin!



    II - DTMs [(DTM1)]

    Welcome to my first section on DTMs.
    DTMs are mainly used for item finding. They consist of points, one is a mainpoint (there can only be one mainpoint) and the other points are sub-points (you can have as many; but you are recommended to keep them between 5-6).

    There are two types of DTM, one I refer to as a Mask DTM, and another as a Unique DTM. A Unique DTM is a DTM which has little or no tolerance on its mainpoint, thus meaning it is unique to that object, as the mainpoint has a unique color.
    A Mask DTM is a DTM which has a tolerance of 255 or more on it's mainpoint, thus meaning it can be used to find anything which fits the mask, or shape, of the points. The tolerance of 255 means that there is no regard for color hence making it a 'Mask'.


    How to Make a Unique DTM:

    Trust me even a newb can do this, firstly take a screen shot of your RuneScape window, by pressing this button:



    Then go to SCAR > Tools > DTM Editor...
    Once the window is open, click Edit on the toolbar and click paste image. You should have the image of the RuneScape window in the DTM Editor, just for clarification mine looks like this:




    Now click in the middle of an item you want to search for, this is referred to as the mainpoint. I have clicked my item, a cowhide.
    Now the item should have outer edges which are black, click around on them such as:




    Now after that you should have a DTM done and ready, now all you need to do is click File > DTMToText. Then close the window, your DTM should appear in the Debug Box like so:



    This is the end of this section, remember save your DTM as you may need it later on.

    Mine looks like this:
    SCAR Code:
    DTM := DTMFromString('78DA6364626660F8C0C8800C8EECDE0DA661A' +
        '28C2035F751D5C064E16A04816A9E1350C30254F38B809A6F4C0C' +
           '0C1F09A8F90554F384801A5EA05DDFF0AB01005B200AFA');


    Now the next section is on Static DTMs.



    How to Make a Static DTM

    Welcome on how to make a static DTM. the principle is just the same, except you modify it at the end.

    So just to run through (this a modified repeat of before):

    So screen shot of the RuneScape window by pressing the Screen Shot button (stated before).

    Then go to SCAR > Tools > DTM Editor...
    Once the window is open, click Edit on the toolbar and click paste image. You should have the image of the RuneScape window in the DTM Editor, just for clarification mine looks like this:




    Now click in the middle of an item you want to search for, this is referred to as the mainpoint. I have clicked my item, a cowhide. Now the item should have outer edges which are black, click around on them such as:



    Now the Modifying comes in...

    You should have noticed that when you add a subpoint a box in the top right hand corner adds onto it's list. This box keeps a record of the points so you can access them and modify them. So click on the first point (as this will be your mainpoint). However, notice that this mainpoint will have a different color than all the other ones.
    After you have clicked on it, go to the tolerance box and double click in it; then type in '255' or above. Finally press enter.

    I have this:



    Now click in File > DTMToText and you should have a DTM, mine looks like this:
    SCAR Code:
    DTM := DTMFromString('78DA6364626660F8C0C8800C8EECDECDF01F4' +
        '88344FF03012348CD7D543510591809A405816A9E1350C30254F3' +
        '8B809A6F4C0C0C1F09A8F90554F384801A5EA05DDFF0AB0100A50' +
           'E0FF5');

    ^ This will work for all cowhides be they green or yellow, all they need is a black outline of 65536. ^


    Using your DTM.

    Remember DTMs are Integers, that means they must be called as Integer, LongInt or Int64 (If you call it as an Integer it is generally faster for the platform and CPU);

    However, well done on making your DTM, now you must use some procedure and functions to use it. Now, there are 3 main functions in accordance with DTM Loading and Freeing:

    PHP Code:
    function LoadDTM(FileNamestring): Integer;
    Load deformable template model from file
    ^ This will load a DTM from a file so, for example my DTM was where my script is, I would do:
    SCAR Code:
    Begin
      LoadDTM(ScriptPath + 'mydtm.DTM'); //the extension for a DTM is '.DTM'


    PHP Code:
    function DTMFromString(sstring): Integer;
    Load deformable template model from stringStrings can be created in deformable template model editor in menu Tools DTM editor
    ^ This will load, from a string, a DTM, Example:
    SCAR Code:
    Begin
      Str := 'FFOOOFFFOFOFOFOFOF'; //Not real
      TheRealDTM := DTMFromString(Str);
    End;

    You may, or may not, have noticed that when you make a DTM via the DTM Editor; SCAR already includes this.


    PHP Code:
    procedure FreeDTM(DTMInteger);
    Unload deformable template editor
    This procedure is important, you need to free your DTMs from SCAR's memory to avoid lag. You must free your DTMs when they are not needed.
    Example:

    SCAR Code:
    Var DTM : Int64;

    Begin
      DTM := DTMFromString('FOOOOFOFOFOF'); // not real
      If Random(2) = 0 Then
        FreeDTM(DTM); //!!!
      Try
       If FindDTM(DTM, x, y, 0, 0, 700, 700) Then
         WriteLn('DTM Not Freed! :)');
      Except
        WriteLn('DTM freed :)');    
    End.


    -------------------------------

    Now these are the functions in accordance to DTM Finding (note: there are actually 3 functions, one is called FindDTMRotated [Which is what DTMRotated is based on], I will not explain that in this tutorial):

    PHP Code:
    function FindDTM(DTMInteger; var xyIntegerx1y1x2y2Integer): Integer;
    Use 
    DTM to find object on client windowx1y1x2y2 specifies box to search inxy returns coordinates if found.
    Example:
    if(
    FindDTM(rockxy100100500300)) then
      Writeln
    ('I rock'); 
    ^ This is the classic function used for DTM Finding ^, Example:

    SCAR Code:
    If FindDTM(DTM, x, y, 0, 0, 700, 700) Then
      WriteLn('DTM Found');

    FreeDTM(DTM); // remember to free ;)

    PHP Code:
    {*******************************************************************************
    function 
    DTMRotated(DTMInteger; var xyIntegerx1y1x2y2Integer): Boolean;
    ByYakman
    Description
    First looks for a DTM without rotationthen increases the amount
    of rotation around 0 gradually until it finds the DTM
    A bit like the
    ProgressiveTol Bitmap Engines
    .
    *******************************************************************************} 
    This function rotates the DTM, so it could be used for DDTMs. Basically if you are worrying about Inventory finding the function will not aid you. However, the principle behind this is that it will keep rotating the DTM until it finds it. Furthermore, with this function you do not need to specify angles and step's, as this does it for you.

    Example:

    SCAR Code:
    If DTMRotated(DTM, x, y, 0, 0, 700, 700) Then
      WriteLn('DTM Found');

      FreeDTM(DTM); // remember to free ;)


    So to put it all together.

    1. You need your DTM:
    SCAR Code:
    DTM := DTMFromString('78DA6364626660F8C0C8800C8EECDECDF01F4' +
        '88344FF03012348CD7D543510591809A405816A9E1350C30254F3' +
        '8B809A6F4C0C0C1F09A8F90554F384801A5EA05DDFF0AB0100A50' +
        'E0FF5');

    2. You need to load it, so create a variable called DTM:
    SCAR Code:
    Var DTM : Integer;

    3. Then use the DTM you had (the stringy stuff) and do this:
    SCAR Code:
    Var DTM : Integer;

    Begin
      DTM := DTMFromString('78DA6364626660F8C0C8800C8EECDECDF01F4' +
        '88344FF03012348CD7D543510591809A405816A9E1350C30254F3' +
        '8B809A6F4C0C0C1F09A8F90554F384801A5EA05DDFF0AB0100A50' +
        'E0FF5');

    End.
    This has loaded your DTM in to the memory of SCAR.

    4. Now choose the function you want to use (I recommend FindDTM);
    SCAR Code:
    Var DTM, x, y : Integer;

    Begin
      DTM := DTMFromString('78DA6364626660F8C0C8800C8EECDECDF01F4' +
        '88344FF03012348CD7D543510591809A405816A9E1350C30254F3' +
        '8B809A6F4C0C0C1F09A8F90554F384801A5EA05DDFF0AB0100A50' +
        'E0FF5');

      If FindDTM(DTM, x, y, 0, 0, 700, 500) Then

    End.
    Remember! Make x, y variables as they will be the co-ords the position of your DTM is stored in! FindDTM will output the x and y variable, so it is crucial you have those!

    5. Now make it do an action with the if statement, for example make it write something if it finds it, or make it click on it.
    SCAR Code:
    Var DTM, x, y : Integer;

    Begin
      DTM := DTMFromString('78DA6364626660F8C0C8800C8EECDECDF01F4' +
        '88344FF03012348CD7D543510591809A405816A9E1350C30254F3' +
        '8B809A6F4C0C0C1F09A8F90554F384801A5EA05DDFF0AB0100A50' +
        'E0FF5');

      If FindDTM(DTM, x, y, 0, 0, 700, 500) Then
        Mouse(x, y, 0, 0, True);
    End.

    6. Free your DTM, if you do not need to use it again!
    SCAR Code:
    Var DTM, x, y : Integer;

    Begin
      DTM := DTMFromString('78DA6364626660F8C0C8800C8EECDECDF01F4' +
        '88344FF03012348CD7D543510591809A405816A9E1350C30254F3' +
        '8B809A6F4C0C0C1F09A8F90554F384801A5EA05DDFF0AB0100A50' +
        'E0FF5');

      If FindDTM(DTM, x, y, 0, 0, 700, 500) Then
        Mouse(x, y, 0, 0, True);

      FreeDTM(DTM); // :)
    End.



    III - Bitmaps[(Bit2)]


    Welcome to my second section on bitmaps, a bitmap is basically a picture. In the 'new' SCAR bitmap finding is faster than DTM Finding (clearance needed.). Making Bitmaps is easy, there are a number of ways of doing this. I'll show you one way, then I'll explain other ways.


    How to Make a Bitmap.

    Now to make a bitmap you need your RuneScape screen loaded, now just as before, you need to take a screen shot of it, by pressing this button:



    Then, open Paint and paste the screen shot. Mine looks like this:



    (Note: I cropped this)

    Now, using the Rectangle select tool; select a small part of the item, you want to find.



    (Note I magnified this for clearer viewing).

    Then, Right click in the square and press 'copy' or 'cut'.

    I really don't need a pic to explain this to you...


    So, open up SCAR. Go to Tools > Picture to String...
    You should have something such as this:



    Now you should see a button labeled paste, click on that and voila:



    You should get that

    Firstly, name it (I have named mine 'Rune_Chain') please make it specific . Secondly, press 'Ok' to confirm. Now you should have some weird symbols and letters in the Debug Box. This is what you call a bitmap. If your observant then you may have noticed that after the name and the ':=' it says

    SCAR Code:
    BitmapFromString
    Omg wait...That was like, the same on DTMz!!
    Well done..

    My Bitmap looks as so:

    SCAR Code:
    Rune_Chain := BitmapFromString(25, 19, 'beNrN001rwkAQgOGxSP' +
      '9RL0VkJ7KkQZRNrWVxIZkqkUUQ/P+nTjObMaQtXnJIeC4JMy/kCyC' +
      'voj2QDQ1DTyt/7MPPWix3QSycF6+bvXjJtwwAnj/e5s7MS2TgDPpM' +
      'pJSrxR8pW4qZ2TJOLfdBgQvo61aXSqf3VH9eyMDoqacyE+Cy7gb5T' +
      'qmVUvAehBZ0S1Y0tQrHPgz6IlLq/vy71GBl3NT6dMWssVXLUP4Vmc' +
      'WUUr+/irRSNbIy5ZQqKBZ0YWgi/wU/P0KXevj9Tza1ibeC6L+U0ib' +
      'Pi0Fzsqn1mQukA4KvSFOvaJPnxWBl3NRoxzdQZKhB');
    Iz Nice!

    Congratz on getting this far, now continue for the head shot!


    Using your Bitmap.

    Using a bitmap is the same as using a DTM, but before we begin the boring funcs + procs must be told. Now, there are so many functions related to Bitmaps, but since this is a small tutorial, I will list the main ones:

    PHP Code:
    function LoadBitmap(pathstring): Integer;
    Loads bitmap (*.bmpin memory and returns handle to itPath can be absolute or relative if starts with a dot.
    Example:
    somepic := LoadBitmap('.\somepic.bmp'); 
    Again the same as a DTM, the filepath must be sepcified.


    PHP Code:
    procedure FreeBitmap(bitmapInteger);
    Releases a bitmap and frees the memory
    Ahh, the holy FreeBitmap procedure, guess where this comes in??

    [answer]This frees a bitmap from memory just like a DTM, you need to free it from SCAR's memory to reduce lag[/answer]


    PHP Code:
    function BitmapFromString(WidthHeightIntegerdatastring): Integer;
    Loads bitmap in memory from string data and returns handle to it. (Older method
    This will make a bitmap out of all that encrypted string.
    You may, or may not, have noticed that when you make a Bitmap via the Picture to String method; SCAR already includes this.

    ---------------------------------------------------

    Apart from this, there are two main Bitmap finding functions. Remember just as DTMs these functions use x and y as cords, remember to put these in!

    This one is used to represent 'static' bitmaps:

    PHP Code:
    function FindBitmap(BitmapInteger; var xyInteger): Boolean;
    Search for the bitmap in client window. If found coordinates are returned in x,ybitmap contains handle to bitmap generated by LoadBitmap
    Usage:
    SCAR Code:
    Var x, y, bitmap : Integer;

    Begin
      bitmap := BitmapFromString('ff0f0f0f00f'); //not real
      If FindBitmap(bitmap, x, y) Then
        Mouse(x, y, 0, 0, True);
    End;

    These are other main functions they are used to find a bitmap in a specific area, however you can add tolerance - if the object you are trying to find, changes:

    PHP Code:
    function FindBitmapIn(BitmapInteger; var xyInteger;  x1y1x2y2Integer): Boolean;
    Search for the bitmap in coordinates specified by x1y1x2y2Bitmap contains handle to bitmap generated by LoadBitmap.

    //With tolerance
    function FindBitmapToleranceIn(BitmapInteger; var xyIntegerx1y1x2y2IntegertoleranceInteger): Boolean;
    Works like FindBitmapIn but with a tolerance parameter for finding any similar colored bitmap

    Tolerance is used to find a colored bitmap in range of the bitmap you are looking for. The greater color range you wantthe higher the tolerance parameter should be
    FindBitmapIn - This will try and find a bitmap in a given area specified by the co-ords, this does not

    ave tolerance, so for example:

    SCAR Code:
    Var x, y, bitmap : Integer;

    Begin
      bitmap := BitmapFromString('ff0f0f0f00f'); //not real
      If FindBitmapIn(bitmap, x, y, 0, 0, 300, 200) Then
        Mouse(x, y, 0, 0, True);
    End;
    This differs from FindBitmap as that function will find it anywhere of the screen .


    FindBitmapToleranceIn - This will try and find a bitmap in a given area specified by the co-ords, this does have tolerance, so for example:

    SCAR Code:
    Var x, y, I, bitmap : Integer;

    Begin
      bitmap := BitmapFromString('ff0f0f0f00f'); //not real
      Repeat
        If Not FindBitmapToleranceIn(bitmap, x, y, 10, 80, 600, 400, I) Then
        Begin  
          Inc(I);  
          Mouse(x, y, 0, 0, True);
        End;
      Until(I > 50);
     If I > 50 Then WriteLn('The bitmap has a great tolerance ;)');
    End;

    These functions will find a bitmap, congratulations on getting this far.


    So to put it all together.

    1. You need your bitmap:
    SCAR Code:
    Bitmap := BitmapFromString(25, 19, 'beNrN001rwkAQgOGxSP' +
      '9RL0VkJ7KkQZRNrWVxIZkqkUUQ/P+nTjObMaQtXnJIeC4JMy/kCyC' +
      'voj2QDQ1DTyt/7MPPWix3QSycF6+bvXjJtwwAnj/e5s7MS2TgDPpM' +
      'pJSrxR8pW4qZ2TJOLfdBgQvo61aXSqf3VH9eyMDoqacyE+Cy7gb5T' +
      'qmVUvAehBZ0S1Y0tQrHPgz6IlLq/vy71GBl3NT6dMWssVXLUP4Vmc' +
      'WUUr+/irRSNbIy5ZQqKBZ0YWgi/wU/P0KXevj9Tza1ibeC6L+U0ib' +
      'Pi0Fzsqn1mQukA4KvSFOvaJPnxWBl3NRoxzdQZKhB');

    2. You need to load it, so create a variable called Bitmap:
    SCAR Code:
    Var Bitmap : Integer;

    3. Then use the DTM you had (the stringy stuff) and do this:
    SCAR Code:
    Var Bitmap : Integer;

    Begin
    Bitmap := BitmapFromString(25, 19, 'beNrN001rwkAQgOGxSP' +
      '9RL0VkJ7KkQZRNrWVxIZkqkUUQ/P+nTjObMaQtXnJIeC4JMy/kCyC' +
      'voj2QDQ1DTyt/7MPPWix3QSycF6+bvXjJtwwAnj/e5s7MS2TgDPpM' +
      'pJSrxR8pW4qZ2TJOLfdBgQvo61aXSqf3VH9eyMDoqacyE+Cy7gb5T' +
      'qmVUvAehBZ0S1Y0tQrHPgz6IlLq/vy71GBl3NT6dMWssVXLUP4Vmc' +
      'WUUr+/irRSNbIy5ZQqKBZ0YWgi/wU/P0KXevj9Tza1ibeC6L+U0ib' +
      'Pi0Fzsqn1mQukA4KvSFOvaJPnxWBl3NRoxzdQZKhB');

    End.
    This has loaded your Bitmap in to the memory of SCAR.

    4. Now choose the function you want to use (I recommend FindBitmap);
    SCAR Code:
    Var Bitmap, x, y : Integer;

    Begin
    Bitmap := BitmapFromString(25, 19, 'beNrN001rwkAQgOGxSP' +
      '9RL0VkJ7KkQZRNrWVxIZkqkUUQ/P+nTjObMaQtXnJIeC4JMy/kCyC' +
      'voj2QDQ1DTyt/7MPPWix3QSycF6+bvXjJtwwAnj/e5s7MS2TgDPpM' +
      'pJSrxR8pW4qZ2TJOLfdBgQvo61aXSqf3VH9eyMDoqacyE+Cy7gb5T' +
      'qmVUvAehBZ0S1Y0tQrHPgz6IlLq/vy71GBl3NT6dMWssVXLUP4Vmc' +
      'WUUr+/irRSNbIy5ZQqKBZ0YWgi/wU/P0KXevj9Tza1ibeC6L+U0ib' +
      'Pi0Fzsqn1mQukA4KvSFOvaJPnxWBl3NRoxzdQZKhB');

      If FindBitmap(Bitmap, x, y) Then

    End.
    Remember! Make x, y variables as they will be the co-ords the position of your Bitmap (if found) is stored in! FindBitmap will output the x and y variable, so it is crucial you have those!

    5. Now make it do an action with the if statement, for example make it write something if it finds

    it, or make it click on it.
    SCAR Code:
    Var Bitmap, x, y : Integer;

    Begin
    Bitmap := BitmapFromString(25, 19, 'beNrN001rwkAQgOGxSP' +
      '9RL0VkJ7KkQZRNrWVxIZkqkUUQ/P+nTjObMaQtXnJIeC4JMy/kCyC' +
      'voj2QDQ1DTyt/7MPPWix3QSycF6+bvXjJtwwAnj/e5s7MS2TgDPpM' +
      'pJSrxR8pW4qZ2TJOLfdBgQvo61aXSqf3VH9eyMDoqacyE+Cy7gb5T' +
      'qmVUvAehBZ0S1Y0tQrHPgz6IlLq/vy71GBl3NT6dMWssVXLUP4Vmc' +
      'WUUr+/irRSNbIy5ZQqKBZ0YWgi/wU/P0KXevj9Tza1ibeC6L+U0ib' +
      'Pi0Fzsqn1mQukA4KvSFOvaJPnxWBl3NRoxzdQZKhB');

      If FindBitmap(Bitmap, x, y) Then
        Mouse(x, y, 0, 0, True);
    End.

    6. Free your Bitmap, if you do not need to use it again!
    SCAR Code:
    Var Bitmap, x, y : Integer;

    Begin
    Bitmap := BitmapFromString(25, 19, 'beNrN001rwkAQgOGxSP' +
      '9RL0VkJ7KkQZRNrWVxIZkqkUUQ/P+nTjObMaQtXnJIeC4JMy/kCyC' +
      'voj2QDQ1DTyt/7MPPWix3QSycF6+bvXjJtwwAnj/e5s7MS2TgDPpM' +
      'pJSrxR8pW4qZ2TJOLfdBgQvo61aXSqf3VH9eyMDoqacyE+Cy7gb5T' +
      'qmVUvAehBZ0S1Y0tQrHPgz6IlLq/vy71GBl3NT6dMWssVXLUP4Vmc' +
      'WUUr+/irRSNbIy5ZQqKBZ0YWgi/wU/P0KXevj9Tza1ibeC6L+U0ib' +
      'Pi0Fzsqn1mQukA4KvSFOvaJPnxWBl3NRoxzdQZKhB');

      If FindBitmap(Bitmap, x, y) Then
        Mouse(x, y, 0, 0, True);

      FreeBitmap(Bitmap); // :)
    End.



    III - Color[(Col3)]

    Hello and welcome to my third, and final, section on color. Color in SCAR is amazing, without color most of our functions would cease to exist. Functions like this:

    SCAR Code:
    function FindObjEx(var cx, cy: Integer; Text: TStringArray; Color: TIntegerArray;
        Tol, Step, xs, ys, xe, ye: Integer): Boolean;
    var
      CurX, CurY, a, b, c, i: Integer;
      Start: Boolean;
    begin
      for b := 0 to (GetArrayLength(Color)-1) do
      begin
        if (FindColorSpiralTolerance(cx, cy, color[b], xs, ys, xe, ye, Tol)) then
        begin
          Start := True;
          Break;
        end;
      end;
      if (Start) then
      begin
        CurX := Round((xs + xe) div 2);
        CurY := Round((ys + ye) div 2) - Step;
        i := 1;
        repeat
          for c := 1 to i do
          begin
            case a of
              0: begin  //To allow for beginning offset and loop
                   a := a + 1;
                   i := 0;
                   CurY := CurY + Step;
                 end;
              1: CurX := CurX + Step;
              2: CurY := CurY - Step;
              3: CurX := CurX - Step;
              4: CurY := CurY + Step;
            end;
            if (CurX >= xs) and (CurX <= xe) and (CurY >= ys) and (CurY <= ye) then
            begin
              try
                for b := 0 to (GetArrayLength(Color)-1) do
                begin
                  if (FindColorTolerance(cx, cy, Color[b], CurX-(Step/2), CurY-(Step/2), CurX+(Step/2),

    CurY+(Step/2), Tol)) then
                  begin
                    MMouse(cx, cy, 3, 3);
                    If (WaitUptextMulti(Text, 300)) then
                    begin
                      GetMousePos(cx, cy);
                      Result := True;
                      Exit;
                    end;
                  end;
                end;
              except
              end;
            end;
          end;
          a := a + 1;
          if a mod 5 = 0 then a := 1;
          if (a = 1) or (a = 3) then i := i + 1;
        until (Result) or ((CurX > xe) and (CurY > ye))
      end;
    end;

    ^ Depend fully on Color! ^


    Usage Of Color

    In this section I will tell you about the usage of color.

    PHP Code:
    function GetColor(xyInteger): Integer;
    Return 
    color number at xy
    This gets the color at x, y. For example GetColor(1, 1) would get that color at 1, 1 in cords.

    To demonstrate:

    I want to get that color at 580, 395. This is to check if a certain item exists.



    SO, we can do:

    SCAR Code:
    If GetColor(580, 395) = 65536 Then
      WriteLn('A cowhide is at inv slot 17') Else
      WriteLn('No cowhide!');

    The great thing about GetColor is that it can be used to check anything, for example:

    SCAR Code:
    {*******************************************************************************
    function RSReady: Boolean;
    By: ZephyrsFury
    Description: Returns true if we are ready to auto (on loginscreen or logged in).
      Useful for waiting until RS has fully loaded.
    *******************************************************************************}


    function RSReady: Boolean;
    begin
      Result := (LoggedIn) or (GetColor(520, 146) = 4038981);
    end;

    See the GetColor in there??

    +++++++++++++++++++++++++++++++++++++++

    Now for the FindColor functions. There are 5 main Color finding functions which do not include TPA's or skipboxes or circles or triangles or componants.

    They be:

    PHP Code:
    function FindColor(var xyIntegercolorxsysxeyeInteger): Boolean;
    Find color in box specified by xsysxeye starting from left to rightReturns True if color foundthe coordinates of the color if found is put in x,y.

    function 
    FindColorTolerance(var xyIntegercolorxsysxeyeIntegerToleranceInteger): Boolean;
    Works like the regular FindColor function but with a tolerance parameter for finding any similar colorTolerance is used to find a color in range of the color you are looking for. The greater color range you wantthe higher the tolerance parameter should be.

    function 
    FindColorSpiral(var xyIntegercolorxsysxeyeInteger): Boolean;
    Find color in box specified by xsysxeye but start from x,y.

    function 
    FindColorSpiralTolerance(var xyIntegercolorxsysxeyeIntegerToleranceInteger): Boolean;

    Works like the regular FindColorSpiral but with a tolerance parameter for finding any similar colorTolerance is used to find a color in range of the color you are looking for. The greater color range you wantthe higher the tolerance parameter should be.

    function 
    FindColorSpiral2(var xyIntegercolorxsysxeyeInteger): Boolean;
    Find color just like FindColorSpiral, and if there is a big spot of that color then it finds the center of it

    PHP Code:
    function FindColor(var xyIntegercolorxsysxeyeInteger): Boolean;
    Find color in box specified by xsysxeye starting from left to rightReturns True if color foundthe coordinates of the color if found is put in x,y
    This first function FindColor will Find a color specified by Color:Integer and will return the

    Co-ordinates of it, in x and y. With this function you can specify what box you want to search in.

    E.g To search in the MainScreen in RS:
    SCAR Code:
    Begin
      If FindColor(x, y, clGreen, MSX1, MSY1, MSX2, MSY2) Then
        MMouse(x, y, 0, 0);

    This is GreAT! As it coincides with SRL's Global Coordinates.


    PHP Code:
    function FindColorTolerance(var xyIntegercolorxsysxeyeIntegerToleranceInteger): Boolean;
    Works like the regular FindColor function but with a tolerance parameter for finding any similar colorTolerance is used to find a color in range of the color you are looking for. The greater color range you wantthe higher the tolerance parameter should be
    This second function FindColorTolerance will Find a color specified by Color:Integer and will return the Co-ordinates of it, in x and y. With this function you can specify what box you want to search in.
    However, the added part is that you can specify the tolerance. The tolerance can help if a color consistantly changes.

    E.g To search in the MainScreen in RS, to find a Yew Tree:
    SCAR Code:
    Begin
      If FindColorTolerance(x, y, clGreen, MSX1, MSY1, MSX2, MSY2, 39) Then
        MMouse(x, y, 0, 0);

    This is GreAT! As it coincides with SRL's Global Coordinates. However, using this function you can use a static color and if the color is slightly different (based on the tolerance) it will find it.


    PHP Code:
    function FindColorSpiral(var xyIntegercolorxsysxeyeInteger): Boolean;
    Find color in box specified by xsysxeye but start from x,y
    This function is the same as FindColor except it spirals outwards from x and y. For example there are two objects on the ground which share the same color, but you want to find the one closest to you:

    SCAR Code:
    Begin
      If FindColorSpiral(MSCX, MSCY, 65534, MSX1, MSY1, MSX2, MSY2) Then
        MMouse(x, y, 0, 0);
    MSCX and MSCY are the center points of the MainScreen box.


    PHP Code:
    function FindColorSpiralTolerance(var xyIntegercolorxsysxeyeIntegerToleranceInteger): Boolean;
    Works like the regular FindColorSpiral but with a tolerance parameter for finding any similar colorTolerance is used to find a color in range of the color you are looking for. The greater color range you wantthe higher the tolerance parameter should be
    This is FindColorTolerance but has the spiral 'outward' characteristic of FindColorSpiral. For example I want to find a Bone closest to me on the ground, however the tolerance changes, combining the technique used before on FindColorSpiral we can do this:

    SCAR Code:
    Begin
      If FindColorSpiralTolerance(MSCX, MSCY, clWhite, MSX1, MSY1, MSX2, MSY2, 39) Then
        MMouse(x, y, 0, 0);


    PHP Code:
    function FindColorSpiral2(var xyIntegercolorxsysxeyeInteger): Boolean;
    Find color just like FindColorSpiral, and if there is a big spot of that color then it finds the center of it
    For example, you want to find a center of a big blob of 'tree' you would use this:

    SCAR Code:
    Begin
      If FindColorSpiral2(MSCX, MSCY, clWhite, MSX1, MSY1, MSX2, MSY2, 39) Then
        MMouse(x, y, 5, 5); //can add randomness as it is the middle of it not the edge.



    Color Constants

    Color constants as constants in SCAR which contain a color in a form of an integer. To find all of them, just press CTRL+Space is SCAR and type in cl.

    The most common ones:

    • ClRed - 255;
    • ClYellow - 65535;
    • ClWhite - 16777215;
    • clBlack - 0;
    • ClNone - 536870911;


    You may have noticed I used them in the FindColor part of the tutorial. Their uses are mainly to do with Form making.


    Count Color

    PHP Code:
    function CountColor(Colorx1y1x2y2Integer): Integer;
    Counts the instances found of Color in the area specified by x1y1x2 and y2
    Count Color counts the number of pixels in an area, and outputs this as a integer. It is simple and easy to use. Say for instance I wanted to find the amount of 'color' pixel in this area:



    I would do

    SCAR Code:
    WriteLn(CountColor(44334, 250, 270, 300, 310));

    This can be useful in other cases such as:

    SCAR Code:
    function SetRun(Run: Boolean): Boolean;
    Begin
      if (CountColorTolerance(5753055, 715, 105, 731, 110, 30) +
      CountColorTolerance(514811, 715, 105, 731, 110, 30) > 10) xor (Run) then
      begin
        Mouse(715, 95, 10, 10, True);
        Result := True;
      end;
    End;

    CountColorTolerance is used, Just as before:

    PHP Code:
    function CountColorTolerance(Colorx1y1x2y2ToleranceInteger): Integer;
    Works like the regular CountColor function but with a tolerance parameter for finding any similar colorTolerance is used to find a color in range of the color you are looking for. The greater color range you wantthe higher the tolerance parameter should be
    This function is open for the color changing if it does (depending on the tolerance) it shall count it in.


    V - End Note.

    Couldn't not have done this without some people:

    1. Yakman,
    2. Niels,
    3. Da0wner,
    4. IceFire,
    5. Zeph.


    Thanks all!



    BTW, sorry for all the ads, I feel like an advertising post after this tutorial xD.
    Last edited by Naum; 07-17-2009 at 02:36 PM.

  2. #2
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Nice, good for beginners

    On a side note, you should keep it the variable types of DTMS, Bitmaps and Colours as Integer's, as they're generally faster for the platform and CPU
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  3. #3
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Okay, Thanks.
    Added

  4. #4
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Haha, very nice tutorial Nauman !

    Rep++.

  5. #5
    Join Date
    Dec 2006
    Location
    Program TEXAS home of AUTOERS
    Posts
    7,934
    Mentioned
    26 Post(s)
    Quoted
    237 Post(s)

    Default

    yay naum!!! good job.

  6. #6
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice tutorial, belongs in intermediates.

    +1

  7. #7
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Looks good but please, crop your pictures. They are unnecessarily large.

    Also, your intro doesn't match the DTM section names. You change static etc.

    Finally, everything you posted is colour! Don't kid yourself nothing here is anything else.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  8. #8
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    Looks good but please, crop your pictures. They are unnecessarily large.

    Also, your intro doesn't match the DTM section names. You change static etc.

    Finally, everything you posted is colour! Don't kid yourself nothing here is anything else.
    Yeah, I can't crop the pictures much more, mainly because it contains the interface from the DTM Editor. I'll edit the section names thx .
    Also, I knew it was color, I did mainly for the person reading it, to split up different sections - to make it more reader-friendly

    Thanks IceFire
    Last edited by Naum; 07-18-2009 at 04:01 PM.

  9. #9
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default

    lol I been here for over a year and never knew how to make a bitmap I feel like such a noob. I always liked DTM's better, they just seem sexier. I wanted to add a food bmp to a script though today, so this showed me what to do, I only didn't know bout boxing a portion of the image, thanks NaumanAkhlaQ. Rep+ for helping a noob who shoulda known this already

  10. #10
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Baked0420 View Post
    lol I been here for over a year and never knew how to make a bitmap I feel like such a noob. I always liked DTM's better, they just seem sexier. I wanted to add a food bmp to a script though today, so this showed me what to do, I only didn't know bout boxing a portion of the image, thanks NaumanAkhlaQ. Rep+ for helping a noob who shoulda known this already
    Thanks, it's always a pleasure to know that someone has actually learnt something .
    It shows my tutorials aren't all going in vain.

  11. #11
    Join Date
    Nov 2007
    Location
    I live in Slovenia! :)
    Posts
    837
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Rep ++ for you

    + DTM's to my SCAR vocabulary
    ~T2

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
  •