Hi all,
I thought I would whip up another Aerolib tutorial that explains how to identify and use items from your inventory and/or bank.
This tutorial will assume that you have read the previous Aerolib tutorial, and that you are familiar with the basics of scripting in Aerolib.
So lets begin!
What are items?
Items are the objects in your inventory and bank. These are the icons that represent real Runescape items like Iron ore, Gold bars, Coins, Herbs etc. The way we identify items is a little different to the way we identify world Objects like mining veins and banks.
Flight has done the hard yards and created some includes inside of Aerolib that make item creation and interaction a breeze!
Items can be identified using a few different processes, but we will be using a type called DTM (Deformable Template Models).
DTMs use points, color and tolerence to identify an object. This usually consists of a main point in the centre of the item (usually on a colored section) and a series of points on the black outline. Every item in runescape has a black outline with the same color and tolerence.
DTMs that need to identify items of a similar nature and structure can use multiple colors or even black counts to really refine the search.
Creating a DTM
Simba just so happens to include a DTM Editor.
This is located in Tools > DTM Editor (a popup will appear).
__________________________________________________ ________________________
If the DTM Editor option does not exist, go to: View > Extensions.
An interface will popup, the same interface you would have used when setting up Simba initially.
Look for a line: dtm_editor.sex, highlight it, and click the enable check box.
__________________________________________________ ________________________
Before proceeding, ensure that you have the Runescape client loaded, and use the Crosshairs in Simba to target the client.
The DTM editor looks like this:
Now that you have the DTM editor open, click on: Image > Load client
This will ensure that only the Runescape client is shown.
Log your character in and have the item you wish to create in your inventory.
If the picture on the DTM editor is outdated, click Image > Load client again.
For the purpose of this tutorial, I will be using an Air Talisman.
Click towards the centre of the object and find a prominent color. A flashing dot will appear and the box on the right will populate with some data.
The data on the right is as follows:
TPoint (578, 225)
Color (10461099)
Tolerence (0)
Unimportant (1, 0)
Now that we have our prime color, we want to trade the black outline. When you mouse over the picture, the box at the top right will populate with the color that your cursor is on. This makes selecting the black outline super easy. Once you have got the black outline under your cursor, click. You will see a color/tol value of 65536/0. If you see another color, you selected the wrong color and need to delete the point (Delete point button).
You will also note a line from the centre point to this point.
Proceed to do this around your DTM. The more points, the more accurate the identification of the DTM will be.
Now that we have created the outline of our DTM, we want to set the tolerence value of the first point. This will be trial and error, as Runescape changes color every time you log in. I usually start with a value of 25 or so, but if the object is quite unique in shape, you can go higher.
To change the value, go to the box on the right hand side where your data is populated and scroll to the top if required. Select the first color (it will be the only different color) and change the Tolerance field to your desired value.
Once you have done that, it is time to save your DTM. Click FIle > Save DTM and then call it whatever you want.
Once saved, close the DTM popup.
Now we want to try the DTM out and see if Simba can identify it.
Re-open the DTM Editor screen.
Your picture will still be there, but your DTM won't be. Click Image > Load client again.
Go to File > Open DTM and select your DTM that you created.
It will appear at the top left corner of the editor - don't worry about this.
Click Image > Show Matching DTMs.
If a red cross appeared over your DTM, you were successful!
If not, you need to adjust your tolerence and ensure that you only selected 1 color and the rest black lines.
Best practice is to try this with the bank open and a copy of the item visible in your bank and your inventory to ensure identification. This also helps to filter out any other items that may identify which shouldn't.
Now that we have successfully created our DTM, we want to generate some code for use in our script.
With your DTM loaded, go to DTM > Print DTM
A line of code will appear in the debug box that looks like this: DTM := DTMFromString('m6wAAAHicjcxZCoAwDEXRVxxAKyhOoLj3Lq Cb7C3Nh595cEJISKKkBRsunFgxo1fLgA4jos1qv+PAhxe33U62 zylRg8sjf3wfm18K8N8DMw==');
Keep this information safe for use later on in the tutorial.
Item functions and includes
There are 2 includes that you will use frequently when it comes to Items: Items.Simba and Bank.Simba.
..Simba\Includes\AeroLib\entities\items\Items.Simb a
..Simba\Includes\AeroLib\core\Bank.Simba
Items.Simba provides information on creating, interacting and using the items, while Bank.Simba includes limited functionality with the items.
Have a read through both of the includes. Any function that uses a TItem can be used to interact with our item.
Creating and interacting with an item in your script
Now that we have created our DTM, it is time to create the item in our script.
This is the mock script that I will be using for the purpose of this tutorial:
Simba Code:
program Tutorial;
{$i AeroLib/AeroLib.Simba}
Procedure LoadItem;
begin
end;
Procedure UseItem;
begin
end;
begin
initAL;
LoadItem();
UseItem();
end.
The first thing we need to do is declare a variable as a TItem. This can called anything, but I like to call it something related to the item. In this case, it will be AirTally.
Simba Code:
program Tutorial;
{$i AeroLib/AeroLib.Simba}
var
AirTally:TItem;
Procedure LoadItem;
begin
end;
Procedure UseItem;
begin
end;
begin
initAL;
LoadItem();
UseItem();
end.
Now we want to set the DTM to the item. Since TItem is a type, we simply type our variable name, followed by a .
This should bring up a list of possible functions and variables we can use with this.
We will be using AirTally.DTM.
Simba Code:
program Tutorial;
{$i AeroLib/AeroLib.Simba}
var
AirTally:TItem;
Procedure LoadItem;
begin
AirTally.DTM := DTMFromString('m6wAAAHicjcxZCoAwDEXRVxxAKyhOoLj3LqCb7C3Nh595cEJISKKkBRsunFgxo1fLgA4jos1qv+PAhxe33U62zylRg8sjf3wfm18K8N8DMw==');
end;
Procedure UseItem;
begin
end;
begin
initAL;
LoadItem();
UseItem();
end.
As you can see, we used the DTM information that we generated and assigned it to the AirTally TItem. This means that any functions that use a DTM that involve this item, will use the DTM we declare here.
Now we want to interact with the item. There are a few ways to do this. I will list a few examples and explain them on the code below.
Simba Code:
program Tutorial;
{$i AeroLib/AeroLib.Simba}
var
AirTally:TItem;
Procedure LoadItem;
begin
AirTally.DTM := DTMFromString('m6wAAAHicjcxZCoAwDEXRVxxAKyhOoLj3LqCb7C3Nh595cEJISKKkBRsunFgxo1fLgA4jos1qv+PAhxe33U62zylRg8sjf3wfm18K8N8DMw==');
end;
Procedure UseItem;
var
pnt: TPoint;
begin
// TIem.InInventory returns a boolean result to see if our item is in our inventory.
if AirTally.InInventory then
WriteLn('Found Item in inventory!');
// TItem.FIndIn(Area:Tbox, var Tpoint) returns a boolean and provides us with a TPoint if our item is found in our inventory.
if AirTally.findIn(Area_Inv, pnt) then
WriteLn('Found Item in our inventory and stored its location on variable: pnt');
// TItem.GetSlot returns an integer for the first slot that has our item in it.
WriteLn('The first slot our item is location in is: ' +IntToStr(AirTally.GetSlot));
// TItem.Interact(mouse varient) finds and interacts with the first instance of our item.
if AirTally.interact(MOUSE_RIGHT) then
WriteLn('We found the item in our inventory and right clicked on it!');
// TItem.GetAmount(Exclude bank) returns an integer with the quantity of our item that is found on the MS. Exclude bank excludes the bank and searches only in the inventory.
WriteLn('We have: ' +IntToStr(AirTally.getAmount(True)) + ' of our item in our inventory');
end;
begin
initAL;
LoadItem();
UseItem();
end.
As you can see, there are many ways for us to interact with our item.
Items.Simba has also has the a function called GetSlots that will get the slot number of each Inventory slot that contains the item, and returns it as a TIntegerArray.
I will show you how this works.
Say for instance we are power mining iron ore. We want to keep the valuable gems that we mine and only drop the Iron ore. This is possible to do with the following script:
Simba Code:
program Tutorial;
{$i AeroLib/AeroLib.Simba}
var
IronOre:TItem;
Procedure LoadItem;
begin
IronOre.DTM := DTMFromString('m6wAAAHicjcxZCoAwDEXRVxxAKyhOoLj3LqCb7C3Nh595cEJISKKkBRsunFgxo1fLgA4jos1qv+PAhxe33U62zylRg8sjf3wfm18K8N8DMw==');
end;
Procedure DropOre;
var
pnt: TPoint;
i: integer;
TempArray: TIntegerArray;
begin
TempArray := IronOre.getSlots(); //Stores the slot numbers that contain our item (1 to 28).
for i := low(TempArray) to high(TempArray) do //Sets the variable i to the lowest slot number found with our item and repeats all numbers inbetween and up to our highest slot number with our item.
begin
MouseBox(InvBox(TempArray[i]), MOUSE_MOVE); //Mouses over a random part of the slot that contains our item.
if IsUpTextMulti(['Iron', 'ore', 'ron or']) then //Checks the uptext of the item to see if it indeed the item we are looking for.
if InteractSlot(TempArray[i], MOUSE_RIGHT) then //Interacts with the slot by right clicking.
if WaitOption('drop', 1000) then //Waits for the option 'drop' to exist after right clicking.
ChooseOption('drop'); //Chooses the option drop after we confirm the option exists.
end; //if i is less than high, this function repeats again, but with i being the next highest value found in the array.
end;
begin
initAL;
LoadItem();
DropOre();
end.
I have added comments in the script itself that talk you through the process. For..To..Do is a very powerful tool in scripting and should be used often