SRL Archive - Help

Detecting when hp is low? [On Private Server]


Pew

2012-12-25 02:21:35

Pretty much I'm trying to make a bot that will click on the master farmer until it detects that the hp bar is at a certain % then eat some food.

This script ran fine when using until a certain number of clicks but when I tried to change the until it detects red (255) at a certain spot it doesn't work. I'm sure there are many other ways to go about this but I only started trying to code yesterday.

This is a 2006 remake so it doesn't have hp displayed on the minimap only in stats and the preset commands in library are mostly too updated and do not work.

Any insight at all it greatly appreciated.

//Start South of master farmer facing North with camera highest.
program new;
{$define srl5}
{$i srl/srl.simba}

var
x, y, i, o: Integer;

procedure Thieve;
var
numberOfWaits: Integer;
begin
repeat
If FindColorTolerance(x, y, 8620429, 242, 115, 283, 151, 5) then
begin
Mouse(x, y, 4, 4, true);
end else
begin
WriteLn('Farmer not found!');
end;
Wait(10 + Random(1500));
Inc(numberOfWaits); // The Inc() command simply increases the var numberOfWaits by 1
WriteLn('We have waited ' + IntToStr(numberOfWaits) + ' times');
until(FindcolorTolerance(i, o, 255, 270, 146, 271, 148, 1));
end;


begin
SetUpSRL;
Thieve;
end.


rj

2012-12-25 15:00:55

Try looking for a dtm that is like 10 pixels across but others people's ho bar will interupt

tiggerred

2012-12-25 15:47:18

Pew I pmed you check it out

Sin

2012-12-25 17:27:40

HPPercent?

Gucci

2012-12-25 18:11:36

From: Shay
HPPercent?


It's private server, also doesn't that look for the health bar next to the minimap?

btw come onto skype

Wardancer

2012-12-26 14:57:13

Would a simple well placed FindColorTolerance work? I'm imagining an hp bar lowering.

doxin

2012-12-26 16:29:44

does he only do 1 damage? if so, you could make a bitmap of your hp down to like, 20, in the stats tab. then have the script check your hp in the stats tab after every time you thieve. then if it finds your bitmap it would eat food. idk if thats complicated but that's what i would do..

EDIT:
like this
//Start South of master farmer facing North with camera highest.
program new;
{$define srl5}
{$i srl/srl.simba}

var
x, y, i, o: Integer;

procedure Thieve;
var
numberOfWaits, hpislow: Integer;
begin
hpislow := // your bitmap of low hp in the stats tab here
repeat
If FindColorTolerance(x, y, 8620429, 242, 115, 283, 151, 5) then
begin
Mouse(x, y, 4, 4, true);
Wait(1000+random1000);
Mouse(585, 186, 2, 2, true); //clicks the stats tab. fix the coordinates
if FindBitmapIn(hpislow, x, y, 616, 196, 684, 247) then
EatFood; //don't forget to make a procedure like this
Wait(500+random(500));
end else
begin
WriteLn('Farmer not found!');
end;
Wait(10 + Random(1500));
Inc(numberOfWaits); // The Inc() command simply increases the var numberOfWaits by 1
WriteLn('We have waited ' + IntToStr(numberOfWaits) + ' times');
until(FindcolorTolerance(i, o, 255, 270, 146, 271, 148, 1));
end;


begin
SetUpSRL;
Thieve;
end.

Pew

2012-12-26 20:46:02

Thanks heaps! That was my thought process but I didn't know how to go about it.

Gucci

2012-12-26 20:54:52

From: Pew
Thanks heaps! That was my thought process but I didn't know how to go about it.


Don't forget to free the bitmap as doxin didn't include that in his example

DannyRS

2012-12-26 20:57:55

From: Gucci
Don't forget to free the bitmap as doxin didn't include that in his example


did i fix it correctly? doublecheck for me

//Start South of master farmer facing North with camera highest.
program new;
{$define srl5}
{$i srl/srl.simba}

