Basic script

Create a basic Simba script tutorial from sratch

By Loading...

In this tutorial Iā€™m going to teach how to make a very basic script to bury bones at GE and if we are not there, we will walk there using only SRL. First of all you must include SRL in your script.

That can be done by adding the following line at the top of your script:

{$I SRL/osr.simba}

This line tells the compiler to include that file which in turn will include all other files in SRL. If you have multiple includes chances are SRL has to be the first one because the others will likely depend on it.

Now letā€™s add a begin end as well:

{$I SRL/osr.simba}

begin

end.

Now, for our script to work, we want to make sure we are logged in, so we are going to:

Add a player Check if we are in game If not, login I also like to have this initial setup separate from everything else, so we are going to move it into a procedure.

{$I SRL/osr.simba}

procedure Init; //you can name it anything but things that make sense are generally the approach.
begin
  Login.AddPlayer('username', 'password', 'bankpin');
  if not RSClient.IsLoggedIn then
    Login.LoginPlayer;
end;

begin
  Init;
end.

Now Iā€™m going to show you one of the coolest things in SRL, in my opinion!

Itā€™s called RSWalker.

RSWalker at itā€™s core just figures out where you are at in the map. But that together with several tricks can allow you to do really cool things. First of all, you can walk. Walking from Lumbridge to the G.E. is no problem at all for RSWalker alongside a webgraph (more on webgraphs in the future). Secondly, we can do nearly tile accurate clicking. Itā€™s not the purpose of this tutorial but if you want to click a specific tile, by knowing you position, the tile position, zoom level and compass angle, with some clever math you can figure out where to click. So, letā€™s setup RSWalker:

{$I SRL/osr.simba}

var
  RSW: TRSWalker;
(*
Name it whatever you want, I usually call it RSW. This means RSW is going to be an instance of TRSWalker.
You can have several instances with different names!
*)

procedure Init;
begin
  RSW.Setup('world');
(*
This can be placed anywhere in the script before you actually use RSW for anything but I like to place it right after SRL.Setup.
'world' means we are going to use the world.png map placed at C:/Simba/Includes/SRL/osr/walker/maps/world.png
Unless you are using WaspLib, custom maps should go there.
*)

  Login.AddPlayer('username', 'password', 'bankpin');
  if not RSClient.IsLoggedIn then
    Login.LoginPlayer;
end;

begin
  Init;
end.

Nowā€¦ SRL already has a built in webgraph with several locations but Iā€™m going to teach you to manually gather coordinates anyway.

So we are going to add a line of code temporarily:

Writeln(RSW.GetMyPos);

This will fetch your position in the world map and print it. We can also add:

RSW.DebugPosition;

This line will make a new window popup which will have a screenshot of our minimap in game with the dots cleared (minimap dots are players, npcs and item dots), alongside the map we loaded marking the position RSWalker thinks we are in. RSWalker is not perfect and it might get your position wrong, so itā€™s useful to use RSW.DebugPosition to see what RSWalker is seeing.

So our script will temporarily look like this:

{$I SRL/osr.simba}

var
  RSW: TRSWalker;

procedure Init;
begin
  RSW.Setup('world');

  Login.AddPlayer('username', 'password', 'bankpin');
  if not RSClient.IsLoggedIn then
    Login.LoginPlayer;
end;

begin
  Init;
  Writeln(RSW.GetMyPos);
  RSW.DebugPosition;
end.

You can also save this to use later as a barebones Position fetcher. Later when you are using WaspLib, thereā€™s something like this included but you can save this for now if you want.

Anyway, moving on. Go stand in the GE, close to the bank/exchange and run the script. You will get something similar to this printed:

Succesfully compiled in 390 milliseconds.
[00:00:00:219]:[RSClient]: Client mode changed: FIXED
{X = 4477, Y = 2491}
Succesfully executed in 4016 milliseconds.

There will also be a window popping up that should look like this:

img0

If your debug image doesnā€™t like the one above, wellā€¦ it shouldā€¦ but RSWalker can mess up sometimes though never had it fail me at the GE to be honest. Anyway, try again and maybe even hop worlds, could be some issues clearing the play dots in a very populated world.

When you get the position right, you have your G.E. Tile X and Y coordinates. Tiles in Simba/SRL are just TPoints.

Letā€™s add it to our script and remove the previously added temporary lines:

{$I SRL/osr.simba}

var
  RSW: TRSWalker;
  GETile: TPoint := [4477, 2491];

procedure Init;
begin
  RSW.Setup('world');

  Login.AddPlayer('username', 'password', 'bankpin');
  if not RSClient.IsLoggedIn then
    Login.LoginPlayer;
