SRL Archive - SRL Archives

[SLOWISH] function GetTextInAreaEx;


Mad Cow

2006-10-22 01:32:59

Well heres a function that I made up that finds ANY text on a line within an area(Requires chars of course). It's fairly slow but it's the fastest I can make it with SCAR.

Well heres the procedure.
function IsFromAlph(Text : String) : Boolean;
var
I : Integer;
AlphNum : String;
begin
AlphNum := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
for I := 1 to Length(AlphNum) do
begin
if(Copy(AlphNum, I, 1)) = (Copy(Text, 1, 1)) then
Result := True;
end;
end;
//RapidSpeed only affects if UseRapid is True(Recommended 3 - 4)
function GetTextInAreaEx(X1, Y1, X2, Y2 : Integer; Tolerance : Integer; Chars : Integer; CheckShadow : Boolean; TextColor, TextLength : Integer; Strict : Boolean; CharRange : TCharRange; UseRapid : Boolean; RapidSpeed : Integer) : String;
var
X, Y, Rapid : Integer;
Text : String;
begin
if(UseRapid) then
Rapid := Trunc(X2 / RapidSpeed) + 1//Keep in mind it looks for the START text and the area then won't matter
else
Rapid := X2 + 1;
X := X1;
Y := Y1;
repeat
if(X = Rapid) then
begin
Y := Y + 1;
X := X1;
end;
if(Y = Y2) then
begin
WriteLn('ERROR: Text not found.');
Exit;
end;
X := X + 1;
Text := GetTextAtEx(X - 1, Y, Tolerance, Chars, CheckShadow, True, 0, 0, TextColor, TextLength, Strict, CharRange);
until(IsFromAlph(Text));
Result := GetTextAtEx(X - 1, Y, Tolerance, Chars, CheckShadow, True, 0, 1, TextColor, TextLength, Strict, CharRange);;
end;

And heres a DEMO to what it can do…
{.Script Info:
# ScriptName = GetTextInAreaEx DEMO
# Author = Mad Cow
# Description = Finds text in an area
# Version = 1.0
# Date = 21 October 2006
# Comments = It works...
/Script Info}

program GetTextInAreaEx;
var
MyChars, ST : Integer;

const
ExtendedDebug = False;//Show what coords it's looking at

function IsFromAlph(Text : String) : Boolean;
var
I : Integer;
AlphNum : String;
begin
AlphNum := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
for I := 1 to Length(AlphNum) do
begin
if(Copy(AlphNum, I, 1)) = (Copy(Text, 1, 1)) then
Result := True;
end;
end;
//RapidSpeed only affects if UseRapid is True(Recommended 3 - 4)
function GetTextInAreaEx(X1, Y1, X2, Y2 : Integer; Tolerance : Integer; Chars : Integer; CheckShadow : Boolean; TextColor, TextLength : Integer; Strict : Boolean; CharRange : TCharRange; UseRapid : Boolean; RapidSpeed : Integer) : String;
var
X, Y, Rapid : Integer;
Text : String;
begin
if(UseRapid) then
Rapid := Trunc(X2 / RapidSpeed) + 1//Keep in mind it looks for the START text and the area then won't matter
else
Rapid := X2 + 1;
X := X1;
Y := Y1;
repeat
if(ExtendedDebug) then
WriteLn('X = ' + IntToStr(X) + ' & Y = ' + IntToStr(Y));
if(X = Rapid) then
begin
Y := Y + 1;
X := X1;
end;
if(Y = Y2) then
begin
WriteLn('ERROR: Text not found.');
Exit;
end;
X := X + 1;
Text := GetTextAtEx(X - 1, Y, Tolerance, Chars, CheckShadow, True, 0, 0, TextColor, TextLength, Strict, CharRange);
until(IsFromAlph(Text));
Result := GetTextAtEx(X - 1, Y, Tolerance, Chars, CheckShadow, True, 0, 1, TextColor, TextLength, Strict, CharRange);;
if(ExtendedDebug) then
WriteLn('FINAL X = ' + IntToStr(X - 1) + ' & FINAL Y = ' + IntToStr(Y));
end;

begin
ClearDebug;
ST := GetSystemTime;
Status('Searching for text...');

MyChars := LoadChars2(AppPath + 'includes\SRL\SmallChars\');//Replace with your chars, these are the chat chars
WriteLn('Text = ' + GetTextInAreaEx(18, 409, 156, 433, 0, MyChars, False, 0, 100, False, tr_NormalChars, True, 3));
Status('Finshed');

WriteLn('Time taken: ' + IntToStr(GetSystemTime - ST) + ' milliseconds');
end.

Well enjoy guys, I'd be great if you could find a use for it =P (I made it for a friend),
Mad Cow