SRL Archive - First Scripts

Lollage22's Autofighter


lollage22

2009-07-13 20:54:38

Well, first post… worked for a while on this one.

This Autofighter fights Flesh Crawlers and giant rats, haven't had the opportunity to test it since SRL needs a revision… it compiles, however, and it worked a few weeks ago. Before publishing, I improved the readability and the procedures. Am I doing things right?

Question 1: I can't get the AntiRandom working. Is including FindNormalRandoms enough? I've done this, and when running I noticed a random. The script did not detect -.-

Question 2: Is there a nicer way to detect food and eat it?

Question 3: Because of lack of AntiRandoms: The Script logs out if no monster is attacked after 10 tries. Is this safe enough?

Question 4: How does DeclarePlayer work? The Script currently assumes that the account is already logged in.

Thanks in advance! :) I will also introduce myself here.


//----------------------------------------------------------------------------//
//-- Lollage Autofighter 1.0 --//
//-- Notes: --//
//-- This AutoFighter is currently tweaked to --//
//-- fleshcrawlers and giant rats. The food that --//
//-- is eaten is salmon. --//
//----------------------------------------------------------------------------//

program New;
{.include SRL/SRL/misc/SMART.scar}
{.include SRL/SRL.scar}
{.Include SRL/SRL/skill/Fighting.scar} //why is that?

{****************************************************************************}

function CheckFood : Integer; // Counts amount of food.
var
p,x,y,Food :Integer;

begin
Food:=0;
for p:= 1 to 28 do
if (findcolortolerance(x,y,7899090, 566+41*(p mod 4), 235+36*trunc(p/4),
570+41*(p mod 4), 239+36*trunc(p/4), 20 {CT} ))
then Food:=Food+1;
writeln('Food left: ' + inttostr(Food));
Result:=Food;
end;


{****************************************************************************}

function EatFood(Food : Integer) : Integer; // Eats food when hp gets low.
var
HPColor : String;
FoodLocation : TPoint;

begin
if (getMMlevels('hp',HPColor)) < (40 + random(5)) then begin
GameTab(4);
FoodLocation:=ItemCoords(Food);
Result:=Food-1;
Mouse(FoodLocation.X, FoodLocation.Y, 2, 3, True);
end
else Result:=Food;
if Food=0 then begin
writeln('Ran out of food: Log Out!');
logout;
exit;
end;
end;

{****************************************************************************}

function FightFoe(FoeColors: array[1..6] of Integer; Foe : Integer) : Boolean;

begin
if(FightNPC(FoeColors, 5, 1000)) then begin
if InFight then begin
Foe:=Foe+1;
writeln('Foe number: '+ inttostr(Foe));
wait(200+random(800));
Result:=True;
end
else Result:=False;
end;
end;

{****************************************************************************}

procedure AntiBanThing;

begin
if random(500)=5 then begin
case random(3)+1 of
1:RandomRClick;
2:HoverSkill('Strength', False);
3:RandomMovement;
end;
end;
end;

{****************************************************************************}

var
FoeColors: array[1..6] of Integer;
Food,CountFoe,FailChecker : Integer;

begin //Main Loop.

//Setting up SMART and SRL
SMARTSetUpEX(55, False, True, False);
SetTargetDC(SMARTGetDC);
SetupSRL;

//Defining all kinds of values
FoeColors[1] := 8814987 ; //Pick 6 colors of the foes you want to fight.
FoeColors[2] := 8950675 ;
FoeColors[3] := 8950675;
FoeColors[4] := 5594201 ;
FoeColors[5] := 8814987;
FoeColors[6] := 5594201 ;

MouseSpeed:= 25;
CountFoe:=0; // Counting Foes killed.
FailChecker:=0; // Goes up when no foe is found.
wait(2000);

Food:=CheckFood;
SetRun(True);

repeat
if not InFight then begin

FindNormalRandoms;
FailChecker:=FailChecker+1

if FightFoe(FoeColors, CountFoe) then begin
FailChecker:=0;
CountFoe:= CountFoe+1;
end;

Food:=EatFood(Food);
end;
wait(200+random(800));
AntiBanThing;
if FailChecker=10 then begin
writeln('Cant attack! Log Out...');
logout;
exit;
end;


until false;


end.

Home

2009-07-14 01:57:30

Well The Declareplayers is why you antirandoms doesn't work :)
Use this:

[PHP]procedure DeclarePlayers;
begin
HowManyPlayers := 1; // Set Number of Players here.
NumberOfPlayers(HowManyPlayers); // Sets the Players Array Length;
CurrentPlayer := 0; // CurrentPlayer = Array Index

Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := ''; // Few letters From Your Name.

Players[0].BoxRewards := ['mote', 'ostume', 'Gem', 'ithril', 'oal', 'une', 'XP', 'oins'];

Players[0].Active := True; // If You use This Player Set True.

end;[/PHP]

And detecting food you can always use DTM's :)


~Home

ian.

