SRL Archive - SRL Archives

Grand Exchange.scar !


Sir R. M8gic1an

2009-02-18 08:43:44

To all you merchanters out there… I am now giving you the power to bend the GE to your will, to forge it with your owns hands, to automatized the cash flows in runescape… I am giving you… the first… include for the Grand Exchange!


//------------------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- » Grand Exchange Routines --//
//------------------------------------------------------------------------//
// * Procedure SetupGE; // * by Rasta Magician
// * Function InGE: boolean; // * by Rasta Magician
// * Function GEIsMember: boolean; // * by Rasta Magician
// * Function GESellMenu: boolean; // * by Rasta Magician
// * Function GEBuyMenu: boolean; // * by Rasta Magician
// * Procedure GEMenuExit; // * by Rasta Magician
// * Function GESpotToTBox(spot: integer): TBox; // * by Rasta Magician
// * Function GEIsSpotFree(spot: integer):boolean; // * by Rasta Magician
// * Function GEFinishedAt(spot: integer): boolean; // * by Rasta Magician
// * Procedure GERecoverAtEx(spot: integer; abort:boolean); // * by Rasta Magician
// * Procedure GERecoverAt(spot: integer); // * by Rasta Magician
// * Procedure GERecoverFinishedAt(spot: integer); // * by Rasta Magician
// * Procedure GEAbortAll; // * by Rasta Magician
// * Procedure GERecoverAll; // * by Rasta Magician
// * Procedure GERecoverFinished; // * by Rasta Magician
// * Function GEFindFreeSpot(var spot:integer): boolean; // * by Rasta Magician
// * Function GESellAt(spot: integer): boolean; // * by Rasta Magician
// * Function GEBuyAt(spot: integer): boolean; // * by Rasta Magician
// * Function GESetPrice(value: string): boolean; // * by Rasta Magician
// * Procedure GESetQuantity(Q: string); // * by Rasta Magician
// * Function GEConfirmOffer: boolean; // * by Rasta Magician
// * Function GEBuy(What, Price, Quantity: string): boolean; // * by Rasta Magician
// * Function GESell(Price, Quantity: string; InvSpot: integer): boolean; // * by Rasta Magician
//------------------------------------------------------------------------//

I have not done any functions to Find the GE or to Open the GE. Those are easy enought to do for anyone who wishes to do so. This scar file deals purely with the management of the GE "inside" of it. There are no web connections to check price changes nor anything like that.
This is my contribution to hitting the RS markets. Where I am strong i have contribued. Now it is up to you to do the rest.

The most interesting functions:

{*******************************************************************************
Function GEBuy(What, Price, Quantity: string): boolean;
By: Rasta Magician
Description: Buys an item from the GE
What (item name) has to be exact
Price: 'min', 'med', 'max', exact value
Quantity: '1', '10', '100', '1000', exact value
*******************************************************************************}


{*******************************************************************************
Function GESell(Price, Quantity: string; InvSpot: integer): boolean;
By: Rasta Magician
Description: Sells an item at GE
Price: 'min', 'med', 'max', exact value
Quantity: '1', '10', '100', 'all', exact value
InvSpot: the Invspot where you have your item
*******************************************************************************}


{*******************************************************************************
Procedure GERecoverAtEx(spot: integer; abort:boolean);
By: Rasta Magician
Description: Collects the items traded received at a certain spot
Aborts the trade is boolean abort is set to true
*******************************************************************************}


I sure hope to see some merchanting scripts soon!

A little run to test: (open ge by yourself)

{.include srl/srl.scar}
{.include srl/srl/misc/GE.scar}

begin
GEBuy('fire rune', 'min', '1');
GEBuy('fire rune', 'med', '10');
GEBuy('fire rune', 'max', '5');
wait(2000);
GERecoverFinished;
end;



