Full Bitmap and DTM Tutorial

Discussion in 'Archives' started by WhoCares357, May 1, 2007.

Full Bitmap and DTM Tutorial
  1. Unread #1 - May 1, 2007 at 6:54 PM
  2. WhoCares357
    Joined:
    Jan 21, 2007
    Posts:
    608
    Referrals:
    1
    Sythe Gold:
    0

    WhoCares357 Forum Addict

    Full Bitmap and DTM Tutorial

    Bitmap and DTM Tutorial
    by WhoCares357

    -Thanks to God

    Table of Contents

    --Using Images
    --Capturing Desktop
    --Bitmaps
    ----Creating Bitmaps
    ----Loading Bitmaps
    ----Using Bitmaps
    ----Releasing Bitmaps
    --DTMs
    ----Creating DTMs
    ----Loading DTMs
    ----Using DTMs
    ----Releasing DTMs
    --Choices, Choices…



    ----------Using Images----------


    If you haven’t figured it out yet, this tutorial is going to teach you how to make and use two different Scar supported image types. You will use these images in your Scar scripts to find items, spells, monsters, or other objects that are otherwise unattainable through Color functions (FindColor, etc.).

    Images (especially Bitmaps) should be your last resort. They take up much computer memory (causing it to lag and even freeze). This creates a problem for users of your script that have a low performance computer (low Ram and CPU power).

    Images should also be made as small as possible. The larger an image is, the more memory it will take, thus the more lag it will cause.

    NOTE: Most of my examples will not actually work. I just created them to show you how to use images.

    So, let’s begin:


    ----------Capturing Desktop----------​


    If you don’t have a desktop image capturing tool, follow these steps:

    1. Press Prt Scrn. This button is found above the Insert and Delete buttons. At this point, you should see the screen freeze for half a second. This is the process by which the image of the desktop is being saved. The image will now be in “Copy”

    [​IMG]

    2. Open paint or any other image editing software and do one of the following:
    --Pres ctrl + v
    --Go to Edit – Paste

    -If you used software to capture the screen, just go to File – Open and find your image.

    Save your image as a 24 bit bitmap. If you want to use a bitmap then follow the Bitmap tutorial below. Otherwise just skip down to DTMs.


    ----------Bitmaps----------​

    <Creating Bitmaps>


    The first step in using Bitmaps is making them.

    Once you have loaded the picture into Paint, use your ubber Paint skills to crop and center the image to focus on the object you want. Do this, by using the selection tools (dashed square or star on the left toolbar):
    --Select your object and drag it to the upper left-hand corner.

    [​IMG]

    [​IMG]

    --Zoom out and drag the image to enclose only the object you want.

    [​IMG]

    --Make the background black.

    [​IMG]

    3. Save the image as a 24 bit bitmap (bmp).

    [​IMG]

    <Loading Bitmaps>

    Now that we’re done with the fun part, let’s use our newly created bitmap in a script. I will be using the lobster from the last part for this section as well.

    There are two ways to load a bitmap. The first way should only be used if you are using the script for personal reasons.
    1. Create an integer and give it a name relative to the picture (ie Lobster).

    --The reason we make an integer for bitmaps (and DTMs) is to use a single word instead of posting the whole bitmap “code” every time we want to use it. You will see this a little later.

    By now our script looks like this:
    Code:
    program New;
    
    var
     Lobster: Integer;
    
    begin
    end.
    As you can tell, this script won’t do anything yet. All we did was assign a name to our picture. Now we have to load the picture:
    2. Put this little bit of code where you want to load the bitmap:
    Code:
    program New;
    
    var
     Lobster: Integer;
    
    begin
      Lobster := LoadBitmap('C:\Lobster.bmp');
    //Bitmap Loaded
    end.
    Look closely at Lobster := LoadBitmap(‘’). What we did here is tell Scar to put the image into the word Lobster. Now every time you use Lobster, Scar will see it as the actual bitmap string. You must put the directory (where the image is located) between ‘’.

    That is the first way to load a bitmap. As you can see, the other person must first have the bitmap in the same folder you have it for him to use the script. This is very unlikely, so you should use the second method if you are creating a script that you will share with the world:

    1. Create an integer named something that is related to your object (ie Lobster).
    Once again, our code will look like this:
    Code:
    program New;
    
    var
     Lobster: Integer;
    
    begin
    end.
    2. Go to Tools-Picture To String.

    [​IMG]

    3. Click Open and find the image you want to use. (Click open)
    4. Click Paste and click OK.

    [​IMG]

    5. Look on the bottom window (Debug Box); you will see a long code starting with the name of the bitmap. This is the bitmap. Scar sees pictures as a bunch of letters and numbers.

    [​IMG]

    6. Change the name of the bitmap (the word I highlighted in picture) to the name of your Integer. (ie If I made the integer named “Nat”, the “Lobster” in Lobster := BitmapFromString(31, 30, '… would have to change to Nat := BitmapFromString(31, 30, ')
    7. Copy the whole code and paste it at the place you want the bitmap to load:
    Code:
    program New;
    
    var
     Lobster: Integer;
    
    begin
      Lobster := BitmapFromString(31, 30, 'z78DAED98FD6E83300CC45' +
           'F09E783347F3260EFFF48CB7CD67428C05A0A6D260DA9AE04147E' +
           '38E7B369D7FD6F4F6EB2111BDDA2B849423FF85172EF7C9214671' +
           'F4B1CBC93D03CBF84C97D48D7273F484E63E8654E313819538197' +
           'B1617E09C925295FE5D3DDA6F0E9FC6D08B3138BA93C599B2A927' +
           'EF6936490E7296697F210938B16538C3F3144EF7C33FC467E0B61' +
           '7002FEDD9A953684A20AE94296193A416E5BAE4D388929A48BEE4' +
           'F30AB07C237E02495421A34916F4266866F20E72F21B74AD9A8A6' +
           '95F3416BE4390419518FD0F6C5CCC2DE8BDE07122816B1F681B27' +
           '7EE26CB33F15B55AA635F40BE421BA32F3BD0A3416B54E87A14F1' +
           '2B443EC798552717E4DC68D19717B4DAA3B9CA8C04ABAF3CC82A6' +
           '68FFAB938DBA7923FC06C8A55127336ED713641610ED9253FA927' +
           '5AAE381AADF638BB3BF958E9D8DF9EAC71A12E9EA05845FAA47E2' +
           'AAC53A5F067D42E8BDC56B4AC07AC72C5BCB80E9F0F66C43A3F1C' +
           '0FF1CB8A1270778E20DFF304A9BD1AB313AFC88A0E3557C7C8573' +
           '28C886A22F25FDC1B57809289D968B572CD4B3957C7A771236766' +
           '5620677233DBBA52B57ACD51B72A9D6AE12039657BEBE8DDCCF75' +
           '51055EEEE151E7D93DD3A7A3F73074EF34966265ACB98BAE5CBE7' +
           'AE6DCD336145CBCC953EDF3C1E9A17291B339FEA8A9790B3C772C' +
           'FBDDB63DF9D79E5ACB571EA0C703D394DE678831BCA74E6529B2F' +
           '4346BB3E93B7FF5FDCC99C5F41343C96');
    //Bitmap Loaded
    end.
    <Using Bitmaps>

    Now you have seen two ways to load a bitmap. But how do we make Scar search for a bitmap? In this section, I will show you how to make Scar search for a bitmap.

    There are many functions in Scar that allow you to use Bitmaps. I will show you only a few. If you are interested in the others, press F1 while Scar is open or go to Help-Help in Scar.

    -FindBitmap-

    This function is very simple. All it does is search the whole screen for the bitmap and then returns the location in x, y:
    Code:
    program New;
    //include SRL\SRL.scar (Mouse command is taken from SRL)
    var
      Lobster: Integer;
      x, y: Integer;
    
    begin
      Lobster := BitmapFromString(31, 30, 'z78DAED98FD6E83300CC45' +
      //I just put an example of an abbreviated bitmap
      if(FindBitmap(Lobster, x, y)) then
      begin
        WriteLn(‘Found Bitmap… Attempting to mine.’);
        Mouse(x, y, 1, 1, true);
      end else
        WriteLn(‘Bitmap not found.’);
    end.
    This code first loads the bitmap “Lobster” (Lobster := BitmapFromString…), then it uses the function FindBitmap. “Lobster” is the name of the bitmap. Remember how we created an Integer to represent the bitmap code; this is exactly that. x and y will store the position where the bitmap is found on the screen. FindBitmap searches the whole screen. If the bitmap is found, the mouse will be moved the x and y and clicked there.

    -FindBitmapIn-

    This function is similar to FindBitmap, except for it offers a specific location to search the bitmap in.

    Code:
    program New;
    
    var
      Lobster: Integer;
      x, y: Integer;
    
    begin
    //load bitmap
      if(FindBitmapIn(Lobster, x, y, 100, 100, 200, 200)) then
      begin
        WriteLn(‘Bitmap found. Attempting to click’);
        Mouse(x, y, 1, 1, true);
      end else
        WriteLn(‘Bitmap not found.’);
    end.
    This example is very similar to the last one. The only thing I replaced is FindBitmap. The new function FindBitmapIn performs almost the same way. The only difference is the 100, 100, 200, 200. This function creates a box. In my example it would start at the coordinate 100, 100 (top left corner) and end the box at 200, 200 (bottom right corner). Then Scar will search that box to find the Bitmap. If it finds the Bitmap, Scar will record the position of the Bitmap in x, y. If you have ever used the function FindColor, this is similar to that.

    -FindColorToleranceIn-

    Code:
    program New;
    
    var
      Lobster: Integer;
      x, y: Integer;
    
    begin
    //load bitmap
      if(FindBitmapToleranceIn(Lobster, x, y, 100, 100, 200, 200, 50)) then
      begin
        WriteLn(‘Bitmap found. Attempting to click’);
        Mouse(x, y, 1, 1, true);
      end else
        WriteLn(‘Bitmap not found.’);
    end.
    In this example, I replaced FindBitmapIn with FindBitmapToleranceIn. This function is exactly like FindBitmapIn. The only difference is the final digit (50). This digit is the color tolerance of the bitmap. This function is helpful when the bitmap may have slightly different colors at times. Change the tolerance from 0 to 250 depending on how much the color varies.

    <Releasing Bitmaps>

    After you’re done using a bitmap, you will want to release it. As I said before, bitmaps take up a lot of memory. By releasing bitmaps, we are reducing lag.

    Code:
    program New;
    
    var
     Lobster: Integer;
    
    begin
      LoadBitmap(‘C:\Lobster.bmp’);//Load bitmap
      //use bitmap with FindBitmap (or others)
      FreeBitmap(Lobster); //remove the bitmap “Lobster” from memory
    end.
    This example is very simple. First, I loaded the bitmap Lobster. Then I used it. After I was done using it, I included FreeBitmap(Lobster) to remove the bitmap Lobster from memory. Releasing bitmaps is very simple, and should be done when you use a bitmap for a short time. Freeing bitmaps will reduce lag and improve overall script performance.



    ----------DTMs----------​

    <Creating DTMs>


    Before using a DTM, you must create it.

    Creating DTM is one step short from the same thing as creating Bitmaps.

    Load the image into Paint and follow the directions:

    --Select your object and drag it to the upper left-hand corner.

    [​IMG]


    [​IMG]

    --Zoom out and drag the image to enclose only the object you want.

    [​IMG]

    Save the image as a 24 bit bitmap (bmp).

    [​IMG]

    The reason we skipped the part about making the background black, is because to make a DTM, we need a background that is a different color than the image border (black line that surrounds the lobster).

    To actually create the DTM, we need to use a tool built into Scar called DTM Editor.

    1. Go to Tools-DTM Editor.

    [​IMG]

    2. Right click anywhere in the area (the big area in the middle of the window where your screen was captured). Press load (or paste if you want to copy paste it on) and select the bitmap to load. IMPORTANT: THE PICTURE MUST BE A BITMAP FOR BEST RESULTS.

    [​IMG]

    3. Once you load the picture, you will see it in the top left corner. There is also a zoom box where you can see a zoomed view of your mouse position. Click in the center of your object (item,etc.). You should see a blinking yellow dot in the spot you clicked and an entry in the list box to the right of the window.

    [​IMG]

    This is your center point. Always choose a center point that is not a border and that is as close to the center as you can get it. Now we will have to define the distance between the center point and the border to give the object a shape.

    4. Move your mouse to a boarder of the object (black line). Look in the magnifying view and make sure that the black pixel(s) of the border line are in the center of the magnified view. You should also notice that another entry appears in the list box to the right of the window.

    [​IMG]

    List Box: The first two numbers are the number of pixels from the origin (the first dot you picked) to the border line (the distance to the border). The last big number is the color number. All your border line selections should have the same color number.

    5. Make sure the first dot is highlighted in the list box to the right. (The one that is highlighted is the one it will measure the distance from) Now select three or four more border locations to give the object a specific shape. Make sure that the color numbers of the border lines are all the same. If they’re not, delete the border line in the List Box to the right, click the first selection in the List Box (your first dot) and choose another point.
    6. Click on the first selection in the List Box to the right and change the color tolerance to 250. Leave the rest alone, since black will always be the same color number.

    [​IMG]


    <Loading DTMs>


    1. Now, you can either save the DTM, or load it to the Debug Box in Scar. Click on File-DTM to Text to load it. Click File-Save to save the DTM. (DTM is not saved as an image, rather as measurements and color numbers)

    Now, this part is almost like the bitmaps, with a variation of a few function/command names:

    2. Create an integer with the name you want for the DTM. I’m going to call it Lobster.

    I explained why this is needed in Bitmaps, and won’t do it again, since it just consumes time and you have a mouse to scroll with ;).

    Once again, there are two ways to load a DTM. The first one is the easiest, but it should only be used for personal use.

    Code:
    program New;
    
    var
      Lobster: Integer; //notice the integer
    
    begin
      LoadDTM('C:\Folder\Lobster.DTM'); //loads DTM from a directory
    end.
    LoadDTM loads the DTM you specify in the location (C:\...) of the image. The other way is longer, but should be used for public scripts.

    3. You can find the image string (code) in the Debug Box (if you loaded the DTM in step one). Change the name (DTM:= DTMFromString changes to Lobster:= DTMFromString) of the DTM and copy the code.
    [​IMG]
    4. Put the code wherever you want it to load.

    Code:
    program New;
    
    var
      Lobster: Integer;
    
    begin
      Lobster := DTMFromString('78DA631462606010604001A54E320CD380342' +
         '310FF07024671208397010D302291409A094808135003929725A0' +
         '461E48B01250C30D24B808A8910412A2F8D500003835066C');
    //DTM now loaded
    end.
    This example will load the DTM directly from the string (not needing to open a file). After we load a DTM, we have to use it somehow, or else it’s useless.

    <Using DTMs>

    Unlike Bitmaps, DTMs is only useable with one function.

    Code:
    program New;
    
    var
      x, y: Integer;
      Lobster: Integer; //DTM
    
    begin
    //start load
      Lobster := DTMFromString('78DA631462606010604001A54E320CD380342' +
         '310FF07024671208397010D302291409A094808135003929725A0' +
         '461E48B01250C30D24B808A8910412A2F8D500003835066C');
    //load ended. Use DTM now
      if FindDTM(Lobster, x, y, 100, 100, 250, 300) then //finds DTM
      begin
        Mouse(x, y, 1, 1, true);  //clicks DTM(SRL)
        WriteLn('Clicked Lobster.');
      end;
    end.
    FindDTM is very similar to FindColor or FindBitmap. The first word, Lobster, is the name of your DTM. Use the name of the DTM that you want to find. The x, y are two integers used to store the location of the DTM if it is found. The final four digits are coordinates (x1, y1, x2, y2). These create an imaginary square from the top left corner (100, 100) to the bottom right corner (250, 300) as dimensions in which Scar will search for the DTM.

    Basically, this example loads the DTM named Lobster, searches for it, and then clicks on it if it is found.


    <Releasing DTMs>

    Just like Bitmaps, DTMs take up memory (though not as much). This causes lag on computers with low RAM. To avoid this, free your DTM from memory after you use it.

    Code:
    program New;
    
    var
      x, y: Integer;
      Lobster: Integer; //DTM
    
    begin
    //load DTM
    //Use DTM
    //Now we need to free it from memory
      FreeDTM(Lobster);
    end.
    FreeDTM frees the DTM that you specify (Lobster in my case). This frees the DTM from the memory. If you free it, you have to load it again to use it.

    ----------Choices, Choices…----------​


    Now, you may be wondering why you can’t just use a DTM or Bitmap all the time. Why does Scar have an option? I will give you a few reasons for this:

    1. DTMs usually take up way less memory than Bitmaps. This allows your script to run smoother.
    2. DTMs are used to find objects with a.)Specific shape b.) Border lines
    This means that you should not use a DTM if you want to use it as a picture of a Fire Rune, because there are many other runes that have the same exact shape. You also wouldn’t use a DTM for an NPC, since they don’t have borders.
    3. Bitmaps are much more specific (but once again require more memory).

    I would recommend a DTM over a Bitmap easily, if it is appropriate. However, bitmaps should be used for all the “others” that just won’t cut it with a DTM. Choose wisely before deciding which to use.
     
  3. Unread #2 - May 1, 2007 at 7:03 PM
  4. Hax4You
    Joined:
    Feb 2, 2007
    Posts:
    741
    Referrals:
    0
    Sythe Gold:
    0

    Hax4You Apprentice

    Full Bitmap and DTM Tutorial

    Damnnnnnn.

    NIIIICEE. >SCAR NERD

    Ahem I mean

    You're really smart! :)
     
< Holy Shit so Raciest - Sterotype Here | WoWsucks imposter - sorry for accusing real one. >

Users viewing this thread
1 guest


 
 
Adblock breaks this site