SRL Archive - OSR Help

My First Script


SamSatanas

2012-04-22 14:45:30

I am trying to make my first script, from reading tut and videos but I can't seem to get it right. For some reason when I test my script out in Smart, it uses my own mouse.

I am trying to find a goblin and attack it. Also using auto color.


program new;
{$DEFINE SMART}
{$DEFINE SRL5}
{$i SRL/srl.simba}


Procedure FailSafe(Reason:String);
begin
Players[CurrentPlayer].Loc:=Reason;
Logout;
Stats_Commit;
Writeln(Reason);
TerminateScript;
end;

Function GColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.46, 1.12);

if not (FindColorsTolerance(arP, 4097397, MSX1, MSY1, MSX2, MSY2, 15)) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
Result := arC[i];
Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;

Function FindGoblin: Boolean;
var
x, y, TreeCounter, TooLong :Integer;
begin
x := MSCX;
y := MSCY;
If FindObj(x, y, 'oblin', GColor, 10) then
begin
Writeln('We Found a Goblin');
GetMousePos(x, y);
Case Random (2) of
0: Mouse(x, y, 7, 7, True);
1:
begin
Mouse(x, y, 5, 5, False);
WaitOption('ttack', 500)
end;
end;
end;
end;

begin
SetupSRL;
GColor;
FindGoblin;
end.

Thanks Blumblebee and tehq

Blumblebee

2012-04-22 14:50:36

you need to include smart at the top ;)

{$i SRL/SRL/misc/SMART.scar}

needs to be above include SRL.

tehq

2012-04-22 14:55:47

Try to follow these standards in the future. It makes your script much easier to follow :)
(added SMART and SRL5 includes)

program new;
{$DEFINE SMART}
{$DEFINE SRL5}
{$i SRL/srl.simba}


Procedure FailSafe(Reason:String);
begin
Players[CurrentPlayer].Loc:=Reason;
Logout;
Stats_Commit;
Writeln(Reason);
TerminateScript;
end;

Function GColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.46, 1.12);

if not (FindColorsTolerance(arP, 4097397, MSX1, MSY1, MSX2, MSY2, 15)) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
Result := arC[i];
Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;

Function FindGoblin: Boolean;
var
x, y, TreeCounter, TooLong :Integer;
begin
x := MSCX;
y := MSCY;
If FindObj(x, y, 'oblin', GColor, 10) then
begin
Writeln('We Found a Goblin');
GetMousePos(x, y);
Case Random (2) of
0: Mouse(x, y, 7, 7, True);
1:
begin
Mouse(x, y, 5, 5, False);
WaitOption('ttack', 500)
end;
end;
end;
end;

begin
SetupSRL;
GColor;
FindGoblin;
end.