SRL Archive - SRL Snippets

function GetTotalLevel


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:
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;

double codes

2013-06-17 06:57:30

I have no experience with scriping with RuneScape.

From what i see, you somehow count the pixels to get the total level, or am i wrong ?
Can you explain it to me how it works please ? I'm Intereste :P .

Thanks

Le Jingle

2013-06-17 12:45:38

Is there not a getTotalLevel function?


function GetTotalLevel(): Integer;
var s: string;
begin
GameTab(Tab_Stats);
s := GetTextAtExWrap(620, 445, 725, 454, 0, 5, 2, 36095, 1, UpChars);
Result := StrToIntDef(GetNumbers(s), -1);
end;

Olly

2013-06-17 13:08:58

From: Le Jingle
Is there not a getTotalLevel function?


function GetTotalLevel(): Integer;
var s: string;
begin
GameTab(Tab_Stats);
s := GetTextAtExWrap(620, 445, 725, 454, 0, 5, 2, 36095, 1, UpChars);
Result := StrToIntDef(GetNumbers(s), -1);
end;


Lol, was posting my reply which was near enough the same, But yeah UpChars is the font "Total level: 2331"

Ian

2013-06-17 17:28:59

From: double codes
I have no experience with scriping with RuneScape.

From what i see, you somehow count the pixels to get the total level, or am i wrong ?
Can you explain it to me how it works please ? I'm Intereste :P .

Thanks

Well I count the pixels in each digit, and by the number of pixels I can tell which digit is which. For example, the digit 8 uses 19 pixels. If there are letters which use the same number of pixels, I do the same thing as earlier but only on the bottom half of the digit. This leaves only one match :)
From: Le Jingle
Is there not a getTotalLevel function?


function GetTotalLevel(): Integer;
var s: string;
begin
GameTab(Tab_Stats);
s := GetTextAtExWrap(620, 445, 725, 454, 0, 5, 2, 36095, 1, UpChars);
Result := StrToIntDef(GetNumbers(s), -1);
end;

The Mayor asked wanted a function to get the total level and he said that ocr wasn't working so I guess he must have been using the wrong font :p

Ah well this was fun to make :)

double codes

2013-06-17 17:51:43

From: BMWxi
Well I count the pixels in each digit, and by the number of pixels I can tell which digit is which. For example, the digit 8 uses 19 pixels. If there are letters which use the same number of pixels, I do the same thing as earlier but only on the bottom half of the digit. This leaves only one match :)

The Mayor asked wanted a function to get the total level and he said that ocr wasn't working so I guess he must have been using the wrong font :p

Ah well this was fun to make :)


Wow cool, i think i can make something similar with VB.NET, though a little bit harder :P.

Thanks for the response ;)