Jump to content

Teacher Required


Recommended Posts

Posted

So I am new to scripting I did a little back when iBot was around and that was easy because mostly everything was already done for you, this on the other hand is more of a challenge... I have looked through some of the tutorials on the forum and watched what I could find on YouTube (which wasn't that many). I was hoping that I could have a mentor someone I could quickly ask a question to and get a fast response with helpful hints and tips that they have picked up them selves. My goal is to create great scripts that will last and to create video tutorials to teach anyone that wants to learn how to script with OSBOT and become a valued member of this community.

 

either way i'm not going to give up.

 

- Codex 

Posted (edited)

http://osbot.org/forum/topic/58775-a-beginners-guide-to-writing-osbot-scripts-where-to-get-started-by-apaec/

 

specifically

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "")
public class main extends Script {

    @Override
    public void onStart() {
        log("Welcome to Simple Tea Thiever by Apaec.");
        log("If you experience any issues while running this script please report them to me on the forums.");
        log("Enjoy the script, gain some thieving levels!.");
    }

    private enum State {
        STEAL, DROP, WAIT
    };

    private State getState() {
        Entity stall = objects.closest("Tea stall");
        if (!inventory.isEmpty())
            return State.DROP;
        if (stall != null)
            return State.STEAL;
        return State.WAIT;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case STEAL:
            Entity stall = objects.closest("Tea stall");//What this does is get's the closest entity //named tea stall, and stores it into stall
            if (stall != null) {//this if statement is saying if the stall
//is not null(exist pretty much) it will interact from it with the option
//"Steal-from"
                stall.interact("Steal-from");
            }
            break;//the break will tell the script to move on to what's
//next/go back to find another state
        case DROP:
            inventory.dropAll();//if your inventory is not empty, it will
//go to this case which basically says it will drop anything in your inventory, one item in your //inventory will trigger this to go off.
            break;
        case WAIT:
            sleep(random(500, 700));//this will happen if your inventory is full, and the stall is //null(nothing on it)
            break;
        }
        return random(200, 300);
    }

    @Override
    public void onExit() {
        log("Thanks for running my Tea Thiever!");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}

This right here is going to be the bear bones to anything you do. You can pretty much write anything using Statements, I'd recommend starting off with a basic script that will power mine/power chop something. Anything that you might need is already a method in the osbot api so you wont need to make your own methods. Do you have knowledge of java itself or have you just wrote a few basic bot scripts before?  Commented on some of the code just so you can get a better idea of what it's doing

Edited by twin 763
Posted

I have a very basic knowledge base of Java although I thought I would use scripting as away to learn and improve on both at the same time. I have an understanding of the script above my down fall if finding the correct methods for what I aim do so for example using an item in the inventory may seem simple but I cant find a method to suggest that's what it will do. I am going to take a step back and as you suggested for me to do small basic scripts first maybe prayer bone bury script.

Posted (edited)

I have a very basic knowledge base of Java although I thought I would use scripting as away to learn and improve on both at the same time. I have an understanding of the script above my down fall if finding the correct methods for what I aim do so for example using an item in the inventory may seem simple but I cant find a method to suggest that's what it will do. I am going to take a step back and as you suggested for me to do small basic scripts first maybe prayer bone bury script.

You'd want something like

if(!inventory.isEmpty()){
Bones.interact("Bury");
break;
}
//then you'd have
if(inventory.isEmpty())
{
bank.Open;
bank.Withdraw(either a string"Bones" or whatever the id of bones are you're using)
;bank.Close();
break;
}
//this isn't 100% right but it's a start. basically just go into the api, press f3 and search 

//inventory, then search for a keyword that you //think will help you, and then implement the method 

//next to inventory so if you want to do something if your inventory is full, inventory.IsFull();

edited something from mobile and it fucked up this things formatting, sorry about that.

Edited by twin 763
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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