SRL Archive - OSR Beginner Scripting Tutorials

[SRL]How To Write Your First Script: Collecting and Banking Cabbages!


Azir

2019-05-28 07:49:06

For search reference, you probably got this error or something close to it.

xcorr := WorldSample.MatchTemplate(mmsample, Self.TMFormula);

Runtime error: "Access violation" at line 209, column 41 in file "C:\Simba 1.3\Includes\RSWalker\Walker.simba"
Succesfully executed in 28297 ms.
The following bitmaps were not freed: [0, Minimap mask, Smart[13256] Image, 3, 4]

Something that took me a while to figure out, but ended up finding it in the discord (Thanks Olly)
Is that the init method changed, from now on just call Walker.Init('mapname') and no more parameters.

In the tutorial there is still a -1 parameter written.

Walk.Init('world.png', -1); //Setup RSWalker by initializing the map we want to use

So if you just remove the -1 it works as it is expected from the tutorial.


Walk.Init('world.png'); //Setup RSWalker by initializing the map we want to use

bobbersssss

2019-06-28 15:24:23

is there any way to use this on a osrs sourced private server

felparers

2019-06-28 15:59:18

From: bobbersssss
is there any way to use this on a osrs sourced private server


If the client and the version is the same as OSRS it should work

bobbersssss

2019-06-30 12:36:55

From: felparers
If the client and the version is the same as OSRS it should work


is there a way to define my rsps client instead of the osrs client?

felparers

2019-07-02 11:20:55

Drag the target( green + on toolbar) on the client you want to use.

otavioafm

2020-05-09 13:06:58

I've Put You script to kill Flesh crawlers lol, but the mouse is moving to fast, any Ideas to made the mouse move more naturaly, and how to put some antiban?
program new;
{$define SMART}
{$I SRL/OSR.simba}
{$I RSWalker/Walker.simba}

const //This is where we declare our constants
LOGIN_NAME = ''; //Username/Email
LOGIN_PASS = ''; //Password
RS_WORLD = -1; //Desired World (-1 = Random)
IS_MEMBER = false; //True if your player is a Member

var //This is where we declare our variables
Walk: TRSWalker; //Used for RSWalker (to walk paths)

{*******************************************************************************
Name: declarePlayers();
Function: Sets the proper variables using the constants above to allow
a successful login.
*******************************************************************************}
procedure declarePlayers();
begin
with Players.New()^ do
begin
LoginName := LOGIN_NAME;
Password := LOGIN_PASS;
IsActive := True;
IsMember := IS_MEMBER;
World := RS_WORLD;
end;
Players.SetCurrent(0);
end;

{*******************************************************************************
Name: waitLoop();
Function: Waits until we have collected our cabbage
*******************************************************************************}
procedure waitLoop();
var
InvCount: Integer;
T: TTimeMarker;
begin
if not SRL.isLoggedIn() then
Exit;

InvCount := Inventory.Count(); //Gets the count in our inventory
T.Start; //Start our timer
repeat
wait(randomRange(75, 250)); //Wait a random amount of time
until((Inventory.Count() > InvCount) or (T.GetTime > 7000)); //Stop repeating once inv count changes or we time out
end;

{*******************************************************************************
Name: findCabbages();
Function: Locates cabbage in the field. Will print on screen if using SMART.
*******************************************************************************}
procedure findCabbages;
var
TPA, Cabbage: TPointArray;
ATPA: T2DPointArray;
begin
if not SRL.isLoggedIn() then //If not logged in, then terminate script
TerminateScript;

if (SRL.FindColors(TPA, CTS2(6688, 2, 0.29, 0.00), MainScreen.GetBounds) > 0) then //If we find colours at all then…
begin
ATPA := TPA.Cluster(2); //Group them within a max pixel distance of 2
ATPA.FilterSize(100, 500); //Remove and ATPA of size < 100, or > 500.
ATPA.SortByIndex(MainScreen.GetMiddle); //Sort by closest to Middle of the screen

{$IFDEF SMART} //If we are using SMART, then…
Smart.Image.DebugATPA(ATPA);
{$ENDIF} //End SMART IF

for Cabbage in ATPA do //For every possible cabbage in our ATPA
begin
Mouse.Move(Cabbage[Random(Length(Cabbage))]); //Move the mouse to the cabbage

if MainScreen.IsUpText('Attack') then //If the uptext is 'Cabbage', try to click it
begin
if Mouse.Click(ctRed) then //Clicks the mouse and looks to see if red 'x' appeard when cicked
begin
waitLoop(); //Call to our waitLoop because we want to wait while picking.
Break; //If found red 'x', then break because we clicked it
end;
end;
end;
end;