end;

begin
  Init;
end.

Now letā€™s create a function that checks if we are close to the GE. We need to be close to it to open the bank otherwise we will have to walk to it first. Iā€™m just going to literally copy paste a very simple function I use in WaspLib:

function AtTile(Tile: TPoint; Distance: Int32 = 15): Boolean;
begin
  Result := RSW.GetMyPos.DistanceTo(Tile)  - if not at the GE, walk to it.
> - if has bones in the the inventory, click them.
> - if it doesn't and the bank is not open, open the bank.

To not over complicate things I'm going to assume the bones are visible right away when opening the bank.
Now we wan to withdraw bones.
TRSBank has some handy records to handle withdrawing and deposit items that are `TRSBankWithdrawItem` and `TRSBankDepositItem`.
If you check SRL's Bank.simba file, they look like this:

```pascal
type
  TRSBankWithdrawItem = record
    Item: TRSItem;
    Quantity: Int32;
    Noted: Boolean;
  end;

  TRSBankDepositItem = record
    Item: TRSItem;
    Quantity: Int32;
  end;

We donā€™t need TRSBankDepositItem for this script but I just thought I would show it to you. Anyway, you can create our BankWithdrawItem like this:

var
  BankWithdrawItem: TRSBankWithdrawItem := ['Bones', 28,  False];
  //There's also a handy constants you can use for quantity that are BANK_WITHDRAW_ALL and BANK_WITHDRAW_ALL_BUT_ONE.

We are not actually going to store this in a variable, but we will use ['Bones', 28, False].

To withdraw TRSBankWithdrawItems you use the following function:

TRSBank.WithdrawItem(Item: TRSBankWithdrawItem; UseQuantityButtons: Boolean)

As you can see, it takes in a TRSBankWithdrawItem instead of a TRSItem like we use for inventory. So we can just do this on the spot:

TRSBank.WithdrawItem(['Bones', BANK_WITHDRAW_ALL, False], True);

We also want to check if we already have the bones when the bank is open. If we do, we can just close the bank. Use Function List to see how to close the bank or see below. Either way you should get used to look at what function are available to you.

Anyway, letā€™s add that to our script:

...
...
...
begin
  Init;

  while True do
  begin
    if not AtTile(GETile) then
      RSW.WebWalk(GETile, 10, 0.2);

    if Bank.IsOpen then //we moved the bank check up here and removed the ""not"".
    begin
      if Inventory.FindItem('Bones') and Inventory.IsFull then
        Bank.Close
      else
      begin
        Bank.WithdrawItem(['Bones', BANK_WITHDRAW_ALL, False], True);
        Wait(700, 1000); //we add a small wait here. Most times when you click an item you want to wait a little bit.
                         //That's because Simba is much faster than osrs at reacting lol.
      end;
    end
    else  //because this is a ""if Bank.IsOpen then.... else"" this else automatically means ""if not Bank.IsOpen then"".
    begin
      if Inventory.FindItem('Bones') then
      begin
        Inventory.ClickItem('Bones');
        Wait(700, 1000);
      end
      else
        Bank.Open(ERSBankLocation.GRAND_EXCHANGE);
    end;
  end;
end.

And that is it. The script is finished!

Iā€™m just going to propose one last change, letā€™s store the item in a variable so we can change it easily. While at it, letā€™s also change it to Tunas, so instead of burying bones you will be eating Tunas.

And the full script should look like this:

{$I SRL/osr.simba}

var
  Item: TRSItem := 'Tuna';
  RSW: TRSWalker;
  GETile: TPoint := [4477, 2491];

procedure Init;
begin
  RSW.Setup('world');

  Login.AddPlayer('username', 'password', 'bankpin');
  if not RSClient.IsLoggedIn then
    Login.LoginPlayer;
end;

function AtTile(Tile: TPoint; Distance: Int32 = 15): Boolean;
begin
  Result := RSW.GetMyPos.DistanceTo(Tile) <= Distance;
end;

begin
  Init;

  while True do
  begin
    if not AtTile(GETile) then
      RSW.WebWalk(GETile, 10, 0.2);

    if Bank.IsOpen then
    begin
      if Inventory.FindItem(Item) and Inventory.IsFull then
        Bank.Close
      else
      begin
        Bank.WithdrawItem([Item, BANK_WITHDRAW_ALL, False], True);
        Wait(700, 1000);
      end;
    end
    else
    begin
      if Inventory.FindItem(Item) then
      begin
        Inventory.ClickItem(Item);
        Wait(700, 1000);
      end
      else
        Bank.Open(ERSBankLocation.GRAND_EXCHANGE);
    end
  end;
end.