2009-07-14 02:03:17

From: Home
Well The Declareplayers is why you antirandoms doesn't work :)
Use this:

[PHP]procedure DeclarePlayers;
begin
HowManyPlayers := 1; // Set Number of Players here.
NumberOfPlayers(HowManyPlayers); // Sets the Players Array Length;
CurrentPlayer := 0; // CurrentPlayer = Array Index

Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := ''; // Few letters From Your Name.

Players[0].BoxRewards := ['mote', 'ostume', 'Gem', 'ithril', 'oal', 'une', 'XP', 'oins'];

Players[0].Active := True; // If You use This Player Set True.

end;[/PHP]

And detecting food you can always use DTM's :)


~Home


Or bitmaps. ;) They're faster.

Coh3n

2009-07-14 07:29:46

From: lollage22

Question 2: Is there a nicer way to detect food and eat it?

Question 3: Because of lack of AntiRandoms: The Script logs out if no monster is attacked after 10 tries. Is this safe enough?


2. I would suggest using Bitmaps/DTMs and then use FindColorTolerance as a failsafe (although if you do it right, you probably won't need it). You can just have it check the player's heath (like you already do) then use Bitmap/DTM finding to find/eat the food.

3. I would do more than 10 tries, maybe 20? I would also add in a couple failsafes of maybe some MM walking to a different spot if it can't find the monster(s).
________________________________________________________________________________________________

Overall, I think it's good for a first script. I would like to see you do more failsafes and learn more about SRL if you are going to continue making RS script. This is one of the better first scripts that I've seen in a while, and for a first post, well done! ;)

Keep up the good work, if you have any questions, don't hesitate to ask. Also, if you're having trouble running any scripts (like you said in the first post), you can use my guide (link in signature) to get SCAR 3.21, and you should be all set.

Cheers. :)

lollage22

2009-07-14 14:01:41

Thanks for the good feedback!

1) The 10 tries is an empirical chosen number. However, when AntiRandom works, this shouldn't be necessary anymore.

2) What is "failsafe"? In the literary sense of the word i get it, but are there any conventional routines? - I guess there is some tut about this. Ill search it. Before posting, this script has run for some weeks. It doesn't stay online all the time, but i could have a nap or two and come back to see my account being logged out. Done between 10-50 k xp.

3) Bitmaps/DTM. Red about them in the forums, but don't exactly know what they are… maybe there's a tut, or ill ask in IRC :)

When some things are worked out, I'll get a 1.1 version here. Thanks again!

ian.

2009-07-14 15:18:04

From: lollage22
Thanks for the good feedback!

1) The 10 tries is an empirical chosen number. However, when AntiRandom works, this shouldn't be necessary anymore.

2) What is "failsafe"? In the literary sense of the word i get it, but are there any conventional routines? - I guess there is some tut about this. Ill search it. Before posting, this script has run for some weeks. It doesn't stay online all the time, but i could have a nap or two and come back to see my account being logged out. Done between 10-50 k xp.

3) Bitmaps/DTM. Red about them in the forums, but don't exactly know what they are… maybe there's a tut, or ill ask in IRC :)

When some things are worked out, I'll get a 1.1 version here. Thanks again!


1. Whatever works, I suppose. ;) Better methods will be available once you understand more.

2. A failsafe is something to make it safe to use the script if some part fails, kinda. It will fix itself, basically. :)

3. A bitmap is a picture. You just look on RS for a picture. ^^ Deformable Template Models (DTM's) are used a lot like bitmaps in SCAR. Basically they compare colors, and depending on what colors are found and how far away from each other they are, the DTM will return a boolean. If the boolean is True, it will record its position. The position recorded is the coordinates of the parent dot. The parent dot is the first point selected when making the DTM. The positions of the other points are relative to the parent dot. (From the SRL Wiki ;) http://www.villavu.com/wiki/index.php/Finding_DTM's)

Hope that helps.

BobboHobbo

2009-07-14 15:43:37

A more accurate approach to find how much food you have in your inventory would be to use this:

function CountItemDTM(DTM: Integer): Integer;
var
i, x, y: Integer;
TB: Tbox;
begin
GameTab(4);
for i := 1 to 28 do
begin
TB := InvBox(i);
if ExistsItem(i) then
if FindDTM(DTM, x, y, TB.x1, TB.y1, TB.x2, TB.y2) then
Inc(Result);
end;
end;

Read how to make DTM's, then use this procedure to read the amount of Salmons or whatever your trying to find.

How to Use:

function CheckFood : Integer; // Counts amount of food.
begin
Result := CountItemDTM(salmon);
Writeln('Food Left' +IntToStr(Result));
end;

Good Job and goodluck.

Coh3n

2009-07-14 17:55:11

From: lollage22
Thanks for the good feedback!

When some things are worked out, I'll get a 1.1 version here. Thanks again!


No problem! :D Glad I could help, and your questions seem to be answered. :p

Can't wait to read the new version. :) Good luck.

Cheers.