{$IFDEF SMART}
Smart.Image.Clear; //Clears the ATPA's from screen
{$ENDIF}
end;

{*******************************************************************************
Name: setUp();
Function: Sets up the script by initializing everything and logging player in.
*******************************************************************************}
function setUp(): boolean;
begin
{$IFDEF SMART} //If we are using SMART, then…
Smart.EnableDrawing := True; //let us draw on SMART
{$ENDIF} //end SMART IF

SRL.Setup([]); //Setup SRL to allow us to access it's functions.

Walk.Init('world.png', -1); //Setup RSWalker by initializing the map we want to use

declarePlayers(); //Declare the player we are using

if (not SRL.isLoggedIn) then //If not logged in then..
begin
Players.LoginCurrent(); //Log player in
MainScreen.setAngle(True); //Sets the camera angle to the highest point
end;
end;

begin //Main
if setUp then //Calls the setup of the script
writeln('We are set up and ready to go!');
repeat
findCabbages(); //Collect Cabbages until inv is full
until(false); //Repeats forever
end.
begin
FindNormalRandoms;
case Random(90) of
0: RandomRClick;
2: PickUpMouse;
3: RandomMovement;
4: BoredHuman;
5: ExamineInv;
6: MakeCompass('N');
7: SetAngle(SRL_ANGLE_HIGH);
8: Wait(5000+random(2000));
9: HoverSkill(skill_attack,false);
end;

vizzyy

2021-06-04 16:24:20

This was a valuable learning exercise for me, to try and rework this script to work with latest SRL-Dev and simba from olly's github.

I've noticed a ton of things don't quite work for me:
1) Smart doesn't work at all
2) Include log in function doesn't hit the "Login" button after typing in information
3) Include doesn't change camera angle
4) RSWalker is included in SRL-Dev so no need for separate dependency
5) Open bank at tile wasn't working for me, maybe I was using tile coords instead of screen coords, but don't know how to tranlate that without reflection method
6) Lots of little syntax changes between the old and new include, most of the antiban section for example.
7) The ACA bit of the tutorial with the color picker tool still works perfectly well

I was able to piece together the components and this is what I came up with – it may be sloppy but at least I got it to run again as it was intended. Sharing it here for anyone who may follow the main link path for getting introduced to this community:


program cabbage;
{$define SMART}
{$I SRL/OSR.simba}

//Declare our Constants
const
LOGIN_NAME = ''; //Username/Email
LOGIN_PASS = ''; //Password

//Declare our variables
var
Walk: TRSWalker; //Used for RSWalker (to walk paths)
pathToPatch: TPointArray;


{*******************************************************************************
Name: declarePlayers();
Function: Sets the proper variables using the constants above to allow
a successful login.
*******************************************************************************}
procedure declarePlayers();
begin
Login.AddPlayer(LOGIN_NAME, LOGIN_PASS);
end;

{*******************************************************************************
Name: setupAntiban();
Function: Sets up the built-in antiban included with the SRL include.
NOTE: Please feel free to customize this and make it unique to you.
*******************************************************************************}
procedure setupAntiban();
begin

Antiban.AddTask(ONE_MINUTE*5, @Antiban.LoseFocus);
Antiban.AddTask(ONE_MINUTE*10, @Antiban.HoverSkills);
Antiban.AddTask(ONE_MINUTE*10, @Antiban.RandomTab);
//Antiban.AddTask(ONE_MINUTE*25, @Antiban.VeryShortBreak);
//Antiban.AddTask(ONE_MINUTE*25, @Antiban.DoMiscStuff);
//Antiban.AddTask(ONE_MINUTE*45, @Antiban.RandomCompass);

Antiban.AddBreak(35*ONE_MINUTE,05*ONE_MINUTE,0.05, 0.03);
Antiban.AddBreak(02*ONE_HOUR,05*ONE_MINUTE,0.20, 0.85);
Antiban.AddBreak(05*ONE_HOUR,05*ONE_MINUTE,0.85, 0.85);
Antiban.AddBreak(16*ONE_HOUR,05*ONE_MINUTE,0.99, 0.99);
end;

{*******************************************************************************
Name: setUp();
Function: Sets up the script by initializing everything and logging player in.
*******************************************************************************}
function setUp(): boolean;
begin
SRL.Setup(); //Setup SRL to allow us to access it's functions.
Walk.Setup('world'); //Setup RSWalker by initializing the map we want to use
declarePlayers(); //Declare the player we are using
pathToPatch := [[4177, 3463], [4159,3449], [4135, 3436], [4128, 3402], [4121, 3364], [4089, 3335], [4049, 3335], [4024, 3310], [4025, 3288], [4025, 3288]];
setupAntiban(); //Setup our antiban

