SRL Archive - General

RS06 Eating


1xp

2013-02-15 10:43:56

I am quite new to the pascal language but Ive been messing around with the code and I was wondering if there was anything included in the RS06 include that I could use to add eating to some of these multifighter scripts and if so how could i integrate it like defining the variables etc. Thanks! I hope to get some feed back soon (:

Ian

2013-02-15 11:50:50

The best way to add eating would be to make a DTM of the food you want to eat and then search the inventory for it. As for adjusting the script for it, put the food checking and eating in the loop that it goes into while fighting. This will be slightly different for each script.

1xp

2013-02-15 13:44:46

Thanks ill try it tonight!

1xp

2013-02-15 15:14:19

Here is the code I am adding to



Program AutoFighter;
{$I SRL/SRL.Simba}
{$I SRL/SRL/Misc/Debug.Simba}
{$I P06Include/P06Include.Simba}
{$DEFINE SMART}
var
Col_Monster, Tol_Monster,C_Color,C_Tol,XpKill,XpGained,MonsterKilled, EatFood, x ,y:Integer;
Uptext_1, Uptext_2, Uptext_3, Status,MonsterKill,Message_1,Message_2:String;
C_Uptext_1, C_Uptext_2, C_Uptext_3, TalkRand,Message_3,Message_4:String;
Seconds,StartTime,C_XpKill,XpPerHour,KillsPerHour,TimeOut:Integer;
Hue_Monster,Sat_Monster,C_Hue,C_Sat:Extended;
Message_5:String;


Procedure DeclareVariables;
Begin


{*****************************************************************}
{****************Declare the monster you want to kill.************}
{*********************Valid options are:**************************}
{**********spider,globin,cow,darkwizzard,guard,custom.************}
{Choose defualt timeout if bot detects you in combatwhen your not*}
{*****************************************************************}

MonsterKill := 'guard';
TimeOut := 15;


{****************************************************************}
{********************Type yes to Talk randomly*******************}
{****************************************************************}

TalkRand := 'Yes';


{****************************************************************}
{*****************Fill in random messages here*******************}
{****************************************************************}

Message_1 := '';
Message_2 := '';
Message_3 := '';
Message_4 := '';
Message_5 := '';


{****************************************************************}
{****If the monster you want to kill is not listed use custom****}
{************Fill in the info using ACA(Auto Color Aid)**********}
{****************************************************************}

C_Color := 0;
C_Hue := 0;
C_Sat := 0;
C_Tol := 0;
C_XpKill := 0;
C_Uptext_1 := '';
C_Uptext_2 := '';
C_Uptext_3 := '';

{****************************************************************}
{*********End of User setup, Don't touch below this line*********}
{****************************************************************}


End;
Procedure WriteProgress;
Begin
Seconds := (1 + ((Getsystemtime - StartTime) / 1000));
XpPerHour := (3600 * XPGained) / (Seconds);
KillsPerHour := (3600 * MonsterKilled) / Seconds;

ClearDebug;
Writeln('*************************');
Writeln('Time Running:' + TimeRunning + '');
Writeln('Status:' + Status + '');
Writeln('Monsters killed:' + IntToStr(MonsterKilled) + '' );
writeLn('Kills Per Hour: ' + IntToStr(KillsPerHour) + '');
Writeln('XP Gained:' + IntToStr(XpGained) + '');
writeLn('Combat XP/H: ' + IntToStr(XpPerHour) + '');
Writeln('*************************');
End;
Procedure EatFood;
begin;
EatFood:= DTMFromString('mLgAAAHicY2JgYChlYmAIB+KnQPYdIN6dLMpgoKDAwMUAAYxQzMAAAIIZBEM=');
SetupSRL;
FindDTM(EatFood, x, y, MIX1, MIY1, MIX2, MIY2);
MMouse(x, y, 0, 0);
FreeDTM(EatFood);
end;
end;
Procedure RandomTalk;
Begin
if TalkRand = 'Yes' then
Begin
case random(1000) of
1: TypeSend(''+ Message_1 + '');
2: TypeSend(''+ Message_2 + '');
3: TypeSend(''+ Message_3 + '');
4: TypeSend(''+ Message_4 + '');
5: TypeSend(''+ Message_5 + '');
End;
End;
End;
Function CheckHP(SearchArea: TBox): TPointArray;
var
T: TPoint;
H, I: integer;
Colors: TIntegerArray;
ATPA: T2DPointArray;
begin
Colors := [HP_BAR_COLOR1, HP_BAR_COLOR2];
H := High(Colors);
SetArrayLength(ATPA, H+1);
T := point((MFBox.x2+MFBox.x1) div 2,(MFBox.y2+MFBox.y1) div 2);
for i := 0 to H do
with SearchArea do
FindColorsSpiralTolerance(T.x, T.y, ATPA[i], Colors[i], X1, Y1, X2, Y2, 2);
Result := MergeATPA(ATPA);
end;
Function srl_IsFighting: Boolean;
begin
Result := InRange(Length(CheckHP(MFBox)), 30, 240);
end;
Function IsFighting: Boolean;
var
PBox: TBox;
Begin
PBox := IntToBox(238, 169, 279, 217);
Result := (AveragePixelShift(PBox, 250, 350) > 15);
//Writeln(IntToStr(AveragePixelShift(PBox, 500, 650)));
Begin
CheckHP(MFBox);
EatFood;
end;

End;
Function Attack: Boolean;
Var
tmpCTS,i, L,Counter,Fighter: Integer;
ObjTPA: TPointArray;
ObjATPA: T2DPointArray;
X,Y,DMCount,Moves: Integer;
Begin
Moves:=0;
DMCount:=0;

tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);

SetToleranceSpeed2Modifiers(Hue_Monster, Sat_Monster);
FindColorsTolerance(ObjTPA, Col_Monster, 1, 1, 514, 338, Tol_Monster);
SplitTPAWrap(ObjTPA, 10, ObjATPA);

SortATPASize(ObjATPA,True);
SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);

