PDA

View Full Version : [OSR][REFLECTION] Grand Exchange Include



One Kid
01-01-2016, 11:22 PM
Here's the include I've been working on the past few hours/days.


type
TSlotInterface = record
Bounds:Tbox;
EmptySlot:Integer;
end;
TOfferInterface = record
bounds:Tbox;
end;
TGrandExchange = Record
Offer:TOfferInterface;
Slot:TSlotInterface;
end;

var
GrandExchange:TGrandExchange;

function TGrandExchange.IsUp: Boolean;
var
ParentWidget, ChildWidget: TReflectWidget;

begin
ParentWidget.GetWidget(465, 2);
ChildWidget.GetChild(ParentWidget, 1);

if Pos('grand', LowerCase(ChildWidget.GetText)) then
Result:= true;
ChildWidget.Free;
ParentWidget.Free;
end;
function TOfferInterface.OfferScreen:Boolean;
var
a, b:TReflectWidget;
begin
if a.Exists(465, 2) then
begin
a.GetWidget(465, 2);
b.GetChild(a, 1);
if Pos('offer', LowerCase(b.gettext)) then
Result := True;
end;
a.free;
b.free;
end;

procedure TSlotInterface.ClickBuy(Slot:integer);
var
a, b:TReflectWidget;
begin
A.GetWidget(465, Slot+6);
B.GetChild(A, 0);
Reflect.Mouse.Move(Point(
RandomRange(b.GetBounds.X1, b.GetBounds.X2),
RandomRange(b.GetBounds.y1, b.GetBounds.y2)
), 0, 0);
Reflect.Mouse.Click(mouse_left);
Wait(RandomRange(400,750));
A.free;
B.free;
end;
procedure TSlotInterface.ClickSell(Slot:integer);
var
a, b:TReflectWidget;

begin
A.GetWidget(465, Slot+6);
B.GetChild(A, 1);
Reflect.Mouse.Move(Point(
RandomRange(b.GetBounds.X1, b.GetBounds.X2),
RandomRange(b.GetBounds.y1, b.GetBounds.y2)
), 0, 0);
Reflect.Mouse.Click(mouse_left);
A.free;
B.free;
end;
procedure TOfferInterface.ClickConfirm;
var
a, b:TReflectWidget;
begin
a.GetWidget(465, 24);
b.GetChild(a, 54);
Reflect.Mouse.Move(Point(
RandomRange(b.GetBounds.X1, b.GetBounds.X2),
RandomRange(b.GetBounds.y1, b.GetBounds.y2)
), 0, 0);
Reflect.Mouse.Click(mouse_left);
a.free;
b.free;

end;

procedure TOfferInterface.SetPrice(amount:string);
var
a, b:TReflectWidget;
begin
a.GetWidget(465, 24);
b.GetChild(a, 12);
Reflect.Mouse.Move(Point(
RandomRange(b.GetBounds.X1, b.GetBounds.X2),
RandomRange(b.GetBounds.y1, b.GetBounds.y2)
), 0, 0);
Reflect.Mouse.Click(mouse_left);
Wait(RandomRange(500, 1000));
Reflect.Keyboard.TypeSend(amount, true);

a.free;
b.free;

end;
procedure TOfferInterface.SetQuantity(amount:String);
var
a, b:TReflectWidget;
begin
a.GetWidget(465, 24);
b.GetChild(a, 7);
Reflect.Mouse.Move(Point(
RandomRange(b.GetBounds.X1, b.GetBounds.X2),
RandomRange(b.GetBounds.y1, b.GetBounds.y2)
), 0, 0);
Reflect.Mouse.Click(mouse_left);
Wait(RandomRange(500, 1000));
Reflect.Keyboard.TypeSend(amount, true);
a.free;
b.free;
end;


