Ian
2013-06-17 06:00:24
I made this to get a player's total level. It takes around 30ms. I am aware that it is probably way more lines long then it needs to be, but it works as it is.
Basically how it works is it determines the number of digits in the total level (2, 3, or 4). Then it uses that information to divide the digits into boxes. Then it distinguishes each number by counting the number of pixels of a certain color in the box. For the numbers that have the same number of pixels as another number, it compares the amount of pixels in the bottom halves of the digits. This separates all of them. Then they are given numbers depending on what digit they are in and these numbers are added together to result as the total levels.
The SMART Debug is commented out in case you don't want it. If you do, just uncomment :)
Picture:

Code:
Basically how it works is it determines the number of digits in the total level (2, 3, or 4). Then it uses that information to divide the digits into boxes. Then it distinguishes each number by counting the number of pixels of a certain color in the box. For the numbers that have the same number of pixels as another number, it compares the amount of pixels in the bottom halves of the digits. This separates all of them. Then they are given numbers depending on what digit they are in and these numbers are added together to result as the total levels.
The SMART Debug is commented out in case you don't want it. If you do, just uncomment :)
Picture:

Code:
function GetTotalLevel:Integer;//By BMWxi
var
TotalLevelColor, TotalLevelTol, PixelCount1, PixelCount2, PixelCount3, PixelCount4,
HalfPixelCount1, HalfPixelCount2, HalfPixelCount3, HalfPixelCount4, FirstDigit,
SecondDigit, ThirdDigit, FourthDigit, TotalLevel:Integer;
begin
//Color Info
TotalLevelColor := 36095;
TotalLevelTol := 10;
if not (GetCurrentTab = tab_Stats) then GameTab(tab_Stats);
//SMART_ClearCanvas;
repeat
if (GetColor(634, 450) = 36095) then
begin
WriteLn('2 Digits!');
//1st Digit
//SMART_DrawBoxEx(true, false, IntToBox(707, 442, 714, 455), clYellow);
PixelCount1 := CountColorTolerance(TotalLevelColor, 707, 442, 714, 455, TotalLevelTol);
HalfPixelCount1 := CountColorTolerance(TotalLevelColor, 707, 450, 714, 455, TotalLevelTol);
//2nd Digit
//SMART_DrawBoxEx(false, false, intToBox(699, 442, 707, 455), clYellow);
PixelCount2 := CountColorTolerance(TotalLevelColor, 699, 442, 707, 455, TotalLevelTol);
HalfPixelCount2 := CountColorTolerance(TotalLevelColor, 699, 450, 707, 455, TotalLevelTol);
Break;
end;
if (GetColor(630, 450) = 36095) then
begin
WriteLn('3 digits!');
//1st Digit
//SMART_DrawBoxEx(true, false, IntToBox(710, 442, 717, 455), clYellow);
PixelCount1 := CountColorTolerance(TotalLevelColor, 710, 442, 717, 455, TotalLevelTol);
HalfPixelCount1 := CountColorTolerance(TotalLevelColor, 710, 450, 717, 455, TotalLevelTol);
//2nd Digit
//SMART_DrawBoxEx(false, false, intToBox(703, 442, 710, 455), clYellow);
PixelCount2 := CountColorTolerance(TotalLevelColor, 703, 442, 710, 455, TotalLevelTol);
HalfPixelCount2 := CountColorTolerance(TotalLevelColor, 703, 450, 710, 455, TotalLevelTol);
//3rd Digit
//SMART_DrawBoxEx(false, false, intToBox(695, 442, 703, 455), clYellow);
PixelCount3 := CountColorTolerance(TotalLevelColor, 695, 442, 703, 455, TotalLevelTol);
HalfPixelCount3 := CountColorTolerance(TotalLevelColor, 695, 450, 703, 455, TotalLevelTol);
Break;
end;
if (GetColor(627, 450) = 36095) then
begin
WriteLn('4 digits!');
//1st Digit
//SMART_DrawBoxEx(true, false, IntToBox(714, 442, 721, 455), clYellow);
PixelCount1 := CountColorTolerance(TotalLevelColor, 714, 442, 721, 455, TotalLevelTol);
HalfPixelCount1 := CountColorTolerance(TotalLevelColor, 714, 450, 721, 455, TotalLevelTol);
//2nd Digit
//SMART_DrawBoxEx(false, false, intToBox(707, 442, 714, 455), clYellow);
PixelCount2 := CountColorTolerance(TotalLevelColor, 707, 442, 714, 455, TotalLevelTol);
HalfPixelCount2 := CountColorTolerance(TotalLevelColor, 707, 450, 714, 455, TotalLevelTol);
//3rd Digit
//SMART_DrawBoxEx(false, false, intToBox(699, 442, 707, 455), clYellow);
PixelCount3 := CountColorTolerance(TotalLevelColor, 699, 442, 707, 455, TotalLevelTol);
HalfPixelCount3 := CountColorTolerance(TotalLevelColor, 699, 450, 707, 455, TotalLevelTol);
//4th Digit
//SMART_DrawBoxEx(false, false, intToBox(692, 442, 699, 455), clYellow);
PixelCount4 := CountColorTolerance(TotalLevelColor, 692, 442, 699, 455, TotalLevelTol);
HalfPixelCount4 := CountColorTolerance(TotalLevelColor, 692, 450, 699, 455, TotalLevelTol);
Break;
end;
until(False);
begin
case PixelCount1 of
18:
begin
case HalfPixelCount1 of
7: FirstDigit := 5;
9: FirstDigit := 0;
end;
end;
15:
begin
case HalfPixelCount1 of
8: FirstDigit := 2;
7: FirstDigit := 3;
end;
end;
17:
begin
case HalfPixelCount1 of
10: FirstDigit := 4;
9: FirstDigit := 6;
8: FirstDigit := 9;
end;
end;
14: FirstDigit := 1;
12: FirstDigit := 7;
19: FirstDigit := 8;
end;
end;
begin
case PixelCount2 of
18:
begin
case HalfPixelCount2 of
7: SecondDigit := 50;
9: SecondDigit := 0;
end;
end;
15:
begin
case HalfPixelCount2 of
8: SecondDigit := 20;
7: SecondDigit := 30;
end;
end;
17:
begin
case HalfPixelCount2 of
10: SecondDigit := 40;
9: SecondDigit := 60;
8: SecondDigit := 90;
end;
end;
14: SecondDigit := 10;
12: SecondDigit := 70;
19: SecondDigit := 80;
end;
end;
begin
case PixelCount3 of
18:
begin
case HalfPixelCount3 of
7: ThirdDigit := 500;
9: ThirdDigit := 0;
end;
end;
15:
begin
case HalfPixelCount3 of
8: ThirdDigit := 200;
7: ThirdDigit := 300;
end;
end;
17:
begin
case HalfPixelCount3 of
10: ThirdDigit := 400;
9: ThirdDigit := 600;
8: ThirdDigit := 900;
end;
end;
14: ThirdDigit := 100;
12: ThirdDigit := 700;
19: ThirdDigit := 800;
end;
end;
begin
case PixelCount4 of
18:
begin
case HalfPixelCount4 of
7: FourthDigit := 5000;
9: FourthDigit := 0;
end;
end;
15:
begin
case HalfPixelCount3 of
8: FourthDigit := 2000;
7: FourthDigit := 3000;
end;
end;
17:
begin
case HalfPixelCount4 of
10: FourthDigit := 4000;
9: FourthDigit := 6000;
8: FourthDigit := 9000;
end;
end;
14: FourthDigit := 1000;
12: FourthDigit := 7000;
19: FourthDigit := 8000;
end;
end;
TotalLevel := (FirstDigit + SecondDigit + ThirdDigit + FourthDigit);
Result := TotalLevel;
end;