SRL Archive - Test corner

Grand Exchange Stuff.


Rikje

2007-11-27 16:28:31

Cause of the new grand exchange i made this:



program GrandExchange;
{.include srl/srl.scar}
var
Log: Integer;


Function FindExchangeScreen: Boolean;
var
Tx, Ty: integer;
begin
Result := IsTextInAreaEx(190, 30, 328, 52, Tx, Ty, 'Grand Exchange', 10, UpChars,
True, False, 0, 0, 39116);
end;

Function OpenExchange: Boolean;
var
Cx, Cy: Integer;
begin
Result := FindObjCustom(Cx, Cy, ['Desk', 'Use Desk'], [6850714], 10);
if Result then
begin
Mouse(Cx, Cy, 2, 2, False);
ChooseOption('Exchange ');
Flag;
Wait(2000);
if FindExchangeScreen then
begin
Result := True;
Exit;
end;
end;
Result := False;
end;

procedure CloseExchenge;
var
C: Integer;
begin
if FindExchangeScreen then
repeat;
Inc(c);
Mouse(485, 42, 3, 3, True);
Wait(1000);
until((C >= 2) or (Not(FindExchangeScreen)));
end;

Function LookForOpenSlot(var Tx, Ty, Slot: Integer): Boolean;
var
SlotCoords: Array [0..5] Of TPoint;
I: Integer;
begin
SlotCoords[0].x := 79; SlotCoords[4].x := 237;
SlotCoords[0].y := 86; SlotCoords[4].y := 206;
SlotCoords[1].x := 238; SlotCoords[5].x := 395;
SlotCoords[1].y := 86; SlotCoords[5].y := 206;
SlotCoords[2].x := 394; Slot := 0;
SlotCoords[2].y := 86;
SlotCoords[3].x := 82;
SlotCoords[3].y := 206;

MMouse(530, 219, 10, 30);
For I := 0 to 5 do
begin
Result := IsTextInAreaEx(SlotCoords[i].x, SlotCoords[i].y, SlotCoords[i].x + 55,
SlotCoords[i].y + 25, Tx, Ty, 'Empty', 20, UpChars, True, False, 0, 0, 39372);
if Result then
begin
Slot := i + 1;
Exit;
end;
end;
end;

Function ExchangeSellItem(ItemBitmap: Integer; SellAmount: string;
LowestPrize: Boolean; ItemTol: Integer): Boolean;
var
Tx, Ty, Slot: Integer;
begin
if OpenExchange then
begin
if LookForOpenSlot(Tx, Ty, Slot) then
begin
WriteLn('Free Slot: ' + IntToStr(Slot));
Mouse(Tx + 10, Ty, 20, 30, True);
Wait(1000 + Random(500));
Mouse(Tx + 35, Ty + 50, 20, 10, True);
Wait(2000 + Random(500));
if (not(TabExists(4))) then
begin
if FindBitmapToleranceIn(ItemBitmap, Tx, Ty, MIX1, MIY1, MIX2, MIY2, ItemTol) then
begin
Mouse(Tx, Ty, 2, 2, True);
Wait(2000 + Random(500));
if FindDeformed(Tx, Ty, ItemBitmap, 104, 94, 147, 134) then
begin
Mouse(237, 223, 3, 3, True);
if (not(FindExchangeScreen)) then Exit;
Wait(2000 + Random(500));
TypeSend(SellAmount);
Wait(2000 + Random(500));
if LowestPrize then
Mouse(286, 222, 3, 3, True)
else Mouse(339, 223, 3, 3, True);
Mouse(216, 285, 100, 10, True);
Wait(2000 + Random(500))
Result := True;
end;
end;
end;
end;
end;
CloseExchenge;
end;

procedure Load; //current bitmap is from a noted willow log.
begin
Log := BitmapFromString(9, 4, 'beNrzkY8MUERGsSFKoT7ygZ6yP' +
'q4yQDYcQUQ8HKScbSTszMWAKoEiQAaQCxQEIqAsUASIIFyICEQQaC' +
'AIAQCcZhmX');
end;

begin
SetUpSRl;
Load;
if ExchangeSellItem(Log, '50', True, 20) then
WriteLn(' Sucsefully Exchanged.');
CloseExchenge;
FreeBitmap(Log);
end.

ExchangeSellItem will sell a item to that thing, by using a bitmap of the item. it can easy be changed to a dtm or something else. :)

n3ss3s

2007-11-28 08:33:01

Nice…. O.o - a script that cuts yews and puts for sale? xD

Wanted

2007-11-28 20:41:57

Pretty nice, a couple of tips though,

Function is a key word and show remain lower case as with any bolded word, it's just bad practice ;)

var
Tx, Ty: integer;

wouldn't it just be easier to use

T: TPoint; //Hint: X use as T.X, Y use as T.Y (same with Cx)

This:

 begin
Mouse(Cx, Cy, 2, 2, False);
ChooseOption('Exchange ');
Flag;
Wait(2000);

maybe change the Flag and add some other waits

 begin