//------------------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- » Grand Exchange Routines --//
//------------------------------------------------------------------------//
// * Procedure SetupGE; // * by Rasta Magician
// * Function InGE: boolean; // * by Rasta Magician
// * Function GEIsMember: boolean; // * by Rasta Magician
// * Function GESellMenu: boolean; // * by Rasta Magician
// * Function GEBuyMenu: boolean; // * by Rasta Magician
// * Procedure GEMenuExit; // * by Rasta Magician
// * Function GESpotToTBox(spot: integer): TBox; // * by Rasta Magician
// * Function GEIsSpotFree(spot: integer):boolean; // * by Rasta Magician
// * Function GEFinishedAt(spot: integer): boolean; // * by Rasta Magician
// * Procedure GERecoverAtEx(spot: integer; abort:boolean); // * by Rasta Magician
// * Procedure GERecoverAt(spot: integer); // * by Rasta Magician
// * Procedure GERecoverFinishedAt(spot: integer); // * by Rasta Magician
// * Procedure GEAbortAll; // * by Rasta Magician
// * Procedure GERecoverAll; // * by Rasta Magician
// * Procedure GERecoverFinished; // * by Rasta Magician
// * Function GEFindFreeSpot(var spot:integer): boolean; // * by Rasta Magician
// * Function GESellAt(spot: integer): boolean; // * by Rasta Magician
// * Function GEBuyAt(spot: integer): boolean; // * by Rasta Magician
// * Function GESetPrice(value: string): boolean; // * by Rasta Magician
// * Procedure GESetQuantity(Q: string); // * by Rasta Magician
// * Function GEConfirmOffer: boolean; // * by Rasta Magician
// * Function GEBuy(What, Price, Quantity: string): boolean; // * by Rasta Magician
// * Function GESell(Price, Quantity: string; InvSpot: integer): boolean; // * by Rasta Magician
//------------------------------------------------------------------------//

var
GEbmp: integer;

{*******************************************************************************
Procedure SetupGE;
By: Rasta Magician
Description: Sets up everything needed for the GE
*******************************************************************************}
Procedure SetupGE;
begin
GEbmp := BitmapFromString(5, 15, 'beNpbW7q1mOH5Wobnexn+/38PZ' +
'FgaSrRYQlGQpSZ1ZaudOCCyUZYMaLLVTootbpoQ2WJLxfdri9/vav' +
'm+d873Y3O/n9v4fW8PkHtvIwhdm1P8fmv1ymwnoBXZXoZTkp2uTUk' +
'Gcu/1RQF1/T/Wc29S8vOl2ffmgMjnAECCbl0=');
end;


{*******************************************************************************
Function InGE: boolean;
By: Rasta Magician
Description: Checks if we are in GE
*******************************************************************************}
Function InGE: boolean;
var x, y: integer;
begin
Result := FindBitmapIn(GEbmp, x, y, 27, 28, 58, 56);
end;


{*******************************************************************************
Function GEIsMember: boolean;
By: Rasta Magician
Description: Checks if it is a member account using GE
*******************************************************************************}
Function GEIsMember: boolean;
begin
if not InGE then exit;
if GetColor(411, 167) <> 65536 then
if GetColor(410, 155) <> 5199452 then
begin
Result := true;
exit;
end;

if GetColor(411, 167) <> 5199452 then //to avoid jagex moving 1px
if GetColor(410, 155) <> 65536 then
begin
Result := true;
exit;
end;

Result := false;
end;


{*******************************************************************************
Function GESellMenu: boolean;
By: Rasta Magician
Description: Checks if we are in the sell menu
*******************************************************************************}
Function GESellMenu: boolean;
begin
if not InGE then exit;
Result := (GetColor(187, 73) = 45055);
end;


{*******************************************************************************
Function GEBuyMenu: boolean;
By: Rasta Magician
Description: Checks if we are in the buy menu
*******************************************************************************}
Function GEBuyMenu: boolean;
begin
if not InGE then exit;
Result := (GetColor(186, 74) = 61385);
end;


{*******************************************************************************
Procedure GEMenuExit;
By: Rasta Magician
Description: Exits the Buy or Sell menu
*******************************************************************************}
Procedure GEMenuExit;
var i, x:integer;
begin
if not InGE then exit;
if not GESellMenu then
if not GEBuyMenu then
exit;

MMouse(40, 291, 18, 9);

for i:= 0 to 5 do
begin
wait(100);
if IsUpText('ack') then break;
end;

if IsUpText('ack') then
begin
GetMousePos(x, i);
Mouse(x, i, 0, 0, true);
for i:= 0 to 5 do
begin
wait(150);
if not GESellMenu then
if not GEBuyMenu then
break;
end;
end;

end;


{*******************************************************************************
Function GESpotToTBox(spot: integer): TBox;
By: Rasta Magician
Description: Returns the coords of a box in GE
*******************************************************************************}
Function GESpotToTBox(spot: integer): TBox;
var
i, x1, x2, y1, y2: integer;
begin
{
box width: 140
box height: 112
gap hor: 16
gap ver: 8
}
if spot > 3 then
i := spot - 3 - 1
else
i := spot - 1 ;

x1 := 32 + (16 + 140)*i;
x2 := 172 + (16 + 140)*i;

if spot > 3 then
i := 1
else
i := 0;

y1 := 82 + (112 + 8)*i;
y2 := 194 + (112 + 8)*i;

Result := IntToBox(x1, y1, x2, y2);
end;


{*******************************************************************************
Function GEIsSpotFree(spot: integer):boolean;
By: Rasta Magician
Description: Checks if a spot is available for buying/selling
*******************************************************************************}
Function GEIsSpotFree(spot: integer):boolean;
var TB: TBox;
begin
if not InGE then exit;
if spot > 2 then
if not GEIsMember then
exit;

TB := GESpotToTBox(spot);
Result := (GetColor(TB.x1 + 9, TB.y2 - 30) <> 0);
writeln('coords: '+IntToStr(TB.x1+9)+', '+ IntToStr(TB.y2 -30));
end;


{*******************************************************************************
Function GEFinishedAt(spot: integer): boolean;
By: Rasta Magician
Description: Checks if a trade has been concluded at spot: spot
*******************************************************************************}
Function GEFinishedAt(spot: integer): boolean;
var TB: TBox;
begin
if not InGE then exit;
if spot > 2 then
if not GEIsMember then exit;

if not GEIsSpotFree(spot) then
begin
TB := GESpotToTBox(spot);
Result := ( GetColor(TB.x1 + 103, TB.y2 - 20) = 1999423 );
end;
end;


{*******************************************************************************
Procedure GERecoverAtEx(spot: integer; abort:boolean);
By: Rasta Magician
Description: Collects the items traded received at a certain spot
Aborts the trade is boolean abort is set to true
*******************************************************************************}
Procedure GERecoverAtEx(spot: integer; abort:boolean);
var
TB: TBox;
i, x, y: integer;
begin
if not InGE then exit;
if GEIsSpotFree(spot) then exit;
if spot > 2 then
if not GEIsMember then
exit;

TB := GESpotToTBox(spot);
MouseBox(TB.x1, TB.y1, TB.x2, TB.y2, 1);
wait(200);

for i:= 0 to 10 do
begin
if (GESellMenu)or(GEBuyMenu) then
break;
wait(150);
end;

if abort then
if (GetColor(359, 312) <> 1999423) then
begin

MMouse(364, 285, 5, 5); //moving to button
wait(100);

for i:= 0 to 5 do // waiting text
begin
if IsUpText('bort') then break;
wait(100);
end;

if IsUpText('bort') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
end;

for i:= 0 to 10 do //waiting until aborted
begin
wait(100);
if (GetColor(202, 309) = 1048714) then break;
end;
wait(200+Random(300));
end;

//collecting spot 1 //
MMouse(416, 299, 5, 5);

for i:= 0 to 5 do // waiting text
begin
if IsUpText('ollect') then break;
wait(100);
end;

if IsUpText('ollect') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
end;

wait(100+Random(200));

//collecting spot 1 //

if (GetColor(467, 298) <> 2176579) then // spot 2
begin
MMouse(467, 298, 5, 5);

for i:= 0 to 5 do // waiting text
begin
if IsUpText('ollect') then break;
wait(100);
end;

if IsUpText('ollect') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
end;

wait(100+Random(200));

end;

for i:=0 to 10 do
begin
wait(150);
if not GESellMenu then
if not GEBuyMenu then
break;
end;

GEMenuExit; //just if something went wrong
end;