var
x, y, i, o: Integer;

procedure Thieve;
var
numberOfWaits, hpislow: Integer;
begin
hpislow := // your bitmap of low hp in the stats tab here
repeat
If FindColorTolerance(x, y, 8620429, 242, 115, 283, 151, 5) then
begin
Mouse(x, y, 4, 4, true);
Wait(1000+random1000);
Mouse(585, 186, 2, 2, true); //clicks the stats tab. fix the coordinates
if FindBitmapIn(hpislow, x, y, 616, 196, 684, 247) then
EatFood; //don't forget to make a procedure like this
Wait(500+random(500));
end else
begin
WriteLn('Farmer not found!');
end;
Wait(10 + Random(1500));
Inc(numberOfWaits); // The Inc() command simply increases the var numberOfWaits by 1
WriteLn('We have waited ' + IntToStr(numberOfWaits) + ' times');
until(FindcolorTolerance(i, o, 255, 270, 146, 271, 148, 1));
end;

Procedure FreeMyStuff;
begin
FreeBitmap(hpislow);
end;

begin
AddOnTerminate('FreeMyStuff');
SetUpSRL;
Thieve;
end.

Gucci

2012-12-26 21:55:39

From: DannyRS
did i fix it correctly? doublecheck for me

//Start South of master farmer facing North with camera highest.
program new;
{$define srl5}
{$i srl/srl.simba}

var
x, y, i, o: Integer;

procedure Thieve;
var
numberOfWaits: Integer;
begin
hpislow := //stuff
repeat
If FindColorTolerance(x, y, 8620429, 242, 115, 283, 151, 5) then
begin
Mouse(x, y, 4, 4, true);
Wait(1000+random1000);
Mouse(585, 186, 2, 2, true); //clicks the stats tab. fix the coordinates
if FindBitmapIn(hpislow, x, y, 616, 196, 684, 247) then
EatFood; //don't forget to make a procedure like this
Wait(500+random(500));
end else
begin
WriteLn('Farmer not found!');
end;
Wait(10 + Random(1500));
Inc(numberOfWaits); // The Inc() command simply increases the var numberOfWaits by 1
WriteLn('We have waited ' + IntToStr(numberOfWaits) + ' times');
until(FindcolorTolerance(i, o, 255, 270, 146, 271, 148, 1));
end;

Procedure FreeMyStuff;
begin
FreeBitmap(hpislow);
end;

begin
AddOnTerminate('FreeMyStuff');
SetUpSRL;
Thieve;
end.


Yeah that'll work but since he declared it locally you'll probably want to free it locally. But for that script since it will be used a lot I would declare and free it globally, so basically I would do what you did Danny.

//Start South of master farmer facing North with camera highest.
program new;
{$define srl5}
{$i srl/srl.simba}

var
x, y, i, o, hpislow: Integer;


procedure DeclareThings;
begin
hpislow := //stuff here;
end;

procedure Thieve;
var
numberOfWaits: Integer;
begin
repeat
If FindColorTolerance(x, y, 8620429, 242, 115, 283, 151, 5) then
begin
Mouse(x, y, 4, 4, true);
Wait(1000+random1000);
Mouse(585, 186, 2, 2, true); //clicks the stats tab. fix the coordinates
if FindBitmapIn(hpislow, x, y, 616, 196, 684, 247) then
EatFood; //don't forget to make a procedure like this
Wait(500+random(500));
end else
begin
WriteLn('Farmer not found!');
end;
Wait(10 + Random(1500));
Inc(numberOfWaits); // The Inc() command simply increases the var numberOfWaits by 1
WriteLn('We have waited ' + IntToStr(numberOfWaits) + ' times');
until(FindcolorTolerance(i, o, 255, 270, 146, 271, 148, 1));
end;

Procedure FreeMyStuff;
begin
FreeBitmap(hpislow);
end;

begin
SetUpSRL;
DeclareThings;
Thieve;
AddOnTerminate('FreeMyStuff');
end.