Mouse(C.X, C.Y, 2, 2, False);
Wait(500 + Random(50));
ChooseOption('xchang');
FFlag(0);
Wait(2000);

These:

  SlotCoords[0].x := 79;        SlotCoords[4].x := 237;
SlotCoords[0].y := 86; SlotCoords[4].y := 206;
SlotCoords[1].x := 238; SlotCoords[5].x := 395;
SlotCoords[1].y := 86; SlotCoords[5].y := 206;
SlotCoords[2].x := 394; Slot := 0;
SlotCoords[2].y := 86;
SlotCoords[3].x := 82;
SlotCoords[3].y := 206;

could be made into

SlotCoords := [Point(79, 86), Point(238, 86), Point...];

then you wouldn't need to set an array length or take up as much space :)

I: Integer;

maybe reduce to

I: Byte;

Looks pretty good for the most part, just work on mastering good standards and making your code efficient as possible :)

Rikje

2007-11-29 02:10:27

Ty :)


SlotCoords := [Point(79, 86), Point(238, 86), Point...];
Never heard of that function :p
ill try to use it in the future.

Santa_Clause

2007-11-29 04:57:35

Good job Rikjess!

I've never heard of anything like that either…:eek:

What's the highest value of a Byte?

P.S - 2.6K posts…Woot!

n3ss3s

2007-11-29 11:53:50

Umm isn't it IntToPoint(IntX, IntY)?

Anyways, I guess there is a Point too…

WTH, when you right click a bank booth you can choose a grand exchange thing too…

Killerdou

2007-11-29 12:02:49

its to collect money/items from the grand exchange trades…

Wizzup?

2007-11-29 12:56:08

From: IceFire908
Function is a key word and show remain lower case as with any bolded word, it's just bad practice ;)


Wrong.
http://www.delphibasics.co.uk/RTL.asp?Name=Function

Function GetSum(a, b : Integer) : Integer;
begin
// Add the two numbers together, and return this value
Result := a + b;
end;

1 	  Function Name : Return type; {Directives;}
2 Function Name(Parameters) : Return type; {Directives;}
3 type Name = Function{(Parameters)} : Return type {of object};

n3ss3s

2007-11-29 13:31:11

Iccy got pwnt by wizzy :)

Capped bold words FTW!!

-Torchering IceFire
 Function Begin End Type Record Label String Var 
>:)

Rikje

2007-11-29 13:37:04

Wizzy you said nothing about my code. i think that explains enough :rolleyes: j/k

From: Santa_Clause
What's the highest value of a Byte?!


Iam wondering the same :p

nielsie95

2007-11-30 01:48:07

8 bit.

0..255

ZephyrsFury

2007-11-30 02:44:59

From: Wizzup?
Wrong.
http://www.delphibasics.co.uk/RTL.asp?Name=Function

Function GetSum(a, b : Integer) : Integer;
begin
// Add the two numbers together, and return this value
Result := a + b;
end;

1 	  Function Name : Return type; {Directives;}
2 Function Name(Parameters) : Return type; {Directives;}
3 type Name = Function{(Parameters)} : Return type {of object};


Ahem Ahem… :rolleyes:

From: SRL Wiki

Object Pascal language reserved words and key words shall always be completely lowercase. Never capitalize words that SCAR displays in bold. It's completely unnecessary and looks ugly!


http://www.wiki.srl-forums.com/index.php/Scripting_Standards

Wizzup?

2007-11-30 04:00:12

I don't know who wrote that, but it clashes with the 'standard' coding standards…

ZephyrsFury

2007-11-30 05:35:39

If you're gonna change it you have to change all the examples as well… :rolleyes:

nielsie95

2007-11-30 09:23:52

SCAR standards differ from Delphi/Pascal..
Check out the SCAR manual, you'll find lowercase functions/examples.

Wanted

2007-11-30 22:34:35

From: Santa_Clause
Good job Rikjess!

I've never heard of anything like that either…:eek:

What's the highest value of a Byte?

P.S - 2.6K posts…Woot!


Byte is 0..255

here is a full list

 Type  Storage size                        Range            

Byte 1 0 to 255
ShortInt 1 -127 to 127
Word 2 0 to 65,535
SmallInt 2 -32,768 to 32,767
LongWord 4 0 to 4,294,967,295
Cardinal 4* 0 to 4,294,967,295
LongInt 4 -2,147,483,648 to 2,147,483,647
Integer 4* -2,147,483,648 to 2,147,483,647
Int64 8 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Single 4 7 significant digits, exponent -38 to +38
Currency 8 50+ significant digits, fixed 4 decimal places
Double 8 15 significant digits, exponent -308 to +308
Extended 10 19 significant digits, exponent -4932 to +4932

* Note : the Integer and Cardinal types are both 4 bytes in size at present (Delphi release 7), but are not guaranteed to be this size in the future. All other type sizes are guaranteed.

From: n3ss3s
Umm isn't it IntToPoint(IntX, IntY)?


Yes, Point is just less characters to type, IntToPoint works too.

R0b0t1

2007-12-01 13:32:22

IntToPoint is a copy of a Delphi function :)


Surprised Delphi doesn't have "unsigned"…