SRL Archive - OSR Help

CoinAmount Broken


bob_dole

2013-04-22 23:23:43

In the amount include the function CoinAmount and FindCoins does not work. I have tried with coins in bank/inventory neither of which work so I am assuming trades wont work either. I have prior programming knowledge but I'm new to SRL scripting so I can't debug the function myself to fix it.

function FindCoins(var X, Y: Integer; Area: string): Boolean;
var
B: TBox;
CTS, I, J, H, L: Integer;
Pts, tPts: TPointArray;
ATPA: T2DPointArray;
V: array [0..1] of TVariantArray;
begin
case Lowercase(Area) of
'inv', 'inventory': B := IntToBox(MIX1, MIY1, MIX2, MIY2);
'bank': B := IntToBox(MBx1, MBy1, MBx2, MBy2);
'trade': B := IntToBox(323, 73, 509, 302);
'your trade': B := IntToBox(9, 73, 196, 302);
end;
V[0] := [1479346, 1, 0.00, 0.00]; //Darker colour (top of coins)
V[1] := [3722229, 7, 0.05, 0.86]; //Lighter colour (rest of the coins)
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetLength(tPts, 0);
try
for I := 0 to 1 do
begin
SetColorSpeed2Modifiers(V[I][2], V[I][3]);
FindColorsTolerance(Pts, V[I][0], B.X1, B.Y1, B.X2, B.Y2, V[I][1]);
if (Length(Pts) < 10) then Exit;
ATPA := SplitTPAEx(Pts, 10, 10);
h := High(ATPA);
L := High(tPts) + 1;
SetLength(tPts, L + h + 1);
for J := 0 to H do
tPts[L + j] := MiddleTPA(ATPA[J]);
end;
ATPA := SplitTPAEx(tPts, 20, 20);
H := High(ATPA);
for I := 0 to H do
if (High(ATPA[I]) = 1) then
Break;
if (I > H) then Exit;
Result := True;
MiddleTPAEx(ATPA[I], X, Y);
finally
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
end;

Thanks. The line of code I am using to test this is as shown below.

WriteLn('Coins found: '+toStr(CoinAmount('inv'))); 

Le Jingle

2013-04-22 23:49:45

Could you post a .png picture of the coin amounts/coin stack?

bob_dole

2013-04-23 22:04:44

To my knowledge the function is supposed to detect the amount of coins (1 coin to 10,000+ coins) so I will upload pngs of all different coin stacks. Unfortunately this will take two posts as I am only allotted 5 pics per post.

bob_dole

2013-04-23 22:06:52

More stacks of coins in PNG format. The function is supposed to detect all amounts of coins but ten thousand plus is the main one I need.

Le Jingle

2013-04-24 00:29:53

https://github.com/SRL/SRL-OSR/pull/124

Don't forget to make sure you're up to date too (with the latest OSR-SRL includes).

*(Either add the function in the pull request I linked manually, or wait until it's added to the includes and then re-download the new .zip of the includes (after the function is committed to the master SRL-OSR), extract, replace, etc.)

Cheers
LJ

bob_dole

2013-04-24 01:02:11

Thanks for the help. While waiting I did devise my own function to handle the task. I am debating whether or not to release my autoSeller (to other players, not shops) but I will be using this function instead.

function Cash(area: string): Integer;
Var
amount, i: integer;
coinsDTM: TIntegerArray;
begin
coinsDTM := [
DTMFromString('mbQAAAHicY2VgYHBiYmDwgWJrILYDYl1GCDYDYmMg1gbiB9ulGc6tlGA4sUSCYdNEUTAfG2DEgsEAAIpTCio='), // > 10,000
DTMFromString('mbQAAAHicY2VgYHBkYmDwAWJvIDYHYmsgfg4UfwfEj4H4GZT9+bgcw7GFEgznVkow3N0qzfD+sBwDNsCIBYMBALteDk4='), // 1,000-10,000
DTMFromString('mggAAAHicY2NgYHBkYmBwA2IvJgjbCoitgfgFUO4REL8B4g9Q+gkQP90tzbBpoijD453SDJ+Py4HZh+dLMOACjDgwBAAAMbMQig=='), // 250-1,000
DTMFromString('mWAAAAHicY2FgYLBmYmAwh2I7IH4BFHsFxM+B+BkQb5ooyvD7sh+YBmF0wIiGQQAAQ7oKuw==')]; // < 250

for i := 0 to (length(coinsDTM) - 1) do
begin
amount := ItemAmount(area, 'dtm', coinsDTM[i], []);

if (amount > 0) then
begin
freeDTMs(coinsDTM);
Result := amount;
break;
end;

end;

freeDTMs(coinsDTM);

end;