DMCount:=RandomRange(3,5);
L := High(ObjATPA)
MarkTime(Counter);
For i := 0 To L Do
Begin
MiddleTPAEx(ObjATPA[i], X, Y);
Repeat Begin
Moves:=Moves+1;
mmouse(x, y, 1, 1);
Status := ('Looking for ' + MonsterKill + 's')
WriteProgress;
Wait(RandomRange(400, 500));
If (P06_IsUpTextMultiCustom([''+Uptext_1,''+Uptext_2,''+ Uptext_3])) Then
Begin
clickmouse2(mouse_Left);
Wait(RandomRange(800, 1200));
Status := ('Fighting ' + MonsterKill +'s')
WriteProgress;
While IsFighting do
Wait(RandomRange(400, 800));
MarkTime(Fighter);
If not IsFighting then
Begin
if (TimeFromMark(Fighter) > 1000) then
Begin
if not IsFighting then
Begin
Break;
End;
End;
if (TimeFromMark(Fighter) > TimeOut) then
Begin
Break;
End;
End;
IncEx(XPGained, XpKill);
IncEx(MonsterKilled, 1);
Exit;
End;
End; Until (Moves > DMCount)
If (TimeFromMark(Counter) > 5000) Then
Begin
Break;
End;
End;
Result:=False;
End;
Procedure SetKill;
Begin
Case LowerCase(MonsterKill) Of
'goblin':
Begin
Col_Monster := 7186324;
Hue_Monster := 0.03;
Sat_Monster := 0.72;
Tol_Monster := 9;
XpKill := 10;
Uptext_1 := 'Attack Go';
Uptext_2 := 'ttack Gob';
Uptext_3 := 'ack Globin';
end;
'spider':
Begin
Col_Monster := 345172;
Hue_Monster := 0.02;
Sat_Monster := 1.63;
Tol_Monster := 7;
XpKill := 10;
Uptext_1 := 'Attack Sp';
Uptext_2 := 'ttack Spi';
Uptext_3 := 'ack Spider';
End;
'cow':
Begin
Col_Monster := 2246755;
Hue_Monster := 0.09;
Sat_Monster := 0.55;
Tol_Monster := 7;
XpKill := 10;
Uptext_1 := 'Attack Cow';
Uptext_2 := 'ttack Cow';
Uptext_3 := 'ack Cow';
End;
'darkwizzard':
Begin
Col_Monster := 2505017;
Hue_Monster := 0.00;
Sat_Monster := 0.48;
Tol_Monster := 3;
XpKill := 10;
Uptext_1 := 'Attack Da';
Uptext_2 := 'ttack Dark';
Uptext_3 := 'ack Dark';
End;
'guard':
Begin
Col_Monster := 990868;
Hue_Monster := 0.05;
Sat_Monster := 0.62;
Tol_Monster := 3;
XpKill := 10;
Uptext_1 := 'Attack Gu';
Uptext_2 := 'ttack Gua';
Uptext_3 := 'ack Guard';
End;
'custom':
Begin
Col_Monster := C_COLOR;
Hue_Monster := C_HUE;
Sat_Monster := C_SAT;
Tol_Monster := C_TOL;
XpKill := C_XpKill;
Uptext_1 := C_UPTEXT_1;
Uptext_2 := C_UPTEXT_2;
Uptext_3 := C_UPTEXT_3;
End;
End;
End;
Begin
SetupSRL;
SetupP06Include;
MouseSpeed := 20;
ActivateClient;
DeclareVariables;
StartTime := GetSystemTime;
SetKill;
Attack;
Repeat
Attack;
Until False;
End.
{
MR HYDE
COL 5337207
TOL 3
HUE MOD 0.20
SAT MOD 0.21
}
{
Drunken Dwarf
Col - 1547472
Tol - 0
hue 0.00
Sat 0.00
}

