SRL Archive - OSR Help

Get Username from chatbox


Sable

2015-01-29 20:16:49

Can anyone help me write a script that reads chatbox usernames in oldschool runescape?

Right now im at this

function Check_trade: boolean;
var
I: Integer;
S: String

begin
For I:=8 downto 1 do
begin
S := getChatBoxText(I, 0);
If (S = '')then
Continue;

new_str = str.copy(1, pos(' wishes to trade', str))
Result := str.copy
If Result then
Click_Trade;
end;
end;


ty

Flight

2015-01-29 23:12:49

Untested but give this a shot:

function Check_trade(): boolean;
var
i : Integer;
s : String
begin
for i:=8 downto 1 do
if (Pos('wishes to trade', getChatBoxText(i, clPurple)) > 0) then
begin
result := true;
s := getChatBoxText(i, clPurple);
between(s, s[0], ' wishes');
end;

if Result then
Click_Trade();
end;

Turpinator

2015-01-29 23:52:14

From: Flight
Untested but give this a shot:

function Check_trade(): boolean;
var
i : Integer;
s : String
begin
for i:=8 downto 1 do
if (Pos('wishes to trade', getChatBoxText(i, clPurple)) > 0) then
begin
result := true;
s := getChatBoxText(i, clPurple);
between(s, s[0], ' wishes');
end;

if Result then
Click_Trade();
end;



function Check_trade(out name: string): boolean;
var
i : Integer;
begin
result := false;
for i := 8 downto 1 do
begin
s := getChatBoxText(i, clPurple);
if s <> '' then
begin
s := s[1] + between(s, s[1], ' wishes to');
result := lenghth(s) > 0
if result then
break;
end;
end;
if Result then
Click_Trade();
end;
what about this?

not sure what exactly hes looking for.
But you have an issue with your between usage, @Flight; (yours is not assigned to anything, and youre not supposed to access s[0])

Flight

2015-01-30 00:07:24

From: Turpinator

function Check_trade(out name: string): boolean;
var
i : Integer;
begin
result := false;
for i := 8 downto 1 do
begin
s := getChatBoxText(i, clPurple);
if s <> '' then
begin
s := s[1] + between(s, s[1], ' wishes to');
result := lenghth(s) > 0
if result then
break;
end;
end;
if Result then
Click_Trade();
end;
what about this?

not sure what exactly hes looking for.
But you have an issue with your between usage, @Flight; (yours is not assigned to anything, and youre not supposed to access s[0])


Oh yeah you're right, I forgot my "s :=" (too used to wrappers). Yes forget character positions in a string begin with index [1] rather than the normal [0] and I also forgot to break the loop. Perhaps next time when I tried to help someone I'll focus on that and not 2 other tasks at the same time. :wacko:

Sable

2015-01-30 07:56:33

I am not entirely sure but i think what that does is, if someone wishes to trade you it will click the trade request.

What im looking for is to trim the string 'Sparc mac wishes to trade you' and make it only return the name sparc mac as result.

Also Error: Unknown declaration "s" at line 23

And just a small notice, im using Aerolib for oldschool.

Thanks alot!

Sable

2015-01-30 08:09:32

This is what im at now.

function Check_trade(out name: string): boolean;
var
i : Integer;
s : String;
begin
result := false;
for i := 8 downto 1 do
begin
s := getChatBoxText(i, clPurple);
if s <> '' then
begin
s := s[1] + between(s, s[1], ' wishes to');
result := lenghth(s) > 0
if result then
break;
end;
end;
if Result then
Click_Trade();
end;

Flight

2015-01-30 08:41:55

This should return true if a trade request is found, output the requester's name and left-click their trade request in the chat box: (again, untested)

function Check_trade(out name: string): boolean;
var
s : String;
p : TPoint;
i,h : Integer;
begin
result := false;
for i := 8 downto 1 do
begin
s := getChatBoxText(i, clPurple);
if s <> '' then
begin
name := s[1] + between(s, s[1], ' wishes to');
result := length(name) > 0;
h := i;
if result then
break;
end;
end;

if Result then
begin
p := getTextCoords(h);
mouseBox(toBox(MCX1,P.y,MCX2,P.y+13), MOUSE_LEFT); // Left-click the chat line with the trade request
end;
end;

Lipcot

2015-01-30 09:10:46

From: Sable
This is what im at now.

function Check_trade(out name: string): boolean;
var
i : Integer;
s : String;
begin
result := false;
for i := 8 downto 1 do
begin
s := getChatBoxText(i, clPurple);
if s <> '' then
begin
s := s[1] + between(s, s[1], ' wishes to');
result := lenghth(s) > 0
if result then
break;
end;
end;
if Result then
Click_Trade();
end;


remember you can use
 and your code will appear ordered and highlited

Sable

2015-01-30 09:12:32

Thanks!, forgot how to do it.