function TSlotInterface.OfferType(Slot: Integer):String;
var
a, b: TReflectWidget;
begin
a.GetWidget(465, (Slot+6));
b.GetChild(a, 16);
Result := b.GetText;
b.Free;
a.Free;
end;


function TSlotInterface.GetItemFromSlot(Slot:Integer):Strin g;
var
a,b:TReflectWidget;
begin
a.GetWidget(465, Slot+6);
b.GetChild(a, 19);
Result:= b.GetText;
a.free;
b.free;
end;

function TOfferInterface.ItemPrice:Integer; //Returns the price of the item
var
a, b:TReflectWidget;
begin
a.GetWidget(465, 15);
b.GetChild(a, 25);
Result := StrToInt(replace(b.GetText, ',', '', [rfReplaceAll]));
a.free;
b.free;

end;

function TOfferInterface.AmountSold:String //Returns the total amount sold so far.
var
a, b:TReflectWidget;
c, d:String;
begin
a.GetWidget(465, 22);
b.GetChild(a, 1);
c := Between('sold', 'for', b.GetText);
d := Between('>', '<', c);
d := replace(d, ',', '', [rfReplaceAll]);
Result := d;
a.free;
b.free;

end;
function TOfferInterface.AmountBought:Integer;//Returns the total amount bought so far.
var
a, b:TReflectWidget;
c, d:String;
begin
a.GetWidget(465, 22);
b.Getchild(a, 1);
c:= Between('bought', 'price', b.GetText);
d:= Between('>','<', c);
Result := StrToInt(replace(d, ',', '', [rfReplaceAll]));
a.free;
b.free;
end;

function TOfferInterface.OfferItem:String; //Returns the item being being bought or sold in the offer screen.
var
a, b:TReflectWidget;
begin
a.GetWidget(465, 24);
b.GetChild(a, 25);
Result:= b.GetText;
a.free;
b.free;
end;

function TGrandExchange.Collect:Boolean;//Clicks the collect button on the GEInterface
var //NOT the collect boxes in the offer screen.
a,b:TReflectWidget;
begin
a.GetWidget(465, 6);
b.GetChild(a, 1);
if Pos('collect', Lowercase(b.GetText)) then
begin
Result:= true;
Reflect.Mouse.Move(Point(
RandomRange(b.GetBounds.X1, b.GetBounds.X2),
RandomRange(b.GetBounds.y1, b.GetBounds.y2)
), 0, 0);
Reflect.Mouse.Click(mouse_left);
end;
a.free;
b.free;

end;



function TOfferInterface.TotalPrice:String; //Returns the total that the items sold/bought for so far.
var
a, b:TReflectWidget;
c, d:String;
begin
a.GetWidget(465, 22);
b.Getchild(a, 1);
c:= Between('price', 'coins', b.GetText);
d:= Between('>','<', c);
Result := replace(d, ',', '', [rfReplaceAll]);
a.free;
b.free;
end;
function TSlotInterface.ClickEmptySlot(buy, sell:Boolean):Boolean;
var
a,b:TReflectWidget;
i:Integer;
begin
if a.Exists(465, i) then
for i:= 7 to 14 do
begin
a.GetWidget(465, i);
b.GetChild(a, 16);
if Pos('Empty', b.GetText) then
begin
if buy then
begin
TSlotInterface.ClickBuy(i-6);
Result:= True;
a.free;
b.free;
Exit;
end;
if sell then
begin
TSlotInterface.ClickSell(i-6);
Result:= True;
a.free;
b.free;
Exit;
end;
end
else
Continue;
end
end;

function TSlotInterface.FindEmpty:Integer;
var
a,b:TReflectWidget;
i:Integer;
begin
if a.Exists(465, i) then
for i:= 7 to 14 do
begin
a.GetWidget(465, i);
b.GetChild(a, 16);
if Pos('Empty', b.GetText) then
Result := i;
end
end;

function TGrandExchange.AbortSlot(Slot:integer):Boolean;
var
a, b:TReflectWidget;
begin
A.GetWidget(465, Slot+6);
B.GetChild(A, 2);
Reflect.Mouse.Move(Point(
RandomRange(b.GetBounds.X1, b.GetBounds.X2),
RandomRange(b.GetBounds.y1, b.GetBounds.y2)
), 0, 0);
Reflect.Mouse.Click(mouse_right);
Wait(RandomRange(254,653));
Result := Reflect.Text.ChooseOption('Abort offer');
Wait(RandomRange(340, 400));
self.Collect;
a.free;
b.free;
end;

procedure TOfferInterface.ClickChooseItem;
var
a,b:TReflectWidget;
p:TPoint;
begin
a.GetWidget(465, 24);
b.GetChild(a, 0);
p.x := RandomRange(b.GetBounds.X1, b.GetBounds.X2);
p.y := RandomRange(b.GetBounds.Y1, b.GetBounds.Y2);
Reflect.Mouse.Move(p, 0, 0);
Reflect.Mouse.Click(mouse_left);
a.free;
b.free;
end;

function TOfferInterface.IsSearch:Boolean;
var
a, b:TReflectWidget;
begin
a.GetWidget(162,38);
Result := a.HasChild;
end;

procedure TOfferInterface.Search(item:string);
var
a,b:TReflectWidget;
i:Integer;
t:TReflectTimer;
pt:TPoint;
begin
if not self.OfferScreen then
exit;
if not self.isSearch then
self.ClickChooseItem;
Wait(RandomRange(250, 650));
Reflect.KeyBoard.TypeSend(item);
Wait(RandomRange(250, 650));
a.GetWidget(162,38);
b.GetChild(a, 1);
pt.x := RandomRange(b.GetBounds.X1, b.GetBounds.X2);
pt.y := RandomRange(b.GetBounds.Y1, b.GetBounds.Y2);
Reflect.Mouse.Move(pt, 0, 0);
Reflect.Mouse.Click(mouse_left);
a.free;
b.free;
end;

function TOfferInterface.GetQuantity:Integer;
var
a,b:TReflectWidget;
s1,s2:String;
i:String;
begin
a.GetWidget(465, 15);
b.GetChild(a, 18);
s1 := replace(b.getText, ',','', [rfReplaceAll]);
Result := StrToInt(Trim(replace(b.getText, ',','', [rfReplaceAll])));
a.free;
b.free;
end;

function TOfferInterface.CompleteBuy:Boolean;
begin
Result := (self.GetQuantity = self.AmountBought);
end;
function TOfferInterface.CompleteSold:Boolean;
begin
Result := (StrToInt(self.AmountSold) = self.GetQuantity);
end;

function TofferInterface.OfferType:String;
var
a, b:TReflectWidget;
begin
a.GetWidget(465, 15);
b.GetChild(a, 4);
Result := b.getText;
a.free;
b.free;
end;
function TOfferInterface.Complete:Boolean;
begin
if (self.OfferType = 'Buy offer') then
Result := self.CompleteBuy;
if (self.offertype = 'Sell offer') then
Result := self.CompleteSold;
end;

Place this in your Includes inside of a folder called GrandExchange.

From there you can use it like this in a script.
http://imgur.com/7UztWP1.png
http://imgur.com/VPknxEw.png
http://imgur.com/9KQlzsz.png


If you have any questions then please feel free to ask!


LIST OF PROCEDURES/FUNCTIONS



function GrandExchange.IsUp: Boolean; //Tells us whether the Grand Exchange interface is up.

function GrandExchange.Offer.OfferScreen:Boolean; //Tells us if we are at the offer screen.

procedure GrandExchange.Slot.ClickBuy(Slot:integer); //Clicks buy on the corresponding slot.

procedure GrandExchange.Slot.ClickSell(Slot:integer); //Clicks sell on the corresponding slot.

