SRL Archive - SRL Suggestions

In game price checking functions


Bionicle

2010-04-02 19:30:20

{*******************************************************************************
function PriceScreenOpen: Boolean;
By: Bionicle1800
Description: Checks to see if the price checking screen is open.
*******************************************************************************}
function PriceScreenOpen: Boolean;
begin
Result := FindTextTPA(2070783, 5, 214, 28, 307, 41, 'rice', UpChars, nothing);
end;

{*******************************************************************************
function OpenPriceScreen: Boolean;
By: Bionicle1800
Description: Opens the price checking screen and returns a boolean.
*******************************************************************************}
function OpenPriceScreen: Boolean;
var
X, Y: Integer;
begin
if not PriceScreenOpen then
begin
GameTab(Tab_Equip);
MMouse(RandomRange(625, 660), RandomRange(415, 450), 0, 0);
Wait(300+Random(200));
end;

if GetColor(630, 425) = 2634812 then
begin
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, true);
Wait(1000+Random(500));
end;
Result := PriceScreenOpen;
end;

{*******************************************************************************
function PriceCheckOne(InvSlot: Integer; Stacked: Boolean; MoneyType: String): Integer;
By: Bionicle1800
Description: Checks the price of one item in the inventory specified by the integer
InvSlot. If stacked is true, then it will check all the items that
are stacked. Valid arguments for MoneyType are 'gp'; returns the amount
in normal gp form, 'k'; returns the amount in thousands, 'm'; returns
the amount in millions, 'b'; returns the amount in billions. Any other
will return in the normal gp form.
*******************************************************************************}
function PriceCheckOne(InvSlot: Integer; Stacked: Boolean; MoneyType: String): Integer;
var
X, Y, RD: Integer;
TB: TBox;
begin

if not InRange(InvSlot, 1, 28) then
begin
srl_Warn('PriceCheckOne', 'Inventory slot ' + IntToStr(InvSlot)
+ ' is not valid.', Warn_AllVersions);
exit;
end;

case Lowercase(MoneyType) of
('gp'): RD := 1;
('k'): RD := 1000;
('m'): RD := 1000000;
('b'): RD := 1000000000;
else
RD := 1;
end;

if not OpenPriceScreen then
begin
Writeln('Error opening the price checking screen.');
exit;
end;

TB := InvBox(InvSlot);
if Stacked then
begin
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, 2);
WaitOption('ll', 500);
end else
begin
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, 1);
Wait(300+Random(500));
end;
Wait(1000+Random(500));

Result := StrToInt(Replace(GetTextAtEx(50, 310, 3, StatChars, false, false, 0,
2, 16777215, 30, true, tr_Digits), ' ', '')) / RD;
end;

{*******************************************************************************
function PriceCheckAll(Stacked: Boolean; MoneyType: String): Integer;
By: Bionicle1800
Description: Checks the price of all items in the inventory. If stacked is true,
then it will check all the items that are stacked. Valid arguments
for MoneyType are 'gp'; returns the amount in normal gp form, 'k';
returns the amount in thousands, 'm'; returns the amount in millions,
'b'; returns the amount in billions. Any other will return in the
normal gp form.
*******************************************************************************}
function PriceCheckAll(Stacked: Boolean; MoneyType: String): Integer;
var
X, Y, I, RD: Integer;
TB: TBox;
begin
case Lowercase(MoneyType) of
('gp'): RD := 1;
('k'): RD := 1000;
('m'): RD := 1000000;
('b'): RD := 1000000000;
else
RD := 1;
end;

if not OpenPriceScreen then
begin
Writeln('Error opening the price checking screen.');
exit;
end;

for I := 1 to 28 do
begin
TB := InvBox(I);
if FindColor(X, Y, srl_outline_black, TB.X1, TB.Y1, TB.X2, TB.Y2) then
begin
if Stacked then
begin
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, 2);
WaitOption('ll', 500);
end else
begin
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, 1);
Wait(300+Random(500));
end;
Wait(1000+Random(500));
end;
end;

Result := StrToInt(Replace(GetTextAtEx(50, 310, 3, StatChars, false, false, 0,
2, 16777215, 30, true, tr_Digits), ' ', '')) / RD;
end;

