PDA

View Full Version : chatbox.getXP



Ashaman88
12-23-2013, 10:45 PM
Just a little something until the devs come up with something better.

function TRSChatBox.getXP: Integer;
var
b: TBox;
s: String;
tpa : TPointArray;
atpa : T2DPointArray;
i,cts,p: Integer;
begin
b := self.getBounds();
b.edit(+(b.x2-b.x1)-140, +10, -5, -94);

findColorsTolerance(tpa, 14013909, b, 4,colorSetting(2, 0.00, 0.00));

if length(tpa) < 2 then
begin
print('chatBox.getXP(): No XP found', TDebug.SUB);
Exit;
end;

atpa := tpa.cluster(5);

b:= atpa.getbounds;
b.edit(-2,-2,+2,+3);

s:=Replace(tesseractgettext(b.x1,b.y1,b.x2,b.y2, FILTER_SMALL_CHARS), ' ', '', [rfReplaceAll]);

P := Pos('x', S);
if P > 0 then
Result := StrToIntDef(ExtractFromStr(Copy(s, P, Length(S)), Numbers), 0)
else
Result := StrToIntDef(ExtractFromStr(S, Numbers), 0);

print('chatBox.getXP(): XP found: ' + tostr(result), TDebug.SUB);
end;

put your xp bar round these parts:
http://puu.sh/5Wvn0.png
http://puu.sh/5WvpJ.png
(in the larger red box)

Then just call chatbox.getxp;


---- chatBox.getXP(): XP found: 870072

Only works for 1 xp bar at a time (any xp bar you set)

You can remove the drawboxes as you please!

Sjoe
12-23-2013, 10:52 PM
lovely ash !

vwxz
12-24-2013, 03:24 AM
I'm getting the following message when I try to call this from a test script (which just logs in, waits, and calls this).


Exception in Script: Runtime error: "Access violation" at line 114, column 19 in file "C:\Simba\Includes\srl-6\lib\utilities\drawing.simba"

Any help would be appreciated!

EDIT: Is any particular height assumed for the chat box? Mine is smaller than default.

sdf
12-24-2013, 03:36 AM
Ooh, so I wasn't the only one who placed their XP bars there. Thanks!

Ashaman88
12-24-2013, 03:40 AM
I'm getting the following message when I try to call this from a test script (which just logs in, waits, and calls this).



Any help would be appreciated!

EDIT: Is any particular height assumed for the chat box? Mine is smaller than default.

Yeah remove those drawing's unless you put SmartEnableDrawing := True;

Ian
12-24-2013, 03:52 AM
Thanks Ashaman, working great! :)

Janilabo
12-24-2013, 04:44 AM
Just a little something until the devs come up with something better.

function TRSChatBox.getXP: Integer;
var
b: TBox;
s: String;
tpa : TPointArray;
atpa : T2DPointArray;
i,cts,p: Integer;
begin
b := self.getBounds();
b.edit(+(b.x2-b.x1)-140, +10, -5, -94);
smartimage.drawbox(b,false,clred);

cts := GetToleranceSpeed();
SetColorToleranceSpeed(2);

SetToleranceSpeed2Modifiers(0.00,0.00);

findColorsTolerance(tpa, 14013909, b, 4);

SetColorToleranceSpeed(CTS);
SetToleranceSpeed2Modifiers(0.2,0.2);

if length(tpa) < 2 then
begin
print('chatBox.getXP(): No XP found', TDebug.SUB);
Exit;
end;

atpa := tpa.cluster(5);

b:= atpa.getbounds;
b.edit(-2,-2,+2,+2);

smartimage.drawbox(b,false,clred);

s:=tesseractgettext(b.x1,b.y1,b.x2,b.y2, FILTER_SMALL_CHARS);

P := Pos('x', S);
if P > 0 then
Result := StrToIntDef(ExtractFromStr(Copy(s, P, Length(S)), Numbers), 0)
else
Result := StrToIntDef(ExtractFromStr(S, Numbers), 0);

print('chatBox.getXP(): XP found: ' + tostr(result), TDebug.SUB);
end;

put your xp bar round these parts:
http://puu.sh/5Wvn0.png
http://puu.sh/5WvpJ.png
(in the larger red box)

Then just call chatbox.getxp;



Only works for 1 xp bar at a time (any xp bar you set)

You can remove the drawboxes as you please!Nice work Ashaman! :)