procedure GrandExchange.Offer.ClickConfirm; //Clicks confirm.

procedure GrandExchange.Offer.SetPrice(amount:string); //Sets the price of the offer.

procedure GrandExchange.Offer.SetQuantity(amount:String); //Sets the quantity for the offer.

function GrandExchange.Slot.OfferType(Slot: Integer):String; //Returns a string of the slot type. It is either 'Buy offer','Sell offer', or 'Empty'.

function GrandExchange.Slot.GetItemFromSlot(Slot:Integer):S tring; //Returns the item in the corresponding slot.

function GrandExchange.Offer.ItemPrice:Integer; //Returns the price of the item

function GrandExchange.Offer.AmountSold:String //Returns the total amount sold so far.

function GrandExchange.Offer.AmountBought:Integer;//Returns the total amount bought so far.

function GrandExchange.Offer.OfferItem:String; //Returns the item being being bought or sold in the offer screen.

function GrandExchange.Collect:Boolean; //Clicks the collect button on the Grand Exchange Interface

function GrandExchange.Offer.TotalPrice:String; //Returns the total that the items sold/bought for so far.

function GrandExchange.Slot.ClickEmptySlot(buy, sell:Boolean):Boolean; //Very simple clicks buy OR sell on an empty slot. Make sure if one is set to true the other is set to false.

function GrandExchange.Slot.FindEmpty:Integer; //Returns the slot number of an empty slot.

function GrandExchange.AbortSlot(Slot:integer):Boolean; //Aborts the slot and then collects the items.

procedure GrandExchange.Offer.ClickChooseItem; //Clicks the Choose item box in the Offer screen, used in another function to check if we are searching for an item.

function GrandExchange.Offer.IsSearch:Boolean; //Returns if we are able to search, sometimes the search in the chat doesnt come up. Failsafe.

procedure GrandExchange.Offer.Search(item:string);//Searchs for an item and then clicks the item in the chat.

function GrandExchange.Offer.GetQuantity:Integer; //Returns the quantity being bought, NOT The quantity that sold.

function GrandExchange.Offer.OfferType:String; //Returns the offer type of the offer.

function GrandExchange.Offer.Complete:Boolean; //Returns true if the offer has completed.


Get the Attachment here:27077

Joopi
01-01-2016, 11:30 PM
Damn that is impressive. Keep up the good work!

yourule97
01-01-2016, 11:32 PM
It's great to see you following up! Best of luck, it's looking great!

One Kid
01-01-2016, 11:39 PM
It's great to see you following up! Best of luck, it's looking great!


Damn that is impressive. Keep up the good work!

Thanks guys.

There are still some minor tweaks coming in, but the functionality is there.

AFools
01-02-2016, 12:12 AM
I am impressed; Your two steps ahead of me. =D

I have been up all night; i will try squeeze a nap in and see what i can make of this! very promising.

Rep+

One Kid
01-02-2016, 01:09 AM
I am impressed; Your two steps ahead of me. =D

I have been up all night; i will try squeeze a nap in and see what i can make of this! very promising.

Rep+

Thank you! Let me know if you need any help.

Laquisha
01-02-2016, 08:56 AM
Nice work. I guess you now need buy and sell ;)

AFools
01-02-2016, 09:33 AM
Nice work. I guess you now need buy and sell ;)

?????



procedure GrandExchange.Slot.ClickBuy(Slot:integer); //Clicks buy on the corresponding slot.

procedure GrandExchange.Slot.ClickSell(Slot:integer); //Clicks sell on the corresponding slot.

I have yet to test the functionality of these.

One Kid
01-02-2016, 04:16 PM
No you do not need buy and sell. That functionality is to be made by the scripter. Because price and other things like quantity need to be set and only the scripter will know what exactly they are trying to do.


Example of how to buy.


GrandExchange.Slot.ClickBuy(5);
GrandExchange.Offer.Search('Law Rune');
GrandExchange.Offer.ClickConfirm;
Wait(250);
GrandExchange.Collect;

