Jump to content

Trying to understand the API.


Pokerstar

Recommended Posts

Want to get into scripting, spending countless hours watching indians on youtube to get a basic understanding. I still dont understand how the API works and how it interacts, so I am just throwing some random shit together and hoping it doesn't smell too bad.

 

Anyway. What I want this script to do is check if Inventory is full, if not then to open bank, withdraw 1 bucket, close bank interface and then drop it....

 

Can someone break down the lines of my script so I can get a better understanding of the mechanics. Tanks..

 

Prepare your eyes for the horror. 

 

public int onLoop() throws InterruptedException {
 
if (!inventory.isFull()); { 
getBank();
bank.withdraw("Bucket", 1);
sleep(3000);
bank.close();
getInventory().dropAll();
 
}
return 6000;
Link to comment
Share on other sites

 

public int onLoop() throws InterruptedException {

 
if (!inventory.isFull()); { 
getBank();
bank.withdraw("Bucket", 1);
sleep(3000);
bank.close();
getInventory().dropAll();
 
}
return 6000;

 

 

So this looks alright, but as it's a live game with things changing all the time, and lag etc, you cannot rely 100% on more or less any line of code to successfully pull off what you want it to do. To combat this, you need to try (and potentially retry) performing actions depending on the current state of the game. There are a number of ways to do this, but perhaps the easiest to understand would be a standard if/else setup within your onLoop:

 

for example, in your code you have a single if statement surrounding all of your code. This is fine, except what if the inventory is full? then the script will loop forever.

 

(on a sidenote, the return value of onLoop is the delay between loops in milliseconds - 6 seconds is quite alot, and you might find it easier if you set it to something around 300 and use a case based structure as i'll show below.

 

I won't give you the code straight up, as that's no way to learn, but I'll tell you the commands which you need to use to perform the actions you're going for. It's up to you to order them and structure them as you need:

// Checks if inventory is full
if (inventory.isFull()); {

}

// finds the nearest bank booth
RS2Object booth = objects.closest("Bank-booth"); //(you may need to change the name)

if (booth != null && booth.exists()); { //Check it's really there
    booth.interact("Bank"); //Interact with bank booth
    sleep(500); // Sleep after interacting to give time for bank to open
}

//Withdrawing an item:
if(bank.contains("Bucket")) {
    bank.withdraw("Bucket", 1);
} else {
//... do something like stop
}

Note that stuff like static sleeps etc are really not a good idea, but it's fine for now. Also, I wrote this in the reply box so there may be some errors (sorry!).

 

So ye back to that if/else thing, basically run checks to determine what action to perform, one at a time. For example, if your inventory has a bucket and the bank is open, close the bank. Or if you have a bucket and the bank is closed, drop the bucket. Or if your inventory is empty and the bank is closed, then open the bank.

 

Hope that helped, sorry it's a scrappy reply, I just woke up!

Let me know if you have any more questions, 

Apa

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...