With SRL-6 you can make it slightly shorter, easier and safer for you - by using TColorSetting methods from color utilities (https://github.com/SRL/SRL-6/blob/master/lib/utilities/color.simba) (big thanks to masterBB who added+tweaked them back then)

Example:

function TRSChatBox.getXP: Integer;
var
b: TBox;
s: String;
tpa : TPointArray;
atpa : T2DPointArray;
i,p: Integer;
begin
b := self.getBounds();
b.edit(+(b.x2-b.x1)-140, +10, -5, -94);
smartimage.drawbox(b,false,clred);

findColorsTolerance(tpa, 14013909, b, 4, colorSetting(2, 0.00, 0.00));

if length(tpa) < 2 then
begin
print('chatBox.getXP(): No XP found', TDebug.SUB);
Exit;
end;

atpa := tpa.cluster(5);

b:= atpa.getbounds;
b.edit(-2,-2,+2,+2);

smartimage.drawbox(b,false,clred);

s:=tesseractgettext(b.x1,b.y1,b.x2,b.y2, FILTER_SMALL_CHARS);

P := Pos('x', S);
if P > 0 then
Result := StrToIntDef(ExtractFromStr(Copy(s, P, Length(S)), Numbers), 0)
else
Result := StrToIntDef(ExtractFromStr(S, Numbers), 0);

print('chatBox.getXP(): XP found: ' + tostr(result), TDebug.SUB);
end;

So that way you don't have to worry about CTS stuff yourself at all.

I even explained the way it works over here (http://villavu.com/forum/showthread.php?t=101777), but that topic is based on the old style that I suggested, before masterBB came up with a lot sexier way to do it - the way SRL uses it now! :p

Basically the magic of it in a nutshell (updated from the topic above, to the SRL way):


function findColorTolerance(var x, y: Integer; color: integer; searchBox: TBox; tol: Integer; settings: TColorSettings): Boolean; overload;
var
cs: TColorSettings;
begin
// Step 1. Captures original (current) color settings in the begin to 'cs' variable
cs.retrieve();
// Step 2. Sets custom color settings (by settings) to Simba
settings.apply();
// Step 3. Performs the function, just like it should - with custom settings!
Result := findColorTolerance(x, y, color, searchBox, tol);
// Step 4. Restores the original color settings from 'cs' variable to Simba
cs.apply();
end;

-Jani

Ashaman88
12-24-2013, 04:51 AM
Nice work Ashaman! :)

With SRL-6 you can make it slightly shorter, easier and safer for you - by using TColorSetting methods from color utilities (https://github.com/SRL/SRL-6/blob/master/lib/utilities/color.simba) (big thanks to masterBB who added+tweaked them back then)

Example:

function TRSChatBox.getXP: Integer;
var
b: TBox;
s: String;
tpa : TPointArray;
atpa : T2DPointArray;
i,p: Integer;
begin
b := self.getBounds();
b.edit(+(b.x2-b.x1)-140, +10, -5, -94);
smartimage.drawbox(b,false,clred);

findColorsTolerance(tpa, 14013909, b, 4, colorSetting(2, 0.00, 0.00));

if length(tpa) < 2 then
begin
print('chatBox.getXP(): No XP found', TDebug.SUB);
Exit;
end;

atpa := tpa.cluster(5);

b:= atpa.getbounds;
b.edit(-2,-2,+2,+2);

smartimage.drawbox(b,false,clred);

s:=tesseractgettext(b.x1,b.y1,b.x2,b.y2, FILTER_SMALL_CHARS);

P := Pos('x', S);
if P > 0 then
Result := StrToIntDef(ExtractFromStr(Copy(s, P, Length(S)), Numbers), 0)
else
Result := StrToIntDef(ExtractFromStr(S, Numbers), 0);

print('chatBox.getXP(): XP found: ' + tostr(result), TDebug.SUB);
end;

So that way you don't have to worry about CTS stuff yourself at all.

I even explained the way it works over here (http://villavu.com/forum/showthread.php?t=101777), but that topic is based on the old style that I suggested, before masterBB came up with a lot sexier way to do it - the way SRL uses it now! :p

Basically the magic of it in a nutshell (updated from the topic above, to the SRL way):


function findColorTolerance(var x, y: Integer; color: integer; searchBox: TBox; tol: Integer; settings: TColorSettings): Boolean; overload;
var
cs: TColorSettings;
begin
// Step 1. Captures original (current) color settings in the begin to 'cs' variable
cs.retrieve();
// Step 2. Sets custom color settings (by settings) to Simba
settings.apply();
// Step 3. Performs the function, just like it should - with custom settings!
Result := findColorTolerance(x, y, color, searchBox, tol);
// Step 4. Restores the original color settings from 'cs' variable to Simba
cs.apply();
end;

-Jani

Yeah I think I had tried doing it the new way in another script but failed miserably haha. This makes sense now thanks man

Janilabo
12-24-2013, 05:00 AM
Yeah I think I had tried doing it the new way in another script but failed miserably haha. This makes sense now thanks manHeh, it's all cool. Glad to hear I was able to explain it!

In those cases when you are not sure exactly how it worked, you can always check out how it has been used in SRL so far, couple examples below:
https://github.com/SRL/SRL-6/blob/d7f80aab99a5e2f8b17795505d3e9b5b28d90ded/lib/interfaces/conversationbox.simba#L203
https://github.com/SRL/SRL-6/blob/627b5f3a6387733a36bc32994a7870db94d3e3d0/lib/misc/antiban.simba#L620

..but yeah, it should be actually easier way than the old one is... Might look/feel a bit weird first, but once you get it rolling it's a nice time saver for you. :) Just takes some time to get used to it, for sure.

Ashaman88
12-24-2013, 05:23 AM
Heh, it's all cool. Glad to hear I was able to explain it!

In those cases when you are not sure exactly how it worked, you can always check out how it has been used in SRL so far, couple examples below:
https://github.com/SRL/SRL-6/blob/d7f80aab99a5e2f8b17795505d3e9b5b28d90ded/lib/interfaces/conversationbox.simba#L203
https://github.com/SRL/SRL-6/blob/627b5f3a6387733a36bc32994a7870db94d3e3d0/lib/misc/antiban.simba#L620

..but yeah, it should be actually easier way than the old one is... Might look/feel a bit weird first, but once you get it rolling it's a nice time saver for you. :) Just takes some time to get used to it, for sure.

Yeah I think I had tried basing off of an include function (that's how I first learned about it) but I must have been doing something crazy w/ the parameters and overload stuff

sdf
12-24-2013, 07:15 AM
http://i.imgur.com/Q8R2nOt.png

This happens occasionally.

Ashaman88
12-24-2013, 02:46 PM
http://i.imgur.com/Q8R2nOt.png

This happens occasionally.

Strange any idea why the +xp dealio is so far to the left? Mine is normally right next to it. But I got's some idears

Edit: sdf try the updated on in the OP

sdf
12-25-2013, 02:50 PM
Strange any idea why the +xp dealio is so far to the left? Mine is normally right next to it. But I got's some idears

Edit: sdf try the updated on in the OP

Works well :thumbsup: