Ok, so this is far from my first script, but it is my first script in a long time. So I personally need to clear some rust, and thought I might write about it, and the blogging section is gone, so I found either this or the writing section to be appropriate.
Now this is the first time I'd work on a full-scale fighting script, and I'm going to attempt to kill ratz under varrock, a feat I've attempted before, but unfortunately got me banned due to lousy programming. I'll be walking through the very basics to some of the advanced here.
So the first thing I did was grab a basic script set up, and run that to make sure I had everything setup correctly.
Simba Code:
program Ratzer;
{$DEFINE SMART}
{$i SRL/SRL.scar}
Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name :=''; // Copy and paste to add more players
Players[0].Pass :='';
Players[0].Nick :=''; //Used for random events
Players[0].Active:=True;
end;
begin
Smart_Server := 1;
SetupSRL;
DeclarePlayers;
LoginPlayer;
end.
Smart loads up, my player logs in. Perfect, everything is correctly set up with my Simba and etc. IF it didn't happen so, it'd probably be a problem with my java settings, or one of the many other common set up problems.
First thing I noticed was that my graphics were on high definition. I manually changed those to minimum, although I do remember SRL has a function to do so. Next thing I noticed was that my angle on the player is too low. So next thing I do is I'll be adding SetAngle(true) to my script. This will higher the camera's viewpoint.
Okay so now, first things first, I wanna kill rats. Therefore I need the rats' colors. I'm using AutoColorAid2 to grab the colors for my rats. I've placed my character at the rat pits, popped up ACA2, and 'Refreshed from Client'.
I set my ColorToleranceSpeed (CTS) settings to 2, as I find that color finding algorithm to be more effective than CTS 1. I grabbed some colors from the rats' head, body and tail. I notice it catches a bit onto some armour, but the amount is not comparable to the rat, so that should be ok, considering that we can later filter color count.
The result I get is: See Picture