Dgby714

2010-04-02 20:09:44

Fixed Standards =)

{*******************************************************************************
function PriceScreenOpen: boolean;
By: Bionicle1800
Description: Checks to see if the price checking screen is open.
*******************************************************************************}
function PriceScreenOpen: boolean;
begin
Result := FindTextTPA(2070783, 5, 214, 28, 307, 41, 'rice', UpChars, nothing);
end;

{*******************************************************************************
function OpenPriceScreen: boolean;
By: Bionicle1800
Description: Opens the price checking screen and returns a boolean.
*******************************************************************************}
function OpenPriceScreen: boolean;
var
X, Y: integer;
begin
GameTab(Tab_Equip);
MMouse(RandomRange(625, 660), RandomRange(415, 450), 0, 0);
Wait(300 + Random(200));

if (GetColor(630, 425) = 2634812) then
begin
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, true);
Wait(1000 + Random(500));
Result := True;
end;
end;

{*******************************************************************************
function PriceCheckOne(InvSlot: integer; Stacked: boolean; MoneyType: string): integer;
By: Bionicle1800
Description: Checks the price of one item in the inventory specified by the integer
InvSlot. If stacked is true, then it will check all the items that
are stacked. Valid arguments for MoneyType are 'gp'; returns the amount
in normal gp form, 'k'; returns the amount in thousands, 'm'; returns
the amount in millions, 'b'; returns the amount in billions. Any other
will return in the normal gp form.
*******************************************************************************}
function PriceCheckOne(InvSlot: integer; stacked: boolean; MoneyType: string): integer;
var
X, Y, RD: integer;
TB: TBox;
begin
if (not (InRange(InvSlot, 1, 28))) then
begin
srl_Warn('PriceCheckOne', 'Inventory slot ' + IntToStr(InvSlot)
+ ' is not valid.', Warn_AllVersions);
Exit;
end;

case MoneyType of
Lowercase('gp'): RD := 1;
Lowercase('k'): RD := 1000;
Lowercase('m'): RD := 1000000;
Lowercase('b'): RD := 1000000000;
else
RD := 1;
end;

if (not (OpenPriceScreen)) then
begin
Writeln('Error opening the price checking screen.');
Exit;
end;

TB := InvBox(InvSlot);
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, Integer(Stacked) + 1);
WaitOption('ll', 500);
Wait(1000 + Random(500));

Result := StrToInt(Replace(GetTextAtEx(50, 310, 3, StatChars, false, false, 0,
2, 16777215, 30, true, tr_Digits), ' ', '')) / RD;
end;

{*******************************************************************************
function PriceCheckAll(Stacked: boolean; MoneyType: string): integer;
By: Bionicle1800
Description: Checks the price of all items in the inventory. If stacked is true,
then it will check all the items that are stacked. Valid arguments
for MoneyType are 'gp'; returns the amount in normal gp form, 'k';
returns the amount in thousands, 'm'; returns the amount in millions,
'b'; returns the amount in billions. Any other will return in the
normal gp form.
*******************************************************************************}
function PriceCheckAll(Stacked: boolean; MoneyType: string): integer;
var
X, Y, I, RD: integer;
TB: TBox;
begin
case MoneyType of
Lowercase('gp'): RD := 1;
Lowercase('k'): RD := 1000;
Lowercase('m'): RD := 1000000;
Lowercase('b'): RD := 1000000000;
else
RD := 1;
end;

if (not (OpenPriceScreen)) then
begin
Writeln('Error opening the price checking screen.');
Exit;
end;

for I := 1 to 28 do
begin
TB := InvBox(I);
if FindColor(X, Y, srl_outline_black, TB.X1, TB.Y1, TB.X2, TB.Y2) then
begin
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, Integer(Stacked) + 1);
WaitOption('ll', 500);
Wait(1000 + Random(500));
end;
end;

Result := StrToInt(Replace(GetTextAtEx(50, 310, 3, StatChars, false, false, 0,
2, 16777215, 30, true, tr_Digits), ' ', '')) / RD;
end;

Bionicle

2010-04-02 20:12:15

From: Dgby714
Fixed Standards =)