if not Login.LoginPlayer() then
TerminateScript('Failed to login!');
MainScreen.SetHighestPitch(); //this doesn't actually do anything atm

Result := True;
end;

{*******************************************************************************
Name: myAntiban();
Function: Executes the antiban and checks for random events.
*******************************************************************************}
Procedure myAntiban;
begin
if (not RSClient.IsLoggedIn) then
Exit;

Antiban.DismissRandom(); //Dismiss random events if any are found
Antiban.DoAntiban(); //Do the antiban
end;

{*******************************************************************************
Name: waitLoop();
Function: Waits until we have collected our cabbage
*******************************************************************************}
procedure waitLoop();
var
InvCount: Integer;
T: TStopwatch;
begin
if (not RSClient.IsLoggedIn) then
Exit;

InvCount := Inventory.Count(); //Gets the count in our inventory
T.Start; //Start our timer
repeat
myAntiban();
wait(randomRange(75, 250)); //Wait a random amount of time
until((Inventory.Count() > InvCount) or (T.ElapsedTime > 7000)); //Stop repeating once inv count changes or we time out
end;

{*******************************************************************************
Name: findCabbages();
Function: Locates cabbage in the field. Will print on screen if using SMART.
*******************************************************************************}
procedure findCabbages();
var
TPA, Cabbage: TPointArray;
ATPA: T2DPointArray;
CabbageColor: TCTS2Color;
begin
if (not RSClient.IsLoggedIn) then //If not logged in, then terminate script
TerminateScript;

CabbageColor := CTS2(2727797, 20, 0.05, 1.15);
if (SRL.FindColors(TPA, CabbageColor, MainScreen.Bounds) > 0) then //If we find colours at all then...
begin
ATPA := TPA.Cluster(2); //Group them within a max pixel distance of 2
ATPA.FilterSize(100, 500); //Remove and ATPA of size < 100, or > 500.
ATPA.SortByIndex(MainScreen.Center); //Sort by closest to Middle of the screen

for Cabbage in ATPA do //For every possible cabbage in our ATPA
begin
Mouse.Move(Cabbage[Random(Length(Cabbage))]); //Move the mouse to the cabbage

if MainScreen.IsUpText('Cabbage') then //If the uptext is 'Cabbage', try to click it
begin
Mouse.Click(MOUSE_LEFT);
if (not MainScreen.DidRedClick) then Exit;
waitLoop(); //Call to our waitLoop because we want to wait while picking.
Break;
end;
end;
end;
end;

function manualBank(): boolean;
var
TPA, BankBooth: TPointArray;
ATPA: T2DPointArray;
BankColor: TCTS2Color;
begin
if (not RSClient.IsLoggedIn) then //If not logged in, then terminate script
TerminateScript;

BankColor := CTS2(5527903, 5, 0.71, 0.53);
writeln("Looking for bank via ATPA");
if (SRL.FindColors(TPA, BankColor, MainScreen.Bounds) > 0) then //If we find colours at all then...
begin
writeln("found some potential banks");
ATPA := TPA.Cluster(2); //Group them within a max pixel distance of 2
ATPA.SortByIndex(MainScreen.Center); //Sort by closest to Middle of the screen

for BankBooth in ATPA do //For every possible BankBooth in our ATPA
begin
writeln(BankBooth);
Mouse.Move(BankBooth[Random(Length(BankBooth))]); //Move the mouse to the BankBooth

if MainScreen.IsUpText('Bank booth') then //If the uptext is 'BankBooth', try to click it
begin
Mouse.Click(MOUSE_LEFT);
Result:= True;
Exit;
end;
end;
end;
end;

begin //Main
if setUp then
writeln('We are set up and ready to go!');

repeat
if not Inventory.IsFull then
begin
Writeln("Walking to cabbage patch!");
Walk.WalkPath(pathToPatch);
end

while (not Inventory.IsFull) do
begin
findCabbages(); //Collect Cabbages until inv is full
end

Writeln("Walking to bank!");
Walk.WebWalk(WorldWeb.LOCATION_DRYNOR_BANK); //Walk to Bank

while (not manualBank) do //open bank
begin
Writeln("Trying to open bank");
wait(randomRange(75, 250));
end;

while Bank.IsOpen(5000) do
begin
writeln("trying to deposit");
wait(randomRange(75, 250));
Bank.DepositAll();
wait(randomRange(75, 250));
Bank.Close();
end
until(false);
end.

x0xh3llx0x

2021-12-14 14:14:44

Big thanks for this tutorial! And also thanks to Vizzyy for his post above :)