SRL Archive - RS3 Outdated / Broken Scripts

[REQ] Trade: Check & Accept Function


Trifonius

2008-01-20 06:30:21

function TradeCheckAccept( TradeWith : String): Boolean;

I'm in need of a function that checks for trade requests and compares the name of the player that wants to trade to the TradeWith String. The TradeWith string contains the name of the player that the function must accept trade requests from.
It has to be able to pick out the right trade request when there are multiple traderequests by different players in a short time.

Don't make a function that accepts trades form anyone and then checks if it is the right player, that would be to slow.

I tried to make this myself, but failed :(

Thx in advance

ZephyrsFury

2008-01-20 06:52:30

Oh sounds fun…. Good for you I'm rather bored atm… I'll see what I can do.

Sir R. M8gic1an

2008-01-20 07:02:24

check out amount.scar and trade.scar you'll see you have all you need in there.

Open Trade, Get Trader Name. GetTextAtEx can also be useful, search for the name you want in the text box, then move to it and if uptext('trade'); then click on it.

~RM

ZephyrsFury

2008-01-20 07:11:43

From: Rasta Magician
check out amount.scar and trade.scar you'll see you have all you need in there.

Open Trade, Get Trader Name. GetTextAtEx can also be useful, search for the name you want in the text box, then move to it and if uptext('trade'); then click on it.

~RM


He doesn't want to open the trade then check.

EDIT:


function TradeCheckAccept(TradeWith: TStringArray): Boolean;
var
k, c, Tx, Ty: Integer;
TP: TPoint;
Text, Name: string;
CPts: TPointArray;
begin
if (not(LoggedIn)) then Exit;
for k := 8 downto 1 do
begin
TP := TextCoords(k);
if (FindColor(Tx, Ty, 8388736, TP.x, TP.y, TP.x + 200, TP.y + 14)) then
begin
WriteLn('Found Trade');
Text := Trim(GetTextAtEx(TP.x - 2, TP.y - 2, 0, SmallChars,
False, False, 0, 1, 8388736, 60, False, tr_allChars));
Name := Copy(Text, 1, Pos('wi', Text) - 1);
WriteLn(Name + ' wishes to trade');
if (not(InStrArr(Name, TradeWith, True))) then Continue;
WriteLn(Name + ' was in TradeWith array, trading...');
FindColorsTolerance(CPts, 8388736, TP.x, TP.y, TP.x + 200, TP.y + 14, 0);
MiddleTPAEx(CPts, Tx, Ty);
c := 0;
while (not(TradeScreen)) do
begin
Mouse(Tx, Ty, 50, 5, True);
Wait(5000);
Inc(c);
if (c >= 5) then
begin
WriteLn('Could not open bank screen');
Exit;
end;
end;
Result := True;
Exit;
end;
end;

I used an array instead of a single string because I believe it would be more useful. So to use it:


if (TradeCheckAccept(['tradewithme', 'imonthelist', 'this function is leet'])) then WriteLn('Blah blah');

Tell me if it doesn't work. I haven't tested it.

Sir R. M8gic1an

2008-01-20 14:14:43

i don't understand what this line does:

if (not(InStrArr(Name, TradeWith, True))) then Continue;

what does the continue do? could you please explain it to me?

~RM

ZephyrsFury

2008-01-21 00:29:18

From: Rasta Magician
i don't understand what this line does:

if (not(InStrArr(Name, TradeWith, True))) then Continue;

what does the continue do? could you please explain it to me?

~RM


If the name of the person trading is not in the TradeWith array, it skips the part where it opens the trade (the mouseclick and the wait) and goes to the next line in the chatbox and looks for another trade.

The continue is used in a loop. When it is called, it skips the rest of the loop and goes back to the beginning. So in this script:


for i := 0 to 10 do
begin
if (i mod 2 = 1) then Continue;
WriteLn(IntToStr(i));
end;

it will only print the even numbers because when it is an odd number it skips the WriteLn and goes back to the start.