Capitalized bold words ftw :(

Frement

2010-04-02 20:14:26

I actually did this also. Just a sec ill find the thread.

http://villavu.com/forum/showthread.php?t=55235

Naum

2010-04-03 09:27:09

Had a quick glance over it, one thing that struck me:

      If Stacked Then
Begin
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, 2);
WaitOption('ll', 500);
End Else
Begin
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, 1);
Wait(300+Random(500));
End;
Wait(1000+Random(500));

To:


MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, Integer(Stacked) + 1);
WaitOption('ll', 500);
Wait(1000+Random(500));

Bionicle

2010-04-03 10:45:58

Thanks naum, fixed and added PriceScreenOpen :)

Nava2

2010-04-03 12:52:41

Capitalized bold words == bad.

Bionicle

2010-04-03 13:31:01

From: Nava2
Capitalized bold words == bad.


fineeeeeeeeee changed :p

Dgby714

2010-04-03 13:32:56

From: bionicle1800
fineeeeeeeeee changed :p


=) Love It

Wizzup?

2010-04-03 16:48:12

From: Nava2
Capitalized bold words == bad.


No; it is a preference that not everyone shares.

Wizzup?

2010-04-03 16:53:45

From: Naum
Had a quick glance over it, one thing that struck me:

      If Stacked Then
Begin
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, 2);
WaitOption('ll', 500);
End Else
Begin
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, 1);
Wait(300+Random(500));
End;
Wait(1000+Random(500));

To:


MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2, Integer(Stacked) + 1);
WaitOption('ll', 500);
Wait(1000+Random(500));

That code isn't very portable; though. I doubt it will work on other platforms nor on a different interpreter. Not to mention his code is more readable.

Bionicle

2010-04-03 18:04:11

From: Wizzup?
That code isn't very portable; though. I doubt it will work on other platforms nor on a different interpreter. Not to mention his code is more readable.


Changed it back.
I kept the bold letters in lowercase, because it is (I'd bet) the preference of the community, which is probably better.
Thanks :)

Awkwardsaw

2010-04-03 18:27:32

function OpenPriceScreen: Boolean;
var
X, Y: Integer;
begin
if not PriceScreenOpen then
begin
GameTab(Tab_Equip);
MMouse(RandomRange(625, 660), RandomRange(415, 450), 0, 0);
Wait(300+Random(200));
end;

if GetColor(630, 425) = 2634812 then
begin
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, true);
Wait(1000+Random(500));
Result := True;
end;
end;

to

function OpenPriceScreen: Boolean;
var
X, Y, C: Integer;
begin
for c := 0 to 2 do
begin
if not PriceScreenOpen then
begin
GameTab(Tab_Equip);
MMouse(RandomRange(625, 660), RandomRange(415, 450), 0, 0);
Wait(300+Random(200));
end;

if GetColor(630, 425) = 2634812 then
begin
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, true);
Wait(1000+Random(500));
Result := PriceScreenOpen;
break;
end;
end;
end;

just an extra failsafe :)

Gu3st...

2010-04-03 18:34:59

From: Awkwardsaw
...

to

...

just an extra failsafe :)
Why? Would look a bit in-human imo

Blumblebee

2010-04-03 18:36:09

From: Zyt3x
Why? Would look a bit in-human imo


lol wut? He makes it look to check twice incase it doesn't work.

I personally don't think loop through is needed, but I guess it could be useful.

Edit: read below. I get it now, sorry Zyt3x :(

Bionicle

2010-04-03 18:38:44

Yea, i don't see the point to that awkward, what it does is moves the mouse to random x,y coords in the price checking button, then the getcolor is the color of the hover color of the button. if it doesn't find it the first time, it will move the mouse within the button and then click on it if it finds the color? If it doesn't find the color the first time, it wouldn't the second time, there is a long enough wait.

Awkwardsaw

2010-04-03 19:12:39

ok, but the result := PriceScreenOpen; is still usefull, :)

Bionicle

2010-04-03 19:14:11

From: Awkwardsaw
ok, but the result := PriceScreenOpen; is still usefull, :)


Yea, i agree, i didnt think about that when i added the PriceScreenOpen function, thanks :p

