PDA

View Full Version : [RS3] IsMouseoverText



Ian
07-23-2013, 09:58 AM
Before reading: I've noticed that there is something in SRL6 to get text from the MainScreen, but I'd made this before thinking to check and SRL6 has not yet been released so I might as well post it now.

So as you may or may not have noticed, there appears to be no UpText in RS3. So you can still check that what you're clicking on is the right thing, I've made IsMouseOverText.

Functions:
function IsMouseoverTextEx(Text, TextType:string): Boolean;
var
x, y, Color: Integer;
begin
Color := 0;
case Lowercase(TextType) of
'action', 'white': Color:= 12378347;
'object', 'cyan': Color:= 16776960;
'npc', 'yellow': Color:= 65535;
'f2pitem', 'pale blue': Color:= 13750712;
'p2pitem', 'orange': Color:= 2131675;
end;
if (Color = 0) then
begin
WriteLn('WARNING! ' + TextType + ' is not a valid TextType!');
Exit;
end;
GetMousePos(x, y);
Result := IsTextInAreaEx(0, 0, 798, 598, x, y, Text, 5, 'UpCharsEx', False, False, 0, 4, Color);
end;

function IsMouseoverText(Text : string) : Boolean; //By Rich
var
I : Integer;
Types : TStringArray;

begin
Types:= ['action', 'object', 'npc', 'f2pitem' 'p2pitem'];
for I:= 0 to 4 do
begin
Result:= IsMouseOverTextEx(Text, Types[I]);
if Result then
Exit;
end;
end;

Requirements for use: Make sure that you have Mouseover text enabled. Enable it in the graphics setting here:
http://i.imgur.com/3GD0dJ8.png

How to choose text:

Choose some text that doesn't have any capitals or odd symbols. Some capitals work but not all, so if your string with a capital doesn't work then try it without.

Do not use multi-line strings, they do not work.

Here's an example of text that you want, the green boxes are around good samples, the red around bad samples:
http://i.imgur.com/wmlyf4e.png

How to use in a script:

Example #1 (http://villavu.com/forum/usertag.php?do=list&action=hash&hash=1) :

if IsMouseoverTextEx('xchange', 'npc') then
begin
WriteLn('Mouse is over the GE clerk!');
ClickMouse(True);
end;


Example #2 (http://villavu.com/forum/usertag.php?do=list&action=hash&hash=2) :

if IsMouseoverText('xchange') then
begin
WriteLn('Mouse is over the GE clerk!');
ClickMouse(True);
end;


The first parameter in IsUptextEx, Text, is the string you've chosen to look for. The second parameter, TextType, is the type of text that you want the function to look for.

IsUptext is the same as IsUptextEx except it only has the text parameter. It will look for UpText text in all five TextTypes by default.

Valid arguments for TextType are:

'action' //(White text)
'object' //(Cyan text)
'npc' //(Yellow text)
'f2pitem' //(Pale Blue text)
'p2pitem' //(Orange text)

'white' //(Action)
'cyan' //(Object)
'yellow' //(NPC)
'pale blue' //(F2P Item)
'orange' //(P2P Item)


If you have any questions/suggestions feel free to post, hopefully this will be useful to people as a substitute to UpText until SRL6 is released :)

You can also use GetMouseOverText to show you what IsMouseoverText is seeing. Useful for debugging purposes.

function GetMouseoverText(TextType:string): string;
var
Color: Integer;
begin
Color := 0;
case Lowercase(TextType) of
'action', 'white': Color:= 12378347;
'object', 'cyan': Color:= 16776960;
'npc', 'yellow': Color:= 65535;
'f2pitem', 'pale blue': Color:= 13750712;
'p2pitem', 'orange': Color:= 2131675;
end;
if (Color = 0) then
begin
WriteLn('WARNING! ' + TextType + ' is not a valid TextType!');
Exit;
end;
Result := GetTextAtExWrap(0, 0, 798, 598, 0, 4, 1, Color, 5, 'UpCharsEx');
end;

xtrapsp
07-23-2013, 10:00 AM
I love you

Itankbots
07-23-2013, 10:02 AM
Very nice man!!

Rich
07-23-2013, 10:49 AM
Very nice. Possibly have an "Ex" function as well as a simpler one?

Eg:

function IsMouseoverTextEx(Text, TextType:string): Boolean;
var
x, y, Color: Integer;
begin
case Lowercase(TextType) of
'action': Color:= 12378347;
'object': Color:= 16776960;
'npc': Color:= 65535;
end;
GetMousePos(x, y);
Result := IsTextInAreaEx((x + 32), (y + 34), (x + 209), (y + 75), x, y, Text, 5, 'UpCharsEx', False, False, 0, 4, Color);
end;

