SRL Archive - SRL Archives

[Very Fast] CountOre


noidea

2008-12-08 21:33:32

Here. It doesn't use DTM's or anything, so that makes it way faster. It just counts the black pixels around the Ore. If it find the right amount of black pixels, +1.

Here. Rate, hate, love, comments, concerns?

program New;
{.include srl/srl.scar}

{*****************************************************
Function CountOre: Integer;
By: noidea
Description: Counts any ore except clay you can mine.
Use/Example: Ore := Ore + CountOre;
writeln(IntToStr(CountOre));
*****************************************************}
Function CountOre: Integer;
var
k, I: Integer;
p : TBox;
begin
I := 1
While I < 29 do
begin
GetInvItemBounds(I, p);
if countcolor(65536, p.x1, p.y1, p.x1+34, p.y1+27) = 171 then
inc(k);
inc(I);
end;
Result := k;
end;


begin
setupsrl;
writeln(inttostr(CountOre));
end.

senrath

2008-12-08 23:16:26

My only question is are you sure that there is no other item that might have the same number of pixels?

Probably wouldn't be much of a problem, but wouldn't hurt to make sure.

NiCbaZ

2008-12-08 23:30:58

Nice, but when not Use a for loop?

Function CountOre: Integer;
var
I: Integer;
p : TBox;
begin
for I:= 1 to 28 do
begin
P:= InvBox(I);
if countcolor(65536, p.x1, p.y1, p.x1+34, p.y1+27) = 171 then
Result:= Result + 1;
end;
end;

NCDS

2008-12-08 23:38:50

From: NiCbaZ
Nice, but when not Use a for loop?

Function CountOre: Integer;
var
I: Integer;
p : TBox;
begin
for I:= 1 to 28 do
begin
P:= InvBox(I);
if countcolor(65536, p.x1, p.y1, p.x1+34, p.y1+27) = 171 then
Result:= Result + 1;
end;
end;



what? lol

Sandstorm

2008-12-09 00:01:19

From: N C D S
what? lol


Something like this. I got the idea from him and made it into a log counting procedure. It counts black vambraces (not sure about other types) as well though lol.

Function CountLogs : Integer;
Var
I : Integer;
P : Tbox;
Begin
For I := 0 To 28 Do
Begin
GetInvItemBounds(I, p);
If CountColor(65536, p.x1, p.y1, p.x1+34, p.y1+27) = 85 Then
Inc(Result);
End;
End;

NiCbaZ

2008-12-09 04:20:56

From: Sandstorm
Something like this. I got the idea from him and made it into a log counting procedure. It counts black vambraces (not sure about other types) as well though lol.

Function CountLogs : Integer;
Var
I : Integer;
P : Tbox;
Begin
For I := 0 To 28 Do
Begin
GetInvItemBounds(I, p);
If CountColor(65536, p.x1, p.y1, p.x1+34, p.y1+27) = 85 Then
Inc(Result);
End;
End;



Just so you know, If you have an If or For then a begin you dont do 2 spaces like


begin
for I:= p to 20(high) do
begin
end;
end;

its

begin
for I:= p to 20(high) do
begin
end;
end;

thus making your function like..


Function CountLogs : Integer;
Var
I : Integer;
P : Tbox;
Begin
For I := 0 To 28 Do
Begin
GetInvItemBounds(I, p);
If CountColor(65536, p.x1, p.y1, p.x1+34, p.y1+27) = 85 Then
Inc(Result);
End;
End;

Wizzup?

2008-12-09 05:30:50

Since when is there an Inventory Spot with the index of 0?
Anyway, finding all the black outlines in one FindColors, then Split the Points, followed by a length check for each TPA should also be very fast. :)

noidea

2008-12-09 06:45:17

From: Wizzup?
Since when is there an Inventory Spot with the index of 0?
Anyway, finding all the black outlines in one FindColors, then Split the Points, followed by a length check for each TPA should also be very fast. :)


Yea, so it should be like

For I := 1 to 28 do

Correct?

Sandstorm

2008-12-09 08:55:11

From: Wizzup?
Since when is there an Inventory Spot with the index of 0?
Anyway, finding all the black outlines in one FindColors, then Split the Points, followed by a length check for each TPA should also be very fast. :)


So that's why I kept getting an unknown inv box error. Lol, I wasn't thinking at the time. I normally start at 0 for a for..to..do, so I just did what I normally do lol.

noidea

2008-12-09 21:01:33

At first I tried a For To Do loop, but failed because I would inc(I) even though the loop did itself, so it only did the even inv spots. rawr!

senrath

2008-12-09 22:18:52

From: noidea
At first I tried a For To Do loop, but failed because I would inc(I) even though the loop did itself, so it only did the even inv spots. rawr!


Then why didn't you just remove the Inc(I) that you had? That would've worked properly.

noidea

2008-12-10 15:53:42

From: senrath
Then why didn't you just remove the Inc(I) that you had? That would've worked properly.


I haddent realized that it auto matically inc(I)

HyperSecret

2008-12-15 10:35:42

Result := 0; at the beginning to make sure it starts counting at 0, for the result.

Sandstorm

2008-12-17 21:38:06

I believe the result is a local variable, so it should be dropped after it's done being used. I may be wrong though.

noidea

2008-12-17 22:06:18

yea, thats what I thought, so I include that.