SRL Archive - SRL Development and Help

backpack function updates (waitTime: integer = 0)


Thomas

2015-04-15 05:09:42

I have not tested these so far, can test later today though. These updates are usefull when looping a banking function with presets untill backpack.isFull or empty, so you don't have to repeat random waits untill you have desired backpack.

function TRSTabBackpack.isFull(waitTime: integer = 0): boolean;
var
i: integer;
t: UInt64;
begin
result := false;
t := (getTickCount64() + waitTime);

while (not result) and (t >= getTickCount64()) do
begin
if (not self.open()) then
exit(false);

for i := BACKPACK_SLOT_LOW to BACKPACK_SLOT_HIGH do
if (not (self.isItemInSlot(i))) then
exit(false);

result := true;
wait(randomRange(20, 50));
end;
end;

function TRSTabBackpack.isEmpty(waitTime: integer = 0): boolean;
var
b: tbox;
t: UInt64;
begin
result := false;
t := (getTickCount64() + waitTime);

while (not result) and (t >= getTickCount64()) do
begin
if (not self.open()) then
exit(false);

b := self.getBounds();
b.edit(0, 0, 0, -30);

result := (not b.colorExists(ITEM_OUTLINE_BLACK)) and (not b.colorExists(ITEM_OUTLINE_BLACK_SECONDARY)) and
(not b.colorExists(ITEM_OUTLINE_WHITE));
wait(randomRange(20, 50));
end;
end;

function TRSTabBackpack.isItemInSlot(slot: integer; waitTime: integer = 0): boolean;
var
t: UInt64;
begin
result := false;
t := (getTickCount64() + waitTime);

while (not result) and (t >= getTickCount64()) do
begin
if (not self.open()) or (not self.isSlotValid(slot))then
exit(false);

result := isItemIn(self.getSlotBox(slot));
wait(randomRange(20, 50));
end;
end;

Thomas

2015-04-15 06:15:34

If someone could test these please? For some reason I'm unable to spawn a SMART client currently…

Thomas

2015-04-15 12:31:27

@Clarity
Do you have any clue why these functions are so much slower then the regular/non modified?

Seems to work just fine on desktop though. If anyone else tests these im sure they can be pushed!

Banking function:
function banking(preset: integer): Boolean;
begin
if (not isLoggedIn()) then
exit(False);
FailTimer.start();
begin
repeat
if bankscreen.open(BANK_GE) then
break();
wait(gaussRangeInt(100, 500));
minimap.clickCompass();
if (FailTimer.getTime() > TIMEOUT) or (not isLoggedIn()) then
exit(False);
until bankScreen.isOpen(5000) or pinscreen.isOpen();
if pinScreen.isOpen() then
pinScreen.enter(players[currentPlayer].bankPin);
repeat
if bankScreen.clickButton(preset) then
exit(True);
wait(gaussRangeInt(100, 500));
until (FailTimer.getTime() > TIMEOUT) or (not isLoggedIn());
end;
end;

Part in mainloop:
repeat
if banking(BANK_BUTTON_PRESET_1) and (not tabBackpack.isFull()) then
failCount := failCount + 1;
if (FailCount > 4) then
begin
writeLn('Failed withdrawing, shutting down');
players[currentPlayer].logout();
terminateScript();
end;
if (not isLoggedIn()) or (FailTimer.getTime() > TIMEOUT) then
exit;
until tabBackpack.isFull(15000);

Clarity

2015-04-15 15:50:13

Hey :)

These are cool snippets! If I am reading your intentions correctly, however, you should be made aware of the waitFunc() method that can be used for any function returning a boolean.

It will continually run the desired function with the desired wait period in between runs. It will wait until the desired function returns true, with a desired timeout.

For example…

waitTypeFunc(@tabBackpack.isFull, 100, 10000);
…will run tabBackpack.isFull every 100ms until 10000ms has elapsed.

You need to use a "@" before the desired function, and waitTypeFunc() if using a type function.

Thomas

2015-04-15 16:24:57

@Clarity
Holy! I did not know that! Screw them repeat random waits until!

You mention waitfunc and waittypefunc, what is the difference? What is a typefunc?

Clarity

2015-04-15 16:33:41

From: lovebotter
@Clarity
Holy! I did not know that! Screw them repeat random waits until!

You mention waitfunc and waittypefunc, what is the difference? What is a typefunc?


No problem :) Making those snippets were still good practice I'm sure!

A normal function:
function hiHelloThere(): boolean;
A type function:
function greetingPhrase.hiHelloThere(): boolean;

So something like tabBackpack.isFull() is a type function, with the type being tabBackpack.

Thomas

2015-04-15 17:45:08

From: Clarity
No problem :) Making those snippets were still good practice I'm sure!

A normal function:
function hiHelloThere(): boolean;
A type function:
function greetingPhrase.hiHelloThere(): boolean;

So something like tabBackpack.isFull() is a type function, with the type being tabBackpack.


Thanks, my script seems to run flawless now!
Will also be usefull for my portable well vials script. Updating that tomorrow.

@Clarity
It seems to crash if I use this, resulting in an error given at the includes (forgot to copy paste);
until waitTypeFunc(@tabBackpack.isItemInSlot(1), 100, 5000);