SRL Archive - Help and Support

Getting some str/int from rs


Laimonas171

2012-10-26 13:01:51

Hello, I have idea to create script which makes profit + increases some skills F2P
But for that I need to know few things.

Is here is the way to get numbers from ge to smart as Var's from certain areas? I guess it's because I know simba can check HP amount, run, skill levels etc.

Example of what I need.
  1. Price of item I going to buy.
  2. How much money do I have in Pouch
  3. How many items I have (runes/noted items) only thoose which takes 1 place at inv.
  4. Extra not necessary how to get last message from pm ?




edit: and no it's not high alcher. then I reread post, I noticed it looks like :D

Le Jingle

2012-10-26 13:50:53

1. GetTextAtExWrap() - lots of examples, even some guides too I think, on using this function. Plus I think there are posted GE scripts that already do this?
2. GetMoneyPouchAmount: Integer; (if you need exact amount, use the functions that revolve around moneypouch, to right click and choose option + read last black chat message in chat box. may also want to filter chat box with SetChat() to make sure your private or public don't interfere)
3. CountDTM()

*grandexchange.simba also has quite a few buying/selling func's when you have that screen open, just fyi

Laimonas171

2012-10-26 13:54:45

From: Le Jingle
1. GetTextAtExWrap() - lots of examples, even some guides too I think, on using this function. Plus I think there are posted GE scripts that already do this?
2. GetMoneyPouchAmount: Integer; (if you need exact amount, use the functions that revolve around moneypouch, to right click and choose option + read last black chat message in chat box. may also want to filter chat box with SetChat() to make sure your private or public don't interfere)
3. CountDTM()

*grandexchange.simba also has quite a few buying/selling func's when you have that screen open, just fyi


Silly my, I seached for GetText, getgold, get pouch etc. :D
Doesn't CountDTM, counts All items at inv, by given dtm?

edit: Here is no Function as CountDTM as default. but here is CountItems, but it does count items etc, by slots, it can count how much one kind of ores you have at inv.

Brandon

2012-10-26 14:01:57

From: Laimonas171
Silly my, I seached for GetText, getgold, get pouch etc. :D
Doesn't CountDTM, counts All items at inv, by given dtm?

edit: Here is no Function as CountDTM as default. but here is CountItems, but it does count items etc, by slots, it can count how much one kind of ores you have at inv.




var
DTMHande, BMPHandle, BMPTolerance: Integer;

DTMHande := DTMFromString(...........);
writeln(CountItems('inv', 'dtm', DTMHandle, []));
FreeDTM(DTMHandle);

BMPTolerance := 10;
BMPHandle := BitmapFromString(.......);
CountItems('inv', 'bmp', BitmapHandle, [BmpTolerance]);
FreeBitmap(BitmapHandle);

CountItems('inv', 'color', ColourToFind, [COLOUR Tolerance, Colour Count]);


Then there is countitemsin.. you can figure that one out.

Le Jingle

2012-10-26 14:02:29

If you are looking to count stacks of one items, such as runes, try;


function ItemAmount(area, ItemType: string; Item: Integer; Tol: TIntegerArray): Integer;

Edit: :ninja:'d

Laimonas171

2012-10-26 14:11:54

From: Brandon

var
DTMHande, BMPHandle, BMPTolerance: Integer;

DTMHande := DTMFromString(...........);
writeln(CountItems('inv', 'dtm', DTMHandle, []));
FreeDTM(DTMHandle);

BMPTolerance := 10;
BMPHandle := BitmapFromString(.......);
CountItems('inv', 'bmp', BitmapHandle, [BmpTolerance]);
FreeBitmap(BitmapHandle);

CountItems('inv', 'color', ColourToFind, [COLOUR Tolerance, Colour Count]);


Then there is countitemsin.. you can figure that one out.


Thank you : )


From: Le Jingle
If you are looking to count stacks of one items, such as runes, try;


function ItemAmount(area, ItemType: string; Item: Integer; Tol: TIntegerArray): Integer;

Edit: :ninja:'d



Though not sure how to use, then i type it at function list i see its at OCR, but then I double click it do not opens main fails, and I'm not sure what should I use on these parameters.. :D only first 4 for coords where to search…

 GetTextAtExWrap() 

Le Jingle

2012-10-26 14:15:29

docs.villavu.com for extra info.

alternatively you could also look at the source code on github too.

for GetTextAtExWrap()
http://docs.villavu.com/simba/scriptref/ocr.html?highlight=gettextatexwrap#gettextatexwrap

Laimonas171

2012-10-26 14:20:18

From: Le Jingle
docs.villavu.com for extra info.

alternatively you could also look at the source code on github too.

for GetTextAtExWrap()
http://docs.villavu.com/simba/scriptref/ocr.html?highlight=gettextatexwrap#gettextatexwrap


what if example there doesn't compile? :D

Brandon

2012-10-26 14:22:26

From: Laimonas171
what if example there doesn't compiles? :D



var
Area: TBox;
Text: String;
Value: Integer;

begin
Area := IntToBox(520, 475, 650, 492); //Change these..

Text := GetTextAtExWrap(Area.X1, Area.Y1, Area.X2, Area.Y2, 0, 0, 5, 6334462, 5, 'UpCharsEx');
Value := StrToIntDef(ExtractFromStr(Text, NUMBERS), -1);

//GetTextAtExWrap(X1, Y1, X2, Y2, MinFontVerticalSpace, MaxFontVerticalSpace, HorizontalSpacing, Colour, Tolerance, Font);

//MinVSpace and MaxVSpace is only non 0 when it's multi-line text you are trying to read.
end.

Laimonas171

2012-10-26 14:35:46

From: Brandon

var
Area: TBox;
Text: String;
Value: Integer;

begin
Area := IntToBox(520, 475, 650, 492); //Change these..

Text := GetTextAtExWrap(Area.X1, Area.Y1, Area.X2, Area.Y2, 0, 0, 5, 6334462, 5, 'UpCharsEx');
Value := StrToIntDef(ExtractFromStr(Text, NUMBERS), -1);

//GetTextAtExWrap(X1, Y1, X2, Y2, MinFontVerticalSpace, MaxFontVerticalSpace, HorizontalSpacing, Colour, Tolerance, Font);

//MinVSpace and MaxVSpace is only non 0 when it's multi-line text you are trying to read.
end.

Getting strange stuff as result thought..
should get
Toggle

and getting
. .. . i . i ' . . . . . . '


where I can find font list for runescape?

Brandon

2012-10-26 14:56:34

From: Laimonas171
Getting strange stuff as result thought..
should get

and getting


where I can find font list for runescape?



:S?? What? I thought you were trying to find the text on the grandexchange thing.. The code I posted would print that 1.XX bill gp.

For other texts, choose different areas, colours and fonts.

C:/Simba/Fonts.

Laimonas171

2012-10-26 14:58:54

From: Brandon
:S?? What? I thought you were trying to find the text on the grandexchange thing.. The code I posted would print that 1.XX bill gp.

For other texts, choose different areas, colours and fonts.

C:/Simba/Fonts.


oh, I though it was universal example. :D tried to get chat text :X sorry let my check again\


EDIT: TY, rep++

Brandon

2012-10-26 16:17:32

From: Laimonas171
oh, I though it was universal example. :D tried to get chat text :X sorry let my check again\


EDIT: TY, rep++



Well I just tried a little Simba scripting which I haven't done in a while. The goal is to write the most efficient font info needed to find specific text around RS.

The below is all I can come up with within the last 15 mins. It's pretty accurate. Seems to get MOST of the fonts, tolerances and spacing correct to find text accurately. It then prints out what values you should enter into GetTextAtExWrap :spongebob:

You can try it and see if it gives good results. It should be able to tell you what fonts and settings to use.

Accuracy is the amount of matches before it considers a result good. Usually I leave it at 1 as it seems to give best results at 1. More than 1 is for more matches. Inother words, if you need it to find 4 instances of the same text, then enter 4. Usually 1 is all you ever need though so I suggest leaving it at that.


{$I SRL/SRL.Simba}

type TTextInfo = record
HSpacing: Integer;
MinVSpace: Integer;
MaxVSpace: Integer;
Tolerance: Integer;
FontType: String;
TextFound: String;
end;

type StringExtract = (Numbers, Letters, AlphaNumeric, Others);

Function CharInRange(C: Char; RangeType: StringExtract): Boolean;
Begin
Case RangeType Of
Numbers : Result := ('0' <= C) And (C <= '9');
Letters : Result := (('A' <= C) And (C <= 'Z')) Or (('a' <= C) And (C <= 'z'));
AlphaNumeric : Result := (('0' <= C) And (C <= '9')) Or ((('A' <= C) And (C <= 'Z')) Or (('a' <= C) And (C <= 'z')));
Others : Result := Not ((('0' <= C) And (C <= '9')) Or ((('A' <= C) And (C <= 'Z')) Or (('a' <= C) And (C <= 'z'))));
End;
End;

Function ExtractFromString(Input: String; RangeType: StringExtract): String;
var
I: Integer;
Begin
For I := Length(Input) DownTo 1 Do
If CharInRange(Input[I], RangeType) Then
Result := Input[I] + Result;
End;

Function MatchPartialTextCount(TextToFind: TStringArray; InputText: TStringArray): Integer;
var
I, J: Integer;
Expression, Haystack: String;
Begin
If (Length(InputText) < 1) Then
Exit;

For I := 0 To High(InputText) Do
For J := 0 To High(TextToFind) Do
Begin
Expression := ExtractFromString(TextToFind[J], AlphaNumeric);
Haystack := ExtractFromString(InputText[I], AlphaNumeric);

If ((Length(TextToFind) > 0) And (Length(InputText[I]) > 0)) Then
If ExecRegExpr(Expression, Haystack) Then
Inc(Result);
End;
End;

Function FindTextInfo(TextToFind: TStringArray; Area: TBox; Colour, MaxTolerance, Accuracy: Integer): TTextInfo;
var
I, J, K: Integer;
Fonts: TStringArray;
Found: String;
Begin
Fonts := ['BigChars', 'CharsNPC', 'CharsTrade', 'FriendChars', 'LoginChars', 'SmallChars', 'SmallCharsNS', 'StatChars', 'UpChars', 'UpCharsEx', 'XPChars'];
For I := 0 To MaxTolerance Do
If (FindColorTolerance(K, J, Colour, Area.X1, Area.Y1, Area.X2, Area.Y2, I)) Then
Begin
K := I + 3;
Break;
End;

For I := 0 To High(Fonts) Do
For J := 0 To 10 Do
For K := 0 To High(TextToFind) Do
Begin
Found := GetTextAtExWrap(Area.X1, Area.Y1, Area.X2, Area.Y2, 0, 0, J, Colour, K, Fonts[I]);
If (MatchPartialTextCount(TextToFind, [Found]) >= Accuracy) Then
Begin
Result.FontType := Fonts[I];
Result.HSpacing := J;
Result.MinVSpace := 0;
Result.MaxVSpace := 0;
Result.Tolerance := K;
Result.TextFound := Found;
Exit;
End;
End;
End;

var
Info1, Info2: TTextInfo;
begin
Info1 := FindTextInfo(['1,024,286,387 gp'], IntToBox(522, 283, 640, 299), 6334462, 5, 1);
writeln(Info1); //Prints 1.xx billion GP Info..

writeln('');
writeln('');

Info2 := FindTextInfo(['Your money pouch'], IntToBox(223, 514, 516, 529), 0, 5, 1);
writeln(Info2); //Prints the Your Moeny Pouch has Info.
end.


For me it printed:

Compiled successfully in 1092 ms.
(3, 0, 0, 2, 'UpCharsEx', '1 , 0 2 4 , 2 8 6 , 3 8 7 g p')


(3, 0, 0, 0, 'SmallChars', 'Y o u r m o n e y p o u c h c u r r e n t l y c o n t a ?r n s 1 6? '' 0? 8 0 c o r n s ')
Successfully executed.

Laimonas171

2012-10-26 16:34:47

damn I would like to know things like that.. :X to create something isn't exist. I mean about totaly new things. And now I can only create procedures/ small functions for a script.. :D like find that do that walk there etc.. :D