{*******************************************************************************
Function Procedure GERecoverAt(spot: integer);
By: Rasta Magician
Description: Recovers items at spot: spot, does not abort the trade
*******************************************************************************}
Procedure GERecoverAt(spot: integer);
begin
GERecoverAtEx(spot, false);
end;


{*******************************************************************************
Procedure GERecoverFinishedAt(spot: integer);
By: Rasta Magician
Description: Recovers items at spot: spot if the trade is concluded
*******************************************************************************}
Procedure GERecoverFinishedAt(spot: integer);
begin
if not InGE then exit;
if GEFinishedAt(spot) then
GERecoverAtEx(spot, false);
end;


{*******************************************************************************
Procedure GEAbortAll;
By: Rasta Magician
Description: Aborts and recovers all current trades
*******************************************************************************}
Procedure GEAbortAll;
var i:integer;
begin
for i:= 1 to 6 do
GERecoverAtEx(i, true);
end;


{*******************************************************************************
Procedure GERecoverAll;
By: Rasta Magician
Description: Recovers all current trades, does not abort
*******************************************************************************}
Procedure GERecoverAll;
var i:integer;
begin
for i:= 1 to 6 do
GERecoverAt(i);
end;


{*******************************************************************************
Procedure GERecoverFinished;
By: Rasta Magician
Description: Recovers all finished trades
*******************************************************************************}
Procedure GERecoverFinished;
var i:integer;
begin
for i:= 1 to 6 do
GERecoverFinishedAt(i);
end;


{*******************************************************************************
Function GEFindFreeSpot(var spot:integer): boolean;
By: Rasta Magician
Description: Finds a free spot to trade in
*******************************************************************************}
Function GEFindFreeSpot(var spot:integer): boolean;
var i:integer;
begin
if not InGE then exit;

Result := false;
spot := 0;

for i:= 1 to 6 do
if GEIsSpotFree(i) then
begin
spot := i;
Result := true;
break;
end;

end;


{*******************************************************************************
Function GESellAt(spot: integer): boolean;
By: Rasta Magician
Description: Presses the sell button at spot: spot
*******************************************************************************}
Function GESellAt(spot: integer): boolean;
var
TB: TBox;
x, y: integer;
begin
if not InGE then exit;
if not GEIsSpotFree(spot) then
begin
writeln('space is not free!');
exit;
end;

TB := GESpotToTBox(spot);
MMouse(TB.x1 + 100, TB.y1 + 65, 5, 5);
wait(150+Random(75));

if IsUpText('ell') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
end;

for x:= 0 to 9 do
begin
wait(100);
if GESellMenu then break;
end;

Result := GESellMenu;
end;


{*******************************************************************************
Function GEBuyAt(spot: integer): boolean;
By: Rasta Magician
Description: Presses the buy button at spot: spot
*******************************************************************************}
Function GEBuyAt(spot: integer): boolean;
var
TB: TBox;
x, y: integer;
begin
if not InGE then exit;
if not GEIsSpotFree(spot) then
begin
writeln('space is not free!');
exit;
end;

TB := GESpotToTBox(spot);
MouseBox(TB.x1 + 35, TB.y1 + 50, TB.x1 + 65, TB.y1 + 80, 3);
wait(150+Random(75));

if IsUpText('Buy') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
end;

for x:= 0 to 9 do
begin
wait(100);
if GEBuyMenu then break;
end;

Result := GEBuyMenu;
end;


{*******************************************************************************
Function GESetPrice(value: string): boolean;
By: Rasta Magician
Description: Sets the price of an item.
'0', 'min' - Minimum Value
'1', 'med' - Market Value
'2', 'max' - Max value
Other - Exact value
*******************************************************************************}
Function GESetPrice(value: string): boolean;
begin

if not InGE then exit;
if not GESellMenu then
if not GEBuyMenu then
exit;

if value = 'min' then value := '0';
if value = 'med' then value := '1';
if value = 'max' then value := '2';

wait(100+Random(50));

case value of
'0': MouseBox(269, 208, 304, 232, 1); // min price
'1': wait(1); // market price
'2': MouseBox(376, 210, 408, 233, 1); // max price
else begin
MouseBox(429, 209, 462, 234, 1);
wait(100+Random(100));
TypeSend(value);
wait(200+Random(100));
if IsChatBoxTextAnyLine('price range', clblack) then
begin
writeln('wrong price! Out of Price Range!');
GEMenuExit;
end;
end;
end;

Result := true;
end;


{*******************************************************************************
Procedure GESetQuantity(Q: string);
By: Rasta Magician
Description: Sets the price of an item.
Options: '1', '10', '100', '1000'(buy), 'all'(sell),
Other - Exact Value
*******************************************************************************}
Procedure GESetQuantity(Q: string);
var i:integer;
begin
if not InGe then exit;
if not GESellMenu then
if not GEBuyMenu then
exit;

case lowercase(Q) of
'1': Mouse(72, 220, 5, 5, true);
'10': Mouse(115, 219, 5, 5, true);
'100': Mouse(155, 220, 5, 5, true);
'all', '1000': Mouse(196, 222, 5, 5, true);
else begin
Mouse(238, 223, 5, 5, true);
for i:= 0 to 3 do
begin
wait(450);
if (GetColor(259, 428) = 8388608) then
if (GetColor(256, 400) = 0) then
break;
end;
TypeSend(Q);
end;
end;
end;


{*******************************************************************************
Function GEConfirmOffer: boolean;
By: Rasta Magician
Description: Confirms an offer
Returns false if it wasn't able to do so
*******************************************************************************}
Function GEConfirmOffer: boolean;
var x, y : integer;
begin
if not InGE then exit;
if not GESellMenu then
if not GEBuyMenu then
exit;

Result := true;

MMouse(215, 284, 96, 21);
wait(250+Random(100));
if IsUpText('ffer') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
wait(1000+Random(200));
end;

if GESellMenu or GEBuyMenu then
begin
writeln('could not confirm offer');
GEMenuExit;
Result := false;
end;

end;


{*******************************************************************************
Function GEBuy(What, Price, Quantity: string): boolean;
By: Rasta Magician
Description: Buys an item from the GE
What (item name) has to be exact
Price: 'min', 'med', 'max', exact value
Quantity: '1', '10', '100', '1000', exact value
*******************************************************************************}
Function GEBuy(What, Price, Quantity: string): boolean;
var
free, x, y:integer;
begin
if not InGE then exit;
if not GEFindFreeSpot(free) then exit;

if GEBuyAt(free) then
begin
wait(50+ Random(50));

if (GetColor(231, 362) <> 23200) then //checking for Item Search
begin
Mouse(125, 117, 7, 7, true);
wait(200+random(50));
end;

TypeSend(lowercase(What));
wait(150+Random(100));

if FindColor(x, y, 23200, 66, 348, 120, 354) then //if it finds our thing
begin
Mouse(x, y, 5, 3, true);
wait(100+Random(100));
end else begin
writeln('Wrong object name');
exit;
end;

wait(100+Random(100));
if not GESetPrice(Price) then exit;
wait(200+Random(100));
GESetQuantity(Quantity);
wait(200+Random(100));
Result := GEConfirmOffer;
end;
end;


{*******************************************************************************
Function GESell(Price, Quantity: string; InvSpot: integer): boolean;
By: Rasta Magician
Description: Sells an item at GE
Price: 'min', 'med', 'max', exact value
Quantity: '1', '10', '100', 'all', exact value
InvSpot: the Invspot where you have your item
*******************************************************************************}
Function GESell(Price, Quantity: string; InvSpot: integer): boolean;
var
free :integer;
begin
if not InGE then exit;
if not GEFindFreeSpot(free) then exit;

if GESellAt(free) then
begin
wait(100+Random(100));
MouseItem(InvSpot, true);
wait(200+Random(100));
GESetPrice(Price);
wait(200+Random(100));
GESetQuantity(Quantity);
wait(200+Random(100));
Result := GEConfirmOffer;
end;
end;


begin
SetupGE;
end.



~RM

Naum

2009-02-18 09:05:15

:). Metagen already did some of this :). Nevertheless good job, Im using another feature in my quester which does some of that. It would be nice if you could get it added to SRL.

The thread: http://www.villavu.com/forum/showthread.php?t=37899 :)

Rep+

hrh

2009-02-18 09:22:36

This could possible help give birth to a GEUpdate detection :o

Sir R. M8gic1an

2009-02-20 01:51:53

wow…. this really got a lot of feedback….

~RM

Colluci

2009-02-20 03:41:25

I like it. Looks sexy. Time to make a merchating script

EvilChicken!

2009-02-20 07:24:01

If any other Devs agree with me, this'll get added to /misc.

Good job, RM.

By the way, take a look at Metagen's functions and see if you can improve your include in any way by looking at his procs and functions.

Naum

2009-02-20 16:39:21

Okay I actually decided to have a look at it,

For instance alot of stuff could be shortened,
GeIsMember:

Function GEIsMember: boolean;
begin
if not InGE then exit;
Result := (GetColor(411, 167) <> 65536) Or (GetColor(410, 155) <> 5199452)
Or (GetColor(411, 167) <> 5199452) Or (GetColor(410, 155) <> 65536);
end;

Is much shorter ;).

NCDS

2009-02-20 16:55:50

I was just thinking of doing this myself the other day :p

Maybe Ill just make the Find/Open functions instead :rolleyes:

Sir R. M8gic1an

2009-02-22 08:58:58

From: NaumanAkhlaQ
Okay I actually decided to have a look at it,

For instance alot of stuff could be shortened,
GeIsMember:

Function GEIsMember: boolean;
begin
if not InGE then exit;
Result := (GetColor(411, 167) <> 65536) Or (GetColor(410, 155) <> 5199452)
Or (GetColor(411, 167) <> 5199452) Or (GetColor(410, 155) <> 65536);
end;

Is much shorter ;).


There you're just checkingif one of the colors return you what you want. this checks for two. You could however remove the second part, which is jsut there to avoid jagex moving 1 px. because if they did then this would try to start clicking on it. if they moved anythign else by one px it jsut wouldn't do anythign which is safe enought. That is why i addedthat failsafe.

~RM

Richard

2009-02-22 14:23:36

I like it, and I think a lot of people's script will benefit from this, so they can add selling/buying of items.

I know my vote doesn't make any difference, but I think this should be added to SRL.

Smarter Child

2009-02-22 14:37:43

:p Nice, this will definetlybe added to SRL, hopefully!:p

tarajunky

2009-02-23 09:07:53

You might have gotten a bit better response if you had posted a test script. :)

I can think of lots of cool functions that people have written that I've never used because I didn't know how, and didn't want to bother figuring it out.

MasterKill

2009-02-23 09:16:47

This looks really nice! And it will be very useful for 99 fletchers and stuff like that :D

<3

Sir R. M8gic1an

2009-02-23 10:18:06

From: tarajunky
You might have gotten a bit better response if you had posted a test script. :)

I can think of lots of cool functions that people have written that I've never used because I didn't know how, and didn't want to bother figuring it out.


heh, thanks for the tip and let me give you a hand with that then :P


{.include srl/srl.scar}
{.include srl/srl/misc/GE.scar}

begin
GEBuy('fire rune', 'min', '1');
GEBuy('fire rune', 'med', '10');
GEBuy('fire rune', 'max', '5');
wait(2000);
GERecoverFinished;
end;

~RM

Tickyy

2009-02-23 13:23:40

Nice stuff RM, this actually gave me the idea of making a SRL merchant script…

it also that could fit into the Free For All category :)

Naike

2009-02-23 16:54:20

Nice work, Should be added.

Sir R. M8gic1an

2009-04-18 19:38:26

I thought this was supposed to be added in #32 ?

~RM

Nava2

2009-04-18 20:00:37

I am going to go through this when I am back at my computer. I think it would be a good addition but I need to also revamp all the bank procedures first. Sorry RM. It probably should have been added.

Nava2

2009-04-22 21:43:37

Added. :)

Thanks RM.

Sir R. M8gic1an

2009-04-22 22:05:47

yay <3 thx

~RM

Nava2

2009-04-22 23:48:22

Closed, its added ;)

EvilChicken!

2009-04-23 00:41:20

Reopened the thread.


I just wanted to tell you that you're a great guy. ^^




.. and closed again.

N2: See I can power abuse too! :)

ZF: So can I.. just for fun!

N2: Hmm, it is fun. :)