SRL Archive - SRL Suggestions

FindTextAll(...fonts: TStringArray;...)


LordJashin

2012-02-28 18:58:45

Basically changed FindText to allow searching for multiple fonts. Very useful for things outside of runescape. As for RS I have absolutely no idea. As for TIME WISE this is very good. For 3 fonts it only took like 1 second. Well here it is, pretty obvious stuff. If any improvements can be made let me know, even if this is denied because I'm definitely keeping this.

What This DOES: Searches for 'Text', with font 1 if it finds it then we are done, if not keeps going. Tries to find text with font 2, etc, ,etc

You need to download the attachment that has the fontset in order to test this. OR change MyFontSet in fonts TStringArray to something else, for instance: SmallCharacters or NPCChars or sumthin

function FindTextAll(var cx, cy: Integer; txt: String; fonts: TStringArray; xs, ys, xe, ye:
Integer): Boolean;
var
S, i: Integer;
begin
for i := 0 to High(fonts) do
begin
S := CreateBitmapMaskFromText(txt, ToStr(fonts[i]));
if (xs < 0) then xs := 0;
if (ys < 0) then ys := 0;
Result := FindBitmapMaskTolerance(S, cx, cy, xs, ys, xe, ye, 30, 30);
FreeBitmap(S);
end;
end;

Code used to test this:

var
w, h: Integer;
fonts: TStringArray;
begin
fonts := [FriendChars, LoginChars, MyFontSet]; // MyFontSet is a font set I made that has the bitmaps for the Simba taskbar title
SetDesktopAsClient;
GetClientDimensions(w, h);

if FindTextAll(x, y, 'Simba', fonts, 0, 0, w - 1, h - 1) then
WriteLn('HakunaMatata!');

WriteLn('TimeRunning In MS: ' + (ToStr(GetTimeRunning)));
end.

Coh3n

2012-02-28 19:27:13


function FindTextAll(var cx, cy: Integer; txt: String; fonts: TStringArray; xs, ys, xe, ye: Integer): Boolean;
var
i: Integer;
begin
for i := 0 to High(fonts) do
if (findText(cx, cy, txt, fonts[i], xs, ys, xe, ye)) then
begin
result := true;
break;
end;
end;
FindNPCChatText actually does the same thing since the NPC text has more than one font, so I would be useful in RS in some cases.

LordJashin

2012-02-28 19:42:01

From: Coh3n
Simba Code:
[LEFT]function FindTextAll(var cx, cy: Integer; txt: String; fonts: TStringArray; xs, ys, xe, ye: Integer): Boolean;
var
i: Integer;
begin
for i := 0 to High(fonts) do
if (findText(cx, cy, txt, fonts, xs, ys, xe, ye)) then
begin
result := true;
break;
end;
end;
[/LEFT]

FindNPCChatText actually does the same thing since the NPC text has more than one font, so I would be useful in RS in some cases.


My bad, well atleast someone ( you ) pointed me to a better function that has the same stuff plus more. In my strangling of the help section with like 3 threads on find text, no1 said anything about this. +1 to you Coh3n, for that and your simba tut's
function FindNPCChatTextMulti(txt: TStringArray; action: fnct_ActionOptions): boolean;
var
i, j, x, y: integer;
chars: TStringArray;
begin
chars := [UpChars, CharsNPC];

for i := 0 to high(txt) do
for j := 0 to high(chars) do
if (findText(x, y, txt[i], chars[j], MCX1, MCY1, MCX2, MCY2)) then
begin
case action of
Move: MMouse(x, y, 6, 3);
ClickLeft: Mouse(x, y, 6, 3, mouse_Left);
ClickRight: Mouse(x, y, 6, 3, mouse_Right);
end;

result := true;
exit;
end;
end;

LordJashin

2012-02-28 19:51:44

function FindNPCChatText(txt: string; action: fnct_ActionOptions): boolean;
begin
result := findNPCChatTextMulti([txt], action);
end;

How does this work? What's [txt] with those brackets? Plz Change this thread to denied or whatever, unless you feel this type of thing should be implemented.

Coh3n

2012-02-29 01:54:06

I think it should be. :)

For the []: findNPCChatTextMulti takes a TStringArray, but findNPCChatText takes just a single string. You can declare TStringArrays like this:

var
arr: TStringArray;
begin
arr := ['number1', 'number2', 'number3'];
end.
So basically, you're giving findNPCChatTextMulti the TStringArray is requires, except there's only one element in the array.

Hope that helps; if not, let me know. :)

LordJashin

2012-02-29 22:13:10

Stupid mistake on my last question. Alright here's the final thing I came up with, this is basic, just made txt a TStringArray aswell. Modified the comments above it too. I don't think anything else should be added. Unless you want to include actions, but FindNPCText, and all that already has that. If you wanted to get rid of FindNPCText altogether then sure add it in, but until then not needed really. Maybe you do want to get rid of it, I remember reading some of the SRL 6 requirements, I think one of them was something to do with getting rid of really small functions. Anyway booop:


(*
FindTextEx
~~~~~~~~

.. code-block:: pascal

function FindTextEx(var cx, cy: Integer; txt,font: TStringArray; xs, ys, xe, ye: Integer): Boolean;

Searches for text or texts in specified box with specified font or fonts returns true on first find of one of
the texts with one of the fonts in the specified box, returns x, y values aswell.

.. note::

by Stupid3ooo, modified by LordJashin

Example:

var
x, y, w, h: Integer;
fonts, txts: TStringArray;

begin

fonts := ['MyOwnFontSet', 'SmallCharacters'];
txts := ['Simba', 'HakunaMatata'];

SetDesktopAsClient;
GetClientDimensions(w, h);

if FindTextEx(x, y, txts, fonts, 0, 0, w - 1, h - 1) then
MoveMouse(x, y);

end.

.. code-block:: pascal

*)

function FindTextEx(var cx, cy: Integer; txt, fonts: TStringArray; xs, ys, xe, ye:
Integer): Boolean;
var
S, j, i: Integer;
begin
for j := 0 to High(txt) do
for i := 0 to High(fonts) do
begin
S := CreateBitmapMaskFromText(ToStr(txt[j]), ToStr(fonts[i]));
if (xs < 0) then xs := 0;
if (ys < 0) then ys := 0;
Result := FindBitmapMaskTolerance(S, cx, cy, xs, ys, xe, ye, 30, 30);
FreeBitmap(S);
end;
end;

LordJashin

2012-03-03 21:54:37

How would I get this added to SRL, should I go find out how to use Github, and pull request or sumthin?

Coh3n

2012-03-04 02:21:48

That would probably be the fastest, but I want to change a few other things when that's added. I'll do it early this week. :)

E: This is added for the next version.

LordJashin

2012-03-06 18:17:05

From: Coh3n
That would probably be the fastest, but I want to change a few other things when that's added. I'll do it early this week. :)

E: This is added for the next version.
Glad I could help. Good job reorganizing everything in text.simba :spongebob:, and adding this code to it. I don't see anything else that could be added. Is there anyway to load like a .ttf file, then convert it into separate bitmaps for Simba/fonts folder? I'll search up on the font updater some later.

Coh3n

2012-03-06 19:33:04

From: LordJashin
Glad I could help. Good job reorganizing everything in text.simba :spongebob:, and adding this code to it. I don't see anything else that could be added. Is there anyway to load like a .ttf file, then convert it into separate bitmaps for Simba/fonts folder? I'll search up on the font updater some later.
I have no idea if you can load fonts that way. That would be a question for Wizzup.