Jump to content

script skeleton with knives


rald

Recommended Posts

Hey guys, noob to scripting here looking for a little help with my knife grabbing bot. Basically I want to make a skeleton based on grabbing knives from the crate in lumbridge. I figured it would be one of the best ways for me to dive right in considering the code has to do with a Crate (object) with a knife (Item) on top and a staircase to the bank. I'm not to positive how to work with the Staircase or Bank, or even get the item on the crate into my inventory.

 

My code probably doesnt make much sense right now but my goal is when i find a knife or any item I hop worlds. First i need to know how to grab the knife and check when my inventory is full or not full. When it has an open slot I grab a knife only if i'm on knife floor. 
Assuming my code uses a "state machine", something i learned about in a scripting guide, my script also is trying to get my code to check what floor i'm on no matter what. Maybe I could create some sort of 2nd state to check this? If I'm on the second floor of lumby castle it needs to go up or down depending on if I should go up and bank or rather go down and get more knives.
I don't mind not understanding that part yet but it seems like something that I should start with in the code skeleton. Right now I'm trying to think of states as a bunch of modes that do different things, and the states can all go in to other states which are kind of like different "countries". The "countries" being floors that check what state I should be in then sending me to the appropriate "country" , then putting me back in another state to complete the task that needs to get done.

 

An example of how i could use this as a skeleton is maybe I could make other bots for picking up other items that spawn on the ground, but those might require me to learn about doors so I was hoping if I figured out how to interact with a crate maybe I could learn how to interact with a door and learning about states I could make door states depending if the door was closed or open.
 

My current code:

-----------------------------------------------------

http://pastebin.com/UJ6gBQWj

 

Link to comment
Share on other sites

Ok so you got a few things you want to learn, cool. Let's start with getting what floor you're on.

int a = myPlayer().getPosition().getZ();
switch (a){
case 0:
//do stuff on ground floor
break;
case 1:
//do stuff on second floor
break;
case 2:
//do stuff on top floor
break;
}

Obviously, you don't need to use a switch, but i've done it like so, so you know what the levels are.

 

 

Next, we have the inventory issue. You can find out if you have a full inventory by:

if(inventory.isFull()){
//do stuff after inventory is full
}

Here's where you tell your program to start climbing the stairs to go to the bank i guess.

If you're on the second floor, you'll need another check to see if you want to go up or down the stairs, you can make the same inventory.isFull() call to find your answer.

 

 

Banks are easy to interact with thanks to the API, all you gotta do is:

bank.Open();
if(bank.isOpen()){
bank.deposit("Knife", 28);
}

API for ref:

Bank: http://osbot.org/api/org/osbot/rs07/api/Bank.html

Player: http://osbot.org/api/org/osbot/rs07/api/model/Player.html

Inventory: http://osbot.org/api/org/osbot/rs07/api/Inventory.html

 

Edited by Zappster
  • Like 1
Link to comment
Share on other sites

Bank.open checks if the bank is open. So in reality he could just do:

if(bank.open())

{

//Banking Code

}

 

Also it's worth mentioning that you are using the Entity super class and you're missing out on some of the functionality. 

Instead try:

RS2Object crate = objects.closest("Crate")

 if (crate != null) {
crate.interact("Examine");
}
 
and
 
RS2Object bank = objects.closest("Bank");
if (bank != null) {
bank.interact("Bank");
inventory.isFull(); <- This does nothing
}
 
Similarly for NPCs:

NPC banker =  npcs.closest("Banker");
 
So inside of your LOOK state:
 
case LOOK:
GroundItem knife = groundItems.closest("Knife");
sleep(random(500, 700));
log(" for a knife");
break;
}
 
 
Good job on using states. Final criticism though:
 
Get rid of these randoms:
random(200, 300);
 
it does absolutely nothing for your bans. Instead "return 250;" is fine. 

 

  • Like 1
Link to comment
Share on other sites

I'm trying to use the "getX" thing that I found in the API to check if I'm on the correct tile during my LOOK state. I believe that I'm supposed to import something, and I want to make sure this works.
 
import org.osbot.rs07.script.Position;
 
It won't let me import this and I dont know why..

//EDIT:
Going to read the 2nd person's post and try to add stuff in, my LOOK state looks like it might be coming together finally! ;D

Here's my code so far:
 
 
 
//EDIT 2:
My script officially can find the knife in the spot it spawns and grabs it! this is so exciting for me haha.
I'm assuming my script will just sit here and wait until the next knife spawns until my inv gets full, but it would take ages to wait for that.. so looks like I need to find a way to make my player hop worlds. When my inventory gets full (I can buy more knives for testing purposes to fill it up, thats not a problem) we gotta check what floor we're on until we get to the top floor.
Instead of making it click the staircase it would be cool if there was a way to make it go to the tile beside the staircase and then click the stairs, but hey whatever works. This would probably just be helpful in coding another script where instead of going up stairs I could just walk to the next destination. For instance if I were going to edit this to grab fire runes in al kharid mining area then walk to the bank there I could use some destination/position code. 

Here's what I got so far, I'm trying to play around with the STEAL state and with the 0, 1, 2 cases inside that currently. Sorry about the multiple edits unsure.png
http://pastebin.com/j5R9pWWt
 
//EDIT 3:
I think I've made some good progress, my script can now hop worlds and when my inventory is full it goes up the stairs. One thing I'm going to try to figure out later is how i can get it to actually bank, getting my player to go up the stairs was easy lol but getting him to actually bank and go back down seems pretty difficult. I've been getting some strange error and i'll post it with my code afterwards. Just wanna say you guys have helped me a lot and I appreciate it. I'm still a little stuck on the multiple cases thing in my script to determine what to do depending on what floor i'm on.
 
[ERROR][bot #1][11/03 04:39:30 PM]: Error in script executor!
java.lang.NullPointerException
at Main.onLoop(Main.java:85)
at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(vk:145)
at java.lang.Thread.run(Unknown Source)

http://pastebin.com/H5Yd8ZNM

 All constructive criticism to make this grabber skeleton better is greatly appreciated!  Hopefully other scripters new and old can learn a thing or two. 
 
//EDIT 4:
After playing around with the code for a while I managed to get it to run without errors, it can pick up knives until you are full, hops worlds to find a new knife, gos upstairs Lumby castle when full, and goes to access the bank. After it opens the bank it closes it then reopens it and tries to go up the stairs. my next goal is to make it deposit my items when the bank gets opened and instead of constantly going up- make it go down when it needs to go get more knives. I someone wants to explain how i can make my code switch to from case to case that would be cool, my best guess was to do return case BANK in the code but it always gives me red lines :/

No errors this time, and here's my updated code:
 

 

Edited by rald
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...