Gu3st...

2010-04-03 19:26:15

case MoneyType of
Lowercase('gp'): RD := 1;
Lowercase('k'): RD := 1000;
Lowercase('m'): RD := 1000000;
Lowercase('b'): RD := 1000000000;
else
RD := 1;
end;
Didn't you mean
  case LowerCase(MoneyType) of
'gp': RD := 1;
'k': RD := 1000;
'm': RD := 1000000;
'b': RD := 1000000000;
else
RD := 1;
end;

Bionicle

2010-04-03 19:38:34

LOL yea thanks
what was i thinking :p

Gu3st...

2010-04-03 19:45:31

Also:
Result := StrToInt(Replace(GetTextAtEx(50, 310, 3, StatChars, false, false, 0,
2, 16777215, 30, true, tr_Digits), ' ', '')) / RD;
Why "… / RD"?
Wouldn't 151,830 result in 152? Shouldn't you multiply instead? (And you would probably add Round() around that statement; Result := Round(StrToInt(….) * RD);

EDIT: Wait, what?! I am tired.. sorry xP

Bionicle

2010-04-03 19:49:16

From: Zyt3x
Also:
Result := StrToInt(Replace(GetTextAtEx(50, 310, 3, StatChars, false, false, 0,
2, 16777215, 30, true, tr_Digits), ' ', '')) / RD;
Why "… / RD"?
Wouldn't 151,830 result in 152? Shouldn't you multiply instead? (And you would probably add Round() around that statement; Result := Round(StrToInt(….) * RD);


RD is depended on what the user wants it to come out to.
EG if it was 46236 gp and the user wanted it in 'k', it would make RD = 1000 and divide the result by RD(1000), the result would be 46 (46k). Result is an integer, so it automatically rounds down.

It reads the text for the total worth in the PC screen, removes the spaces, converts the string to an integer, then divides it by RD.

Gu3st...

2010-04-04 06:36:19

From: bionicle1800
RD is depended on what the user wants it to come out to.
EG if it was 46236 gp and the user wanted it in 'k', it would make RD = 1000 and divide the result by RD(1000), the result would be 46 (46k). Result is an integer, so it automatically rounds down.

It reads the text for the total worth in the PC screen, removes the spaces, converts the string to an integer, then divides it by RD.


Right.. So it did what I though it did after all.. But why do you want it to be like that? Wouldn't 46236 be better than 46? I don't agree your logic here.. :/

Frement

2010-04-04 06:38:42

Yeah, I think the value divisions are too much in it.

Bionicle

2010-04-04 20:25:46

If you want it in the basic gp form, then put 'gp'.
things like 'k' and 'm' would be for proggies, that is what I would use them for, because you don't want a 1m/h script putting 4857645 when it ran for 5 hours, you would want it more along the lines of 4857k or 4m.
EG:
Procedure BasicProggy;
Var
I: Integer;
Begin
I := PriceCheckAll(true, 'k');
AddToReport('Ran for ' + TimeRunning);
AddToReport('Made ' + IntToStr(I) + 'k.');
End;

E: Any more comments? Any one like the idea? :p

Gu3st...

2010-04-05 06:27:23

Oh, lol of course. I forgot you could specify what output you wanted xP
Sorry

Naum

2010-04-05 09:48:15

From: Wizzup?
That code isn't very portable; though. I doubt it will work on other platforms nor on a different interpreter. Not to mention his code is more readable.


Okay, on the subject of readable code -

procedure DropAllExcept(DontDrop: TIntegerArray);
var
inv, i, h: Integer;
begin
h := high(DontDrop);
for i := 0 to h do
{ Set the bit associated with the DontDrop Array }
inv := inv or (1 shl DontDrop[i]);
for i := 1 to 28 do
{ Check the bit at i, and if its high, then we dont drop. }
if (((inv shr i) and 1) = 0) then
DropItem(i);
end;

Could someone explain why that's in there?

Bionicle

2010-04-05 14:54:30

From: Zyt3x
Oh, lol of course. I forgot you could specify what output you wanted xP
Sorry


Lol that's why you specify it as 'gp', 'k', 'm' or 'b' :p