SRL Archive - SRL Archives

GetAmount


XcanadamanX

2009-08-29 04:50:01

Hey i wrote a new GetAmount because the other one wasnt working for me.




{*******************************************************************************
function GetAmount(ItemX, ItemY: Integer): Integer;
By: XcanadamanX
Description: Returns the amount of an item at coordinates (ItemX, ItemY).
Returns approximate values for 'K' and 'M'.
*******************************************************************************}

function GetAmount(ItemX, ItemY : Integer): Integer;
var
S : String;
TPA : TPointArray;
ATPA : T2DPointArray;
B: TBox;
Cols : Array of Integer;
x : Integer;
begin
Cols:= [65535, 8453888, 16777215];
if (FindColors(TPA, 65536, ItemX - 50, ItemY - 50, ItemX + 50, ItemY + 50)) then
begin
SortTPAFrom(TPA, Point(ItemX, ItemY));
ATPA := SplitTPAEx(TPA, 5, 5);
B:= GetTPABounds(ATPA[0])
For x := 0 to 2 do
begin
if FindColors(TPA, Cols[x], B.x1 - 5, B.y1 - 5, B.x2 + 5, B.y2 + 5) then
break;
end;
if High(TPA) = -1 then exit;
SortTPAFrom(TPA, Point(B.x1, B.y1));
B := GetTPABounds(TPA);
S := GetTextAtEx(B.x1 - 1, B.y1 - 1, 0, StatChars, False, False, 0, 1, Cols[x], 5, True, tr_AllChars);
Result := StrToIntDef(GetNumbers(S), 1);
if (Pos('M', S) > 0) then Result := Result * 1000000 else
if (Pos('K', S) > 0) then Result := Result * 1000;
end;
end;


results with 1 when item found
function GetAmount(ItemX, ItemY : Integer): Integer;
var
S : String;
TPA : TPointArray;
ATPA : T2DPointArray;
B: TBox;
Cols : Array of Integer;
x : Integer;
begin
Cols:= [65535, 8453888, 16777215];
if (FindColors(TPA, 65536, ItemX - 50, ItemY - 50, ItemX + 50, ItemY + 50)) then
begin
result := 1;
SortTPAFrom(TPA, Point(ItemX, ItemY));
ATPA := SplitTPAEx(TPA, 5, 5);
B:= GetTPABounds(ATPA[0])
For x := 0 to 2 do
begin
if FindColors(TPA, Cols[x], B.x1 - 5, B.y1 - 5, B.x2 + 5, B.y2 + 5) then
break;
end;
if High(TPA) = -1 then exit;
SortTPAFrom(TPA, Point(B.x1, B.y1));
B := GetTPABounds(TPA);
S := GetTextAtEx(B.x1 - 1, B.y1 - 1, 0, StatChars, False, False, 0, 1, Cols[x], 5, True, tr_AllChars);
Result := StrToIntDef(GetNumbers(S), 1);
if (Pos('M', S) > 0) then Result := Result * 1000000 else
if (Pos('K', S) > 0) then Result := Result * 1000;
end;
end;

credits to zeph for the original.

I didnt know if there was no text if it should result as 1 or 0.

ian.

2009-08-29 04:54:59

If no text is found but an item is found, have it return 1. :)

ZephyrsFury

2009-08-29 06:17:41

N1ke added a new GetAmount in the Open Dev repos. Apparently it works better than my old one but I'm not sure how it compares to this.