Originally Posted by
ACA2, Rats
BestColor = 6646383
Tol = 13;
Hue = 0.33
Sat = 0.23
Now as I'm lazy and currently just laying the foundations for the script, I'll use ACAs finding function (for now), but I will later make my own. ACAs function looks like this:
Simba Code:
function FindObject(var fx, fy: Integer): Boolean;
var
arP: TPointArray;
ararP: T2DPointArray;
tmpCTS, i, arL: Integer;
P: TPoint;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.33, 0.23);
if not(FindColorsTolerance(arP, 6646383, MSX1, MSY1, MSX2, MSY2, 13)) then
begin
Writeln('Failed to find the color, no object found.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;
SortTPAFrom(arP, Point(MSCX, MSCY));
ararP := SplitTPAEx(arP, 20, 20);
arL := High(ararP);
for i := 0 to arL do
begin
P := MiddleTPA(ararP[i]);
MMouse(P.x, P.y, 5, 5);
Wait(100 + Random(100));
if (IsUpText('iant')) then
begin;
Result := True;
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
if (i = arL + 1) then
begin
Writeln('FindObject could not find object.');
Exit;
end;
GetMousePos(fx, fy);
end;
I renamed it to FindRat. When I re-write this function I'll include a color count, I'll use SplitTPA instead of SplitTPAEx (due to the diff algorithms) and I'll use ColorMouse, a function I made, instead of SRLs MMouse.
Very well, time to find and kill my first Rat.
Simba Code:
Procedure Fight;
var
x, y: integer;
begin
FindRat(x, y);
end;
//Added procedure Fight to Mainloop
Notice: The function from ACA2 would not click - I modified it so it would click.
Okay, tested and it worked. I successfully attacked a rat. Yay for me. Next thing I want to do is gather colors for the drops. I'm ranging so it's extremely important for me that I pickup my arrows.
I got the colors for the bottom end and the stick. ACA recognizes the arrows quite effectively.

Originally Posted by
ACA2, Arrows
Color = 729430;
HSL Tol = 14;
Hue = 0.28;
Sat = 0.19;

Originally Posted by
ACA2, Bones
Color = 10395826;
HSL Tol = 24;
Hue = 0.07;
Sat = 0.39;

Originally Posted by
ACA2, Meat
Color = 729430;
HSL Tol = 9;
Hue = 0.01;
Sat = 0.02;
I gathered the colors both on MS and on inventory as some sort of cross-referencing failsafe. The bones are somewhat troublesome as they also identify as raw rat meat. This might turn out to be a problem later, but hopefully not... perhaps this will be the first time I actually use the NotColors/BadColors algorithm.
Posting, need to pee. - mission accomplished.
The fighting cycle is pretty simple, on its simplest level:
- Find Target
- Attack
- WaitForDeath
- - (Eat)
- Pickup Loot
so a quick Mockup:
Simba Code:
Procedure Fight;
var
x, y: integer;
begin
if FindRat(x,y) then
begin
repeat
wait(500+random(500));
if GetHP < 50 then
if not Eat then
RunAndRest;
until(not srl_InFight)
PickupLoot('All');
end;
end;
Seems pretty simple, no? To add some bones to the skeleton,
Simba Code:
//Gets HP lvl from MM; Function renamed to spare string and shorten code
Function GetHP: integer;
var
color: string;
begin
Result := GetMMLevels('hp', color);
end;
//Function will look for cooked rat meat in inventory and eat it
//mockup
Function Eat: boolean;
begin
Result := False;
end;
//Function runs away from battlefield and rests until HP is restored
Function RunAndRest: boolean;
begin
Result := RunAway('w', true, 2, 100);
if not SetRest then
writeln('trouble resting')
else
repeat
wait(5000);
until(GetHP > 100)
Result := GetHP >= 100;
end;
//Function picks up loot
Function PickupLoot(which: string):boolean;
var
color, tol, arL, i: integer;
h, s: extended;
uptext: string;
TPA: TPointArray;
ATPA: T2DPointArray;
P: TPoint;
begin
writeln('Looting, ' + which);
if (lowercase(which) = 'arrows')and(Players[CurrentPlayer].Skill <> 'range') then
exit;
case lowercase(which) of
'all':
Result := PickupLoot('bones') and
PickupLoot('meat') and
PickupLoot('arrows');
'bones':
begin
color := 10395826;
Tol := 24;
h := 0.07;
s := 0.39;
uptext := 'ones';
end;
'meat':
begin
color := 729430;
Tol := 9;
h := 0.01;
s := 0.02;
uptext := 'eat';
end;
'arrows':
begin
color := 729430;
Tol := 14;
h := 0.28;
s := 0.19;
uptext := 'rrows';
end;
end;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(h, s);
Result := FindColorsSpiralTolerance(MSCX, MSCY, TPA, color, MSX1, MSY1, MSX2, MSY2, Tol);
if not Result then
begin
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
exit;
end;
ATPA := SplitTPAEx(TPA, 20, 20);
arL := High(ATPA);
for i := 0 to arL do
begin
P := MiddleTPA(ATPA[i]);
if ColorMouse(P.x, P.Y,color, tol, uptext) then
begin
Result := True;
writeln(which + ' looted');
Break;
end;
end;
if not lowercase(which) = 'arrows' then
begin
InvC := InvCount;
Result := WaitInvMinCount(InvC + 1, 5000);
end else
wait(3000 + random(2000));
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
Simba Code:
{test log
With the mockup as it is, and a loop on fighting, I am finding this:
1. SRLs inFight relies on your HP bar, which takes a while to disappear
-- Track Enemy Rat, track their HP bar and determine InFight from there (as well)
2. Clicking on rats already under attack
-- Checking for HP Bar Above Rat, exclude these from TPA
-- Checking for 'already under attack' text
3. When running away, gate might be closed
4. Bones Uptext does not show up under meat or other
^^ Your own HP bar will never appear if you kill too quickly at a range
^^ Fix: WaitFunc(@srl_InFight)
^^ Scripts is frenetically clicking on rats, until one of them comes and attacks you
^^ Fix: WaitFunc(@srl_InFight)
}
~RM