SRL Archive - SRL Suggestions

GetMoneyPouchAmount


Richard

2012-01-11 10:38:32

The previous GetMoneyPouchAmount was based on colours to determine the multiplier of the money, however, unlike with money in your inventory, the money colour is yellow, but still has the 'K' suffix after it if is between 10000 and 99999 GPs. This edition checks for the presence of letters instead of using the colours. In addition, I also changed the return type to a standard integer. Previously it was returning a longint, but I didn't understand why, as money in RS is 32bit, thus we can just use a standard integer for saving teenee bits of memory :)

(*
GetMoneyPouchAmount
~~~~~~~~~~~~~~~~~~~

.. code-block:: pascal

function GetMoneyPouchAmount: LongInt;

Returns amount of coins in pouch.

.. note ::

by Home

*)
function GetMoneyPouchAmount: Integer;
var
Previous: Boolean;
TPA: TPointArray;
B: TBox;
I :Integer;
Col :TIntegerArray;
Money :String;
begin
Previous := IsMoneyPouchOpen;
if (ToggleMoneyPouch(True)) then
WaitFunc(@IsMoneyPouchOpen, 10, 2750);
Col := [65535, 65278, 16777215, 8453888];
for I := 0 to 3 do
if (FindColors(TPA, Col[I], 450, 90, 510, 109)) then
begin
B := GetTPABounds(TPA);
B := IntToBox(B.X1 - 2, B.Y1 - 2, B.X2 + 2, B.Y2 + 2);
Money := (GetTextAtEx(B.X1 - 1, B.Y1 - 1, 0, StatChars, False, False, 0, 2, Col[I], 5, False, tr_AllChars));
Result := StrToIntDef(GetNumbers(Money), -1);
If Pos('K', Money) > 0 then
Result := Result * 1000;
If Pos('M', Money) > 0 then
Result := Result * 1000000;
break;
end;
if (not(Previous)) then
begin
Wait(RandomRange(500, 1500));
ToggleMoneyPouch(Previous);
end;
end;

A few tests for confirmation:
Returns 11000000.

Returns 9236000.

Returns 36000.

Returns 771.

Coh3n

2012-01-16 16:19:57

Fixed for the next version, thanks. :)