When I compile It says Duplicate Identifier on this procedure

Procedure EatFood;
begin
EatFood:= DTMFromString('mLgAAAHicY2JgYChlYmAIB+KnQPYdIN6dLMpgoKDAwMUAAYxQzMAAAIIZBEM=');
SetupSRL;
FindDTM(EatFood, x, y, MIX1, MIY1, MIX2, MIY2);
MMouse(x, y, 0, 0);
FreeDTM(EatFood);
end;

Ian

2013-02-15 15:39:49

You can remove the SetupSRL; from the eating procedure, because it was already called at the beginning of the script.

Your procedure is called "EatFood", but you also declared your DTM as "EatFood". They need to be different because Simba already recognizes the procedure as EatFood. I'd recommend naming the DTM "SalmonDTM" or "TunaDTM" because then you remember that:
A)It's a DTM
B)It's a DTM for Salmon (or whatever food it is)

You should also declare these as local variables, unless you need to use SalmonDTM elsewhere in the script.

You can declare local variables like this example (I also added some things which I'll explain):


procedure EatFood;
var // This tells the script that the following line is variables.
SalmonDTM, x, y:Integer; //DTMs and coordinates are stored as Integers.
begin
SalmonDTM := kvokdsjkojwoif0i2b; //I just hit the keyboard, this isn't an actual DTM
WriteLn('Looking for Food');//Add these throughout the script to help you pinpoint problems
if FindDTM(...) then //Put your DTM info in the "..."
begin
MMouse(x, y, 0, 0);
WriteLn('Found the Food'); //More problem pinpointing stuff
end;
FreeDTM(SalmonDTM); //Frees the DTM
end;

1xp

2013-02-15 17:15:02

Thanks Mate! It now compiles just fine. Although I'm having an issue with it clicking the guards to attack them

heres the updated code:
Program AutoFighter;
{$I SRL/SRL.Simba}
{$I SRL/SRL/Misc/Debug.Simba}
{$I P06Include/P06Include.Simba}
{$DEFINE SMART}
var
Col_Monster, Tol_Monster,C_Color,C_Tol,XpKill,XpGained,MonsterKilled:Integer;
Uptext_1, Uptext_2, Uptext_3, Status,MonsterKill,Message_1,Message_2:String;
C_Uptext_1, C_Uptext_2, C_Uptext_3, TalkRand,Message_3,Message_4:String;
Seconds,StartTime,C_XpKill,XpPerHour,KillsPerHour,TimeOut:Integer;
Hue_Monster,Sat_Monster,C_Hue,C_Sat:Extended;
Message_5:String;
Procedure DeclareVariables;
Begin


{*****************************************************************}
{****************Declare the monster you want to kill.************}
{*********************Valid options are:**************************}
{**********spider,globin,cow,darkwizzard,guard,custom.************}
{Choose defualt timeout if bot detects you in combatwhen your not*}
{*****************************************************************}

MonsterKill := 'guard';
TimeOut := 15;


{****************************************************************}
{********************Type yes to Talk randomly*******************}
{****************************************************************}

TalkRand := 'Yes';


{****************************************************************}
{*****************Fill in random messages here*******************}
{****************************************************************}

Message_1 := '';
Message_2 := '';
Message_3 := '';
Message_4 := '';
Message_5 := '';


{****************************************************************}
{****If the monster you want to kill is not listed use custom****}
{************Fill in the info using ACA(Auto Color Aid)**********}
{****************************************************************}

C_Color := 0;
C_Hue := 0;
C_Sat := 0;
C_Tol := 0;
C_XpKill := 0;
C_Uptext_1 := '';
C_Uptext_2 := '';
C_Uptext_3 := '';

{****************************************************************}
{*********End of User setup, Don't touch below this line*********}
{****************************************************************}
End;
Procedure WriteProgress;
Begin
Seconds := (1 + ((Getsystemtime - StartTime) / 1000));
XpPerHour := (3600 * XPGained) / (Seconds);
KillsPerHour := (3600 * MonsterKilled) / Seconds;

ClearDebug;
Writeln('*************************');
Writeln('Time Running:' + TimeRunning + '');
Writeln('Status:' + Status + '');
Writeln('Monsters killed:' + IntToStr(MonsterKilled) + '' );
writeLn('Kills Per Hour: ' + IntToStr(KillsPerHour) + '');
Writeln('XP Gained:' + IntToStr(XpGained) + '');
writeLn('Combat XP/H: ' + IntToStr(XpPerHour) + '');
Writeln('*************************');
End;
Procedure EatFood;
var // This tells the script that the following line is variables.
LobbyDTM, x, y:Integer; //DTMs and coordinates are stored as Integers.
begin
LobbyDTM :=DTMFromString('mQwAAAHicY2ZgYPBkYmDwg+InQP4NIL4DxJviRYEkI4OokBADFwMCMCJhIAAA5WUE9A=='); //I just hit the keyboard, this isn't an actual DTM
WriteLn('Looking for Food');//Add these throughout the script to help you pinpoint problems
if FindDTM(LobbyDTM,x, y,1, 1, 200, 200) then //Put your DTM info in the "..."
begin
MMouse(x, y, 0, 0);
WriteLn('Found the Food'); //More problem pinpointing stuff
end;
FreeDTM(LobbyDTM); //Frees the DTM
end;

Procedure RandomTalk;
Begin
if TalkRand = 'Yes' then
Begin
case random(1000) of
1: TypeSend(''+ Message_1 + '');
2: TypeSend(''+ Message_2 + '');
3: TypeSend(''+ Message_3 + '');
4: TypeSend(''+ Message_4 + '');
5: TypeSend(''+ Message_5 + '');
End;
End;
End;
Function CheckHP(SearchArea: TBox): TPointArray;
var
T: TPoint;
H, I: integer;
Colors: TIntegerArray;
ATPA: T2DPointArray;
begin
Colors := [HP_BAR_COLOR1, HP_BAR_COLOR2];
H := High(Colors);
SetArrayLength(ATPA, H+1);
T := point((MFBox.x2+MFBox.x1) div 2,(MFBox.y2+MFBox.y1) div 2);
for i := 0 to H do
with SearchArea do
FindColorsSpiralTolerance(T.x, T.y, ATPA[i], Colors[i], X1, Y1, X2, Y2, 2);
Result := MergeATPA(ATPA);
end;
Function IsFighting: Boolean;
var
PBox: TBox;
Begin
PBox := IntToBox(238, 169, 279, 217);
Result := (AveragePixelShift(PBox, 250, 350) > 15);
//Writeln(IntToStr(AveragePixelShift(PBox, 500, 650)));
Begin
CheckHP(MFBox);
EatFood;
end;

End;
Function Attack: Boolean;
Var
tmpCTS,i, L,Counter,Fighter: Integer;
ObjTPA: TPointArray;
ObjATPA: T2DPointArray;
X,Y,DMCount,Moves: Integer;
Begin
Moves:=0;
DMCount:=0;

tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);

SetToleranceSpeed2Modifiers(Hue_Monster, Sat_Monster);
FindColorsTolerance(ObjTPA, Col_Monster, 1, 1, 514, 338, Tol_Monster);
SplitTPAWrap(ObjTPA, 10, ObjATPA);

SortATPASize(ObjATPA,True);
SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);

