SRL Archive - SRL Archives

Smithing.scar ~ FindBar


Rich

2008-12-08 14:54:36

{*******************************************************************************
function FindBar(var cx, cy : Integer; xs, ys, xe, ys : Integer; Bar : string) : Boolean;
By: R1ch
Description: Returns True if the bar specified in found in the place specified
Used Like: FindBar(x, y, MIX1, MIY2, MIX2, MIY2, 'Rune')
Valid "Bar": Bronze, Iron, Steel, Mith, Addy, Rune
*******************************************************************************}

function FindBar(var cx, cy : Integer; xs, ys, xe, ys : Integer; Bar : string) : Boolean;
var
BTF : Integer;
begin
case (Bar) of
'Bronze': BTF := DTMFromString('78DA635CC7C4C060C5C8800CA25C351944803' +
'448F43F10306E00AA31425503918591407A3B508D1901359B806A' +
'EC08A8590D54E34A40CD3CA01A4722D4581150B310A8C61CBF1A0' +
'07E6E0C2E');

'Iron': BTF := DTMFromString('78DA636C656260106164400689D1510C22401' +
'A24FA1F08187B806A0450D54064612490EE05AA1125A0A60DA846' +
'86809A1AA01A05026A8A806A2409A82907AA11C6AF0600E699097' +
'A');

'Steel': BTF := DTMFromString('78DA635CC3C4C020CAC8800C26B4B63208016' +
'990E87F2060DC0454C38FAA06220B2381F436A01A31026A3602D5' +
'481350B312A84691809AF94035B244A811C5542382AC6621508D3' +
'06E73D8801800ABCC0BFA');

'Mith': BTF := DTMFromString('78DA63BCCEC4C020CEC8800CBCBDF31944803' +
'448F43F1030DE06AAE147550391859140FA21508D10013577816A' +
'2409A801B9479E809AD340357204D41CC7F417869A3384DD0C00E' +
'40A0CA1');

'Addy': BTF := DTMFromString('78DA63CC66646098C38002FC93FD194480345' +
'086E13F10301600595319D000231209A44B30CDC1509303642D21' +
'A02605C85A46404D1490B590809A58206B3601350940D60CFC6A0' +
'043E00D52');

'Rune': BTF := DTMFromString('78DA637CC7C0C0B09F0105046497338800694' +
'620FE0F048C5F818C5D0C6880118904D25F80C421026ADE028993' +
'04D43C2142CD03207182809ABB40E22001357780C411026A1E028' +
'9BD04D47C0712FBF0AB0100A2AE160E');
end;
Result:= FindDTM(BTF, cx, cy, xs, ys, xe, ye);
end;

Quite a simple but handy function. If the bar that is specified is found in the area of the screen specified then it returns True.

Example:
if FindBar(x, y, MIX1, MIY2, MIX2, MIY2, 'Rune') then

Comments?

senrath

2008-12-08 14:59:56

Result:= FindDTM(BTF, cx, cy, xs, ys, xe, ye;
Should be
Result:= FindDTM(BTF, cx, cy, xs, ys, xe, ye);

But other than that, looks good.

Edit: And shouldn't it be
function FindBar(var cx, cy : Integer; xs, ys, xe, ys : Integer; Bar : string) : Boolean;

Rich

2008-12-08 16:10:44

Thanks senrath, fixed the little errors. Does anyone else have any comments?

senrath

2008-12-08 16:17:56

From: R1ch
Thanks senrath, fixed the little errors. Does anyone else have any comments?


You didn't quite fix the second thing I mentioned. You put it like this:
function FindBar(var cx, cy, xs, ys, xe, ys : Integer; Bar : string) : Boolean;

You need it like this:
function FindBar(var cx, cy : Integer; xs, ys, xe, ys : Integer; Bar : string) : Boolean;

Rich

2008-12-08 16:25:29

I don't need to do that, as they are all integers.

Cazax

2008-12-08 16:28:14

Yes you have to do that because you are asking for 6 variables instead of 2.

Rich

2008-12-08 16:31:36

Oh, sorry. I've changed that, but could you explain to me why I need to declare Integer; twice please?

Thanks,
Richard

Cazax

2008-12-08 16:34:15

From: R1ch
Oh, sorry. I've changed that, but could you explain to me why I need to declare Integer; twice please?

Thanks,
Richard

If you do this:
function FindBar(var cx, cy, xs, ys, xe, ys : Integer; Bar : string) : Boolean;
then the person who wants to call the function has to do this:
procedure X;
Var
A, B, C, D, E, F, G : Integer;
Begin
FindBar(A, B, C, D, E, F, G, 'bronze');
....
End;
If you don't declare those variables you'll get a variable excepted error.

senrath

2008-12-08 16:42:41

From: R1ch
Oh, sorry. I've changed that, but could you explain to me why I need to declare Integer; twice please?

Thanks,
Richard


It's because you're declaring 2 variables that happen to be integers, and also saying that you need the input of 4 other integers.

Floor66

2008-12-11 08:22:21

Putting 'var x, y : Integer; xs, ys, xe, ye' for example, will require a user to put:

Procedure SomeThing;
Var
x, y : Integer;
Begin
Blabla(x, y, 0, 0, 1440, 900); // X and Y will be _filled in_ by the function while xs, ys, etc. are e.x coords of a window where it'll search "it"
End;

Rich

2008-12-11 11:03:34

Ok, thanks guys. Apart from that, any other comments about the function?

trojan

2009-01-31 18:50:32

I think that it should definately be added.
+rep

would it be used like

begin
OpenBankFast('akb');
if FindBar(x, y, MSX1, MSY2, MSX2, MSY2, 'iron') then
begin
Mouse(x, y, 3, 3, false);
ChooseOption('Withdraw-All');
CloseBank;
end;
end;
to make iron bars?

WT-Fakawi

2009-02-01 14:34:50

If you declare DTMs you need to free them as well. This function will slowly fill up your memory. And indeed, it should return the x and y coords to use it as trojan indicates.

But good work!

n3ss3s

2009-02-09 11:14:46

Use bitmaps.scar,

bmp_Bar_Bronze = 10;
bmp_Bar_Iron = 11;
bmp_Bar_Steel = 12;
bmp_Bar_Silver = 13;
bmp_Bar_Gold = 14;
bmp_Bar_Mithril = 15;
bmp_Bar_Adamant = 16;
bmp_Bar_Runite = 17;