function IsMouseoverText(Text : string) : Boolean;
var
I : Integer;
Types : TStringArray;

begin
Types:= ['action', 'object', 'npc'];
for I:= 0 to 2 do
begin
Result:= IsMouseOverTextEx(Text, Types[I]);
if Result then
Exit;
end;
end;

EDIT: It might also be better to just replace the uptext functions with this so every time an uptext check is called it doesn't have to be changed.

Ian
07-23-2013, 10:55 AM
Very nice. Possibly have an "Ex" function as well as a simpler one?

Eg:

function IsMouseoverTextEx(Text, TextType:string): Boolean;
var
x, y, Color: Integer;
begin
case Lowercase(TextType) of
'action': Color:= 12378347;
'object': Color:= 16776960;
'npc': Color:= 65535;
end;
GetMousePos(x, y);
Result := IsTextInAreaEx((x + 32), (y + 34), (x + 209), (y + 75), x, y, Text, 5, 'UpCharsEx', False, False, 0, 4, Color);
end;

function IsMouseoverText(Text : string) : Boolean;
var
I : Integer;
Types : TStringArray;

begin
Types:= ['action', 'object', 'npc'];
for I:= 0 to 2 do
begin
Result:= IsMouseOverTextEx(Text, Types[I]);
if Result then
Exit;
end;
end;

Good idea! And the simple one will be good for most things, as it won't be that common to have a near duplicate uptext for different text types anyway :)

E: It has been brought to my attention that this does not include colors for items. And because of the moveable inventories and whatnot the original tactic of looking in the area of the box will not work. So I'm going to add the light blue item color, and change the search to the whole screen.

Following Rich's format (and keeping his simplified version of IsMouseoverTexr :)),

function IsMouseoverTextEx(Text, TextType:string): Boolean;
var
x, y, Color: Integer;
begin
case Lowercase(TextType) of
'action': Color:= 12378347;
'object': Color:= 16776960;
'npc': Color:= 65535;
'item': Color:= 13750712;
end;
Result := IsTextInAreaEx(0, 0, 798, 598, x, y, Text, 5, 'UpCharsEx', False, False, 0, 4, Color);
end;

function IsMouseoverText(Text : string) : Boolean;
var
I : Integer;
Types : TStringArray;

begin
Types:= ['action', 'object', 'npc', 'item'];
for I:= 0 to 3 do
begin
Result:= IsMouseOverTextEx(Text, Types[I]);
if Result then
Exit;
end;
end;

I tested and this now works for items in the inventory as well :)

E2: Copying updated version(s) to the OP

Rich
07-23-2013, 07:19 PM
for I:= 0 to 2 doshould be changed tofor I:= 0 to 3 dowith the addition of the new colour :)

Ian
07-23-2013, 07:25 PM
for I:= 0 to 2 doshould be changed tofor I:= 0 to 3 dowith the addition of the new colour :)

I missed that, thank you :)

Turpinator
07-25-2013, 02:58 PM
Glad to see you added the extra colors. :)

also, added a 'multi' version so that you can input a string array.
function IsMouseoverTextEx(Text: TStringArray; TextType:string): Boolean;
var
x, y, Color, i: Integer;
begin
case Lowercase(TextType) of
'action', 'white': Color:= 12378347;
'object', 'cyan': Color:= 16776960;
'npc', 'yellow': Color:= 65535;
'f2pitem', 'blue': Color:= 13750712;
'p2pitem', 'orange': Color:= 2131675;
else begin
WriteLn('WARNING! ' + TextType + ' is not a valid TextType!');
Exit;
end;
end;
GetMousePos(x, y);
for i := 0 to length(Text) - 1 do
begin
Result := IsTextInAreaEx(0, 0, 798, 598, x, y, Text[i], 5, 'UpCharsEx', False, False, 0, 4, Color);
if Result then Exit;
end;
end;

function IsMouseoverText(Text : string) : Boolean; //By Rich
var
I : Integer;
Types : TStringArray;

begin
Types:= ['action', 'object', 'npc', 'f2pitem','p2pitem'];
for I:= 0 to 4 do
begin
Result:= IsMouseOverTextEx([Text], Types[I]);
if Result then
Exit;
end;
end;