Laquisha
01-03-2016, 07:41 AM
?????



procedure GrandExchange.Slot.ClickBuy(Slot:integer); //Clicks buy on the corresponding slot.

procedure GrandExchange.Slot.ClickSell(Slot:integer); //Clicks sell on the corresponding slot.

I have yet to test the functionality of these.


No you do not need buy and sell. That functionality is to be made by the scripter. Because price and other things like quantity need to be set and only the scripter will know what exactly they are trying to do.


Example of how to buy.


GrandExchange.Slot.ClickBuy(5);
GrandExchange.Offer.Search('Law Rune');
GrandExchange.Offer.ClickConfirm;
Wait(250);
GrandExchange.Collect;


Oh, I guess you could do it like that. I was thinking like GrandExchange.Buy('Law Rune', 300, 10000); to turn those 5 lines into 1 (like the srl one).

AFools
01-03-2016, 07:51 AM
Oh, I guess you could do it like that. I was thinking like GrandExchange.Buy('Law Rune', 300, 10000); to turn those 5 lines into 1 (like the srl one).

I don't want to take any credit from 'One Kid' because this is primarily his project; but behind the scene we are now working together on the overall "run-loop" in regards to functionality of the widgets he has made.

So far the script places buy/sell order - with the desired quantity; I have just woken up and will see if i can get this completely functioning by the end of the day.

Then comes consolidating the widgets into a 'concise-usable function'

One Kid
01-03-2016, 04:08 PM
Oh, I guess you could do it like that. I was thinking like GrandExchange.Buy('Law Rune', 300, 10000); to turn those 5 lines into 1 (like the srl one).

Well then, I suppose I will put out an update that does just that. I'll make it a function that returns true if the offer is placed, or false if it isn't. For both sell or buy.

Vizual
01-19-2016, 01:30 AM
Looks amazing.

One Kid
01-21-2016, 12:42 AM
Looks amazing.

Thank you! Glad you like it.

Laquisha
01-21-2016, 06:57 AM
Thank you! Glad you like it.

He doesn't actually like it. He probably couldn't care less. He was just spamming to get a post count of 10 so he could PM :p

One Kid
01-23-2016, 01:18 AM
He doesn't actually like it. He probably couldn't care less. He was just spamming to get a post count of 10 so he could PM :p

Doh! lol that makes sense. I'd like to think he does :P

k9thebeast
02-04-2016, 06:15 AM
Looks awesome. I think reflection widgets are outdated at the moment so that would be the only hickup :/ It seems as though the hooks for the objects are updated much more often than the widgets.

Mj
02-11-2016, 05:18 AM
Looks awesome. I think reflection widgets are outdated at the moment so that would be the only hickup :/ It seems as though the hooks for the objects are updated much more often than the widgets.

I was just in the middle of making this for one of my scripts... I didn't even notice this existed, awesome work man.

One Kid
02-11-2016, 05:39 AM
I was just in the middle of making this for one of my scripts... I didn't even notice this existed, awesome work man.

Thanks. I haven't really messed with it in awhile. If you have any questions feel free to message me.

maikelpro99
02-12-2016, 08:08 AM
I read all and i think these codes will buy items on g.e at middle price. Will you give us any option to buy any item for %5 more of normal price? Thanks.

One Kid
02-12-2016, 05:19 PM
I read all and i think these codes will buy items on g.e at middle price. Will you give us any option to buy any item for %5 more of normal price? Thanks.


When You've already searched for your item do this.



GrandExchange.Offer.SetPrice(IntToStr(Round(GrandE xchange.Offer.ItemPrice*1.05)));

rj
02-18-2016, 05:56 AM
TOfferInterface = record
bounds:Tbox;
end;

Might aswell not be a record, or could be changed to

TOfferInterface = TBox;

for organization purposes I guess