DMCount:=RandomRange(3,5);
L := High(ObjATPA)
MarkTime(Counter);
For i := 0 To L Do
Begin
MiddleTPAEx(ObjATPA[i], X, Y);
Repeat Begin
Moves:=Moves+1;
mmouse(x, y, 1, 1);
Status := ('Looking for ' + MonsterKill + 's')
WriteProgress;
Wait(RandomRange(400, 500));
If (P06_IsUpTextMultiCustom([''+Uptext_1,''+Uptext_2,''+ Uptext_3])) Then
Begin
clickmouse2(mouse_Left);
Wait(RandomRange(800, 1200));
Status := ('Fighting ' + MonsterKill +'s')
WriteProgress;
While IsFighting do
Wait(RandomRange(400, 800));
MarkTime(Fighter);
If not IsFighting then
Begin
if (TimeFromMark(Fighter) > 1000) then
Begin
if not IsFighting then
Begin
Break;
End;
End;
if (TimeFromMark(Fighter) > TimeOut) then
Begin
Break;
End;
End;
IncEx(XPGained, XpKill);
IncEx(MonsterKilled, 1);
Exit;
End;
End; Until (Moves > DMCount)
If (TimeFromMark(Counter) > 5000) Then
Begin
Break;
End;
End;
Result:=False;
End;
Procedure SetKill;
Begin
Case LowerCase(MonsterKill) Of
'goblin':
Begin
Col_Monster := 7186324;
Hue_Monster := 0.03;
Sat_Monster := 0.72;
Tol_Monster := 9;
XpKill := 10;
Uptext_1 := 'Attack Go';
Uptext_2 := 'ttack Gob';
Uptext_3 := 'ack Globin';
end;
'spider':
Begin
Col_Monster := 345172;
Hue_Monster := 0.02;
Sat_Monster := 1.63;
Tol_Monster := 7;
XpKill := 10;
Uptext_1 := 'Attack Sp';
Uptext_2 := 'ttack Spi';
Uptext_3 := 'ack Spider';
End;
'cow':
Begin
Col_Monster := 2246755;
Hue_Monster := 0.09;
Sat_Monster := 0.55;
Tol_Monster := 7;
XpKill := 10;
Uptext_1 := 'Attack Cow';
Uptext_2 := 'ttack Cow';
Uptext_3 := 'ack Cow';
End;
'darkwizzard':
Begin
Col_Monster := 2505017;
Hue_Monster := 0.00;
Sat_Monster := 0.48;
Tol_Monster := 3;
XpKill := 10;
Uptext_1 := 'Attack Da';
Uptext_2 := 'ttack Dark';
Uptext_3 := 'ack Dark';
End;
'guard':
Begin
Col_Monster := 990868;
Hue_Monster := 0.05;
Sat_Monster := 0.62;
Tol_Monster := 3;
XpKill := 10;
Uptext_1 := 'Attack Gu';
Uptext_2 := 'ttack Gua';
Uptext_3 := 'ack Guard';
End;
'custom':
Begin
Col_Monster := C_COLOR;
Hue_Monster := C_HUE;
Sat_Monster := C_SAT;
Tol_Monster := C_TOL;
XpKill := C_XpKill;
Uptext_1 := C_UPTEXT_1;
Uptext_2 := C_UPTEXT_2;
Uptext_3 := C_UPTEXT_3;
End;
End;
End;
Begin
SetupSRL;
SetupP06Include;
MouseSpeed := 20;
ActivateClient;
DeclareVariables;
StartTime := GetSystemTime;
SetKill;
Attack;
CheckHP(MFBox);
EatFood;
Repeat
Attack;
CheckHP(MFBox);
EatFood;
Until False;
End.
{
MR HYDE
COL 5337207
TOL 3
HUE MOD 0.20
SAT MOD 0.21
}
{
Drunken Dwarf
Col - 1547472
Tol - 0
hue 0.00
Sat 0.00
}