function IsMouseoverTextMulti(Text : TStringArray) : Boolean;
var
I : Integer;
Types : TStringArray;
begin
Types:= ['action', 'object', 'npc', 'f2pitem','p2pitem'];
for I:= 0 to 4 do
begin
Result:= IsMouseOverTextEx(Text, Types[I]);
if Result then
Exit;
end;
end;


also changed the case to use an else for throwing the error. (didnt test it, so im not too sure if the syntax is correct)

also, i do believe this will not always work, ie if your mouse is super close to the side of the screen and the game automatically moves the mousebox.

Ian
07-25-2013, 03:22 PM
Glad to see you added the extra colors. :)

also, added a 'multi' version so that you can input a string array.
-Stuff-


also changed the case to use an else for throwing the error. (didnt test it, so im not too sure if the syntax is correct)

also, i do believe this will not always work, ie if your mouse is super close to the side of the screen and the game automatically moves the mousebox.

I'll add the multi version to the op as well, than you :)

I'll test the case else.

As for the not always working because of the game moving the hover box when close to the side of the screen, that's the reason that I made it search the whole screen and not just the part determined by GetMousePos. I just had forgot to remove GetMousePos from the function, but as you can see it does not use it :)

So yes it should work all the time :)

Turpinator
07-25-2013, 04:13 PM
I'll add the multi version to the op as well, than you :)

I'll test the case else.

As for the not always working because of the game moving the hover box when close to the side of the screen, that's the reason that I made it search the whole screen and not just the part determined by GetMousePos. I just had forgot to remove GetMousePos from the function, but as you can see it does not use it :)

So yes it should work all the time :)

oh yeah i didnt see you changed it to the whole screen. id suggest using getclientdimensions(w,h) so it searches the whole thing no matter how big someone has their smart set to be. You could also just search for a large area around the mouse rather than the whole screen for sake of speed. might have to logic so that it doesnt try to search off screen if your mouse is near the edge.

Sjoe
07-25-2013, 11:26 PM
function WaitMouseOverTextMulti(Text : TStringArray; Time: Integer) : Boolean;
var
T: Integer;
begin
Result := false;
T := GetSystemTime + Time;
while (GetSystemTime < T) do
begin
if (IsMouseOverTextMulti(Text)) then
begin
Result := True;
Exit;
end;
Wait(20 + Random(20));
end;
end;

Rich
07-25-2013, 11:51 PM
function WaitMouseOverTextMulti(Text : TStringArray; Time: Integer) : Boolean;
var
T: Integer;
begin
Result := false;
T := GetSystemTime + Time;
while (GetSystemTime < T) do
begin
if (IsMouseOverTextMulti(Text)) then
begin
Result := True;
Exit;
end;
Wait(20 + Random(20));
end;
end;


function WaitMouseOverTextMulti(Text : TStringArray; Time: Integer) : Boolean;
begin
Result := WaitFuncEx('IsMoveOverTextMulti', [Text], 25, Time) : Boolean;
end; :p

Sjoe
07-26-2013, 12:02 AM
function WaitMouseOverTextMulti(Text : TStringArray; Time: Integer) : Boolean;
begin
Result := WaitFuncEx('IsMoveOverTextMulti', [Text], 25, Time) : Boolean;
end; :p

U know how to get WaitFuncEx to work, I applaud sir. Well played :)

Ian
07-28-2013, 07:25 AM
Added GetMouseoverText, useful for those wishing to find out what IsMouseoverTextEx is actually "seeing"

function GetMouseoverText(TextType:string): string;
var
Color: Integer;
begin
Color := 0;
case Lowercase(TextType) of
'action', 'white': Color:= 12378347;
'object', 'cyan': Color:= 16776960;
'npc', 'yellow': Color:= 65535;
'f2pitem', 'pale blue': Color:= 13750712;
'p2pitem', 'orange': Color:= 2131675;
end;
if (Color = 0) then
begin
WriteLn('WARNING! ' + TextType + ' is not a valid TextType!');
Exit;
end;
Result := GetTextAtExWrap(0, 0, 798, 598, 0, 4, 1, Color, 5, 'UpCharsEx');
end;


Works well for single-line things, kinda thrown off by multi liners.

Test code:

WriteLn('Action: ' + GetMouseoverText('action'));
WriteLn('NPC: ' + GetMouseoverText('npc'));


http://i.imgur.com/6l4G37z.png



Action: Talk-to
NPC: Banker
Successfully executed.


http://i.imgur.com/wqAbVFA.png



Action: Talk-to
NPC: Grac nledrkExchange
Successfully executed.