SRL Archive - SRL Archives

Fixed GetAmount();


Home

2009-07-29 00:40:08

I have seen couple people that says the current one missed one digit.
Example real amount 480;
Script saw it as 80;


{*******************************************************************************
function GetAmount(ItemX, ItemY: Integer): Integer;
By: ZephyrsFury Edited By Home
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;
Col, II: Integer;
B: TBox;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
if (FindColorsTolerance(TPA, 65536, ItemX - 50, ItemY - 50, ItemX + 50, ItemY + 50, 0)) then
begin
SortTPAFrom(TPA, Point(ItemX, ItemY));
ATPA := SplitTPAEx(TPA, 5, 5);
B := GetTPABounds(ATPA[0]);
if (Length(ATPA[0]) < 15) or (B.X2 - B.X1 < 5) or (B.Y2 - B.Y1 < 5) then Exit;
Result := 1;
for II := 2 downto 0 do
if (FindColorsTolerance(TPA, 7575987 * II * II - 6796134 * II + 65535, B.X1 - 10, B.Y1 - 10, B.X2 + 10, B.Y2 + 10, 0)) then
Break;
if (II < 0) then Exit;
SortTPAFrom(TPA, Point((B.X1 + B.X2) shr 1, (B.Y1 + B.Y2) shr 1));
ATPA := SplitTPAEx(TPA, 5, 5);
TPA := ATPA[0];
Col := 7575987 * II * II - 6796134 * II + 65535;
B := GetTPABounds(TPA);
S := Trim(GetTextAtEx(B.X1 - 10, B.Y1 - 1, 0, StatChars, False, False, 0, 1, Col, 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;

I edited this:

 S := Trim(GetTextAtEx(B.X1 , B.Y1 - 1, 0, StatChars, False, False, 0, 1, Col, 5, True, tr_AllChars));

To:

 S := Trim(GetTextAtEx(B.X1 - 10, B.Y1 - 1, 0, StatChars, False, False, 0, 1, Col, 5, True, tr_AllChars));

I know a small fix, but still something :)

~Home

ShowerThoughts

2009-07-29 00:42:40

We love you home :)!
NOT!

Nadeem

2009-07-29 01:04:54

Funny i just fixed it yesterday, and added an extra thing :p -6 was good enough however.
http://www.villavu.com/forum/showthread.php?p=608449



~NS

Naike

2009-07-29 01:08:46

Nice work Home!

Good to see you contributing ;)

Home

2009-07-29 01:12:58

From: Nadeem
Funny i just fixed it yesterday, and added an extra thing :p -6 was good enough however.
http://www.villavu.com/forum/showthread.php?p=608449



~NS


Heh, ohh well :) ANd thanks N1ke! :)

~Home

Naike

2009-07-29 03:09:39

Ended up re-writing GetAmount.
It now works, and I've uploaded the new one to the Dev-svn.

Thanks again Home.
Closed.