Echo_

2013-02-15 17:51:40

This shouldn't be in the programming section…

Ian

2013-02-15 18:15:09

From: 1xp
Thanks Mate! It now compiles just fine. Although I'm having an issue with it clicking the guards to attack them


Make sure you chose the right colors,the right tolerances, the right hues, the right saturation ect. I'm sure Rjj would have said how in the script thread.
You'll need to ask Rjj about that one, he knows more about how the attacking works because he made the script :)

And like Echo_ said, for future reference, scripting help questions should be placed in the Scripting Help Section :)

1xp

2013-02-15 18:40:11

ok thanks!

rj

2013-02-16 21:05:32

I'm updating this ATM to eat to make it much easrier to use with a Tform, thanks to chris filling out the bot info will look something like this:


Ian

2013-02-16 21:17:33

From: rjj95
I'm updating this ATM to eat to make it much easrier to use with a Tform, thanks to chris filling out the bot info will look something like this:



Eww comic sans :p

I'd suggest making the boxes line up it would look nicer :)

rj

2013-02-16 21:25:00

From: BMWxi
Eww comic sans :p

I'd suggest making the boxes line up it would look nicer :)


Doing atm, also adding custom DTM options, and option of a cord to click incase out of food

EDIT: Unless there is a different form designer.. this probably won't happen: