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!
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:
I sure hope to see some merchanting scripts soon!
A little run to test: (open ge by yourself)
~RM
//------------------------------------------------------------------------//
//-- 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