SRL Archive - SRL Bugs

Amount.scar -- GetAmount


Coh3n

2010-11-12 19:26:27

I put one of each rune in my inventory to test some MSI functions, and GetAmount is returning that there's 11 of a lot of runes. I've tested the DTMs individually, so that's not the problem.

I looked at GetAmount, and I think it would work better if it was based of inventory slots rather than item coordinates. It uses the coords as a 'mainpoint' to figure out where the text is. I think it would be more accurate if this 'mainpoint' was in the center of the inventory slot, no?

Make sense?

Also, the reason I'm posting this is because I don't have time to do this for the next few days. If someone is up for the challenge, be my guest. :)

Cheers,
Coh3n

NCDS

2010-11-12 22:13:09

I might have a minute tomorrow to test that theory. I'm just concerned as to how that would handle the situation of having a large number of items in the slot next to the one your looking at.

Bad Boy JH

2010-11-12 22:39:40

well, I don't like that idea, cause it would stop it being used for the bank, however a fix would be a good idea…

Coh3n

2010-11-13 02:44:40

From: Bad Boy JH
well, I don't like that idea, cause it would stop it being used for the bank, however a fix would be a good idea…

It can always be edited to work with the bank… and deposit box for that matter.

Bad Boy JH

2010-11-13 07:57:48

as long as it remains so it can do that, I have no issue…
it was poorly phrased…

NCDS

2010-11-13 09:38:25

If this does end up working (I'll know soon) then it would be pretty simple to see what interface is open (ie BankScreen, DepositScreen, or just Inv), and just store the TBox to a var so it could work either way.

TomTuff

2010-11-13 12:36:18

1. Get pixel coords of rune
2. Find out which inventory slot (via TBoxes) the rune is in
3. use center coords ((box.x2-box.x1), (box.y2-box.y2)) as a reference point to get text
4. OCR text
5. Result := …

just an idea :P

Coh3n

2010-11-14 15:58:41

From: TomTuff
1. Get pixel coords of rune
2. Find out which inventory slot (via TBoxes) the rune is in
3. use center coords ((box.x2-box.x1), (box.y2-box.y2)) as a reference point to get text
4. OCR text
5. Result := …

just an idea :P

That's just a more specific way of what I meant. :p

Coh3n

2010-11-16 03:14:23

Alright, I think I have this working pretty well. I even added a little part it that will get the exact number of the item if greater than 100k. :) I'd like a few people to test with different numbers before I commit, just to be sure. In the image below, the red box is just the inventory slot, and the yellow box is where it searches for the text. You can test with this script:

program new;
{$i srl/srl/misc/smart.scar}
{$i srl/srl.scar}
{$i srl/srl/misc/PaintSmart.scar}

function tGetAmount(Area: string; Slot: Integer): Integer;
var
textCols: TIntegerArray;
x, y, i: Integer;
b, bounds: TBox;
TPA: TPointArray;
s: String;
begin
case Lowercase(Area) of
'inv': b := InvBox(Slot);
'bank': b := BankIndexToMSBox(Slot);
'deposit box', 'dbox': b := DepositItemBox(Slot);
else
srl_Warn('GetAmount', 'Invalid GetAmount area ', warn_AllVersions);
end;

// If no item is found in the specified slot
if (not FindColor(x, y, SRL_OUTLINE_BLACK, b.x1, b.y1, b.x2, b.y2)) then
begin
srl_Warn('GetAmount', 'Item doesn''t exist in '+Capitalize(Area)+' slot '+IntToStr(Slot)+' ', warn_AllVersions);
Exit;
end;

Inc(Result);
textCols := [65535, 65278, 16777215, 8453888];

SMART_DrawBoxEx(False, b, clRed);

// Loop through all the possible text colors until one is found
for i := 0 to High(textCols) do
if (FindColor(x, y, textCols[i], b.x1, b.y1, b.x2, b.y2)) then
begin
FindColors(TPA, textCols[i], b.x1, b.y1, b.x2, b.y2);
bounds := GetTPABounds(TPA);
bounds := IntToBox(bounds.x1-2, bounds.y1-2, bounds.x2+2, bounds.y2+2);
SMART_DrawBoxEx(False, bounds, clYellow);

s := GetTextAtExWrap(bounds.x1, bounds.y1, bounds.x2, bounds.y2, 0, 1, 1, textCols[i], 0, StatChars);

Result := StrToIntDef(GetNumbers(s), 1);

// If greater than 100k, examine it to get the exact number
if ((i = 2) or (i = 3)) then
begin
MouseBox(b.x1, b.y1, b.x2, b.y2, 2);
if (WaitOption('xamine', 500)) then
Result := StrToInt(GetNumbers(GetChatBoxText(8, clBlack)));
end;

Exit;
end;
end;

var
i: Integer;
begin
Smart_Server := 152;
Smart_Members := False;
Smart_Signed := True;
Smart_SuperDetail := False;

SetupSRL;
ClearDebug;
SmartSetDebug(True);
ActivateClient;
SMART_DrawBoxEx(True, IntToBox(0, 0, 0, 0), clRed); // Clears the canvas

for i := 1 to 15 do
Writeln(IntToStr(tGetAmount('bank', i)));

//Writeln(GetNumbers(GetChatBoxText(8, clBlack)));
end.
Inventory:

Bank:

Deposit Box:
Haven't tested yet.

E: Oh, I forgot to mention that it did printed out all the right amounts. :p

E2: I've found that occasionally it won't get the right number after it right clicks an item and reads the chat text for whatever reason. Something may be wrong with that function, or GetAmount can just give an approximate result if the calculated result is less than 100k.

Coh3n

2010-11-16 16:23:12

Turns out the original wasn't as hard to fix as I though. Committed a fixed version. The one that I wrote above hasn't been committed. I may use it in MSI, we'll have to see. :p

Overtime

2010-11-16 16:30:18

lol silly coh3n.

my turn to post a bug!