Jump to content

A Beginners Guide to Writing OSBot Scripts (where to get started!) by Apaec


Apaec

Recommended Posts

Make sure you install the JDK (Java Developer Kit) before step 1. Having Java installed is not enough. You need access to the libraries.

 

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

 

NOTE: Download the x86 version NOT the 64 bit version. Otherwise you will not be able to attach with the mirror client when running scripts. I found out the hard way. 64 bit and mirror client do not work well together as of now...

Edited by mustang guy
Link to comment
Share on other sites

Thanks man, you got me into scripting! biggrin.png

I have a problem though, yesterday i made a script that worked perfectly, but now i tried to make another one and it won't show up in the Script Selector even though the other one does. They're in the same location and im pretty sure the Manifest is correct.

Any idea what i'm doing wrong? 

 

Screenshot: http://puu.sh/jFYaQ/72737b9bdf.png

 

 

 

  • Like 1
Link to comment
Share on other sites

Thanks man, you got me into scripting! biggrin.png

I have a problem though, yesterday i made a script that worked perfectly, but now i tried to make another one and it won't show up in the Script Selector even though the other one does. They're in the same location and im pretty sure the Manifest is correct.

Any idea what i'm doing wrong? 

 

Screenshot: http://puu.sh/jFYaQ/72737b9bdf.png

 

close osbot, delete all files in your script directory, open osbot, reexport script, refresh scripts, voila!

 

apa

PS i'm glad I got you into scripting

 

hopefully things go well and good luck :) don't give up!

 

apa

Link to comment
Share on other sites

Hi, 

 

Im trying to get into scripting. 

 

The thing that confuses me is how to find out what everything is called

like i know how to create an entity or an npc or grounditem now and interact with it, but every time i want to try out something new like for instance check if the inventory is full i have no idea how to go about and find out what code i should use. 

 

 

like. i read from the API 

 

 

public boolean dropAllExcept(int... ids)
Drops all the items in the inventory excluding items with the ids passed.
Parameters:
ids - Item ids to ignore when dropping.
Returns:
True if the items were dropped successfully.

 

 

so naturally i put:

    public int onLoop() throws InterruptedException {
		switch (getState()) {
		case COLLECT:
			break;
		case DROP:
			public boolean dropAllExcept(526);
			break;
		case WAIT:
			break;
		}
		return random(200, 300);

 but it gives me an error... tell me what im doing wrong.

Edited by levvyy
Link to comment
Share on other sites

Hi, 

 

Im trying to get into scripting. 

 

The thing that confuses me is how to find out what everything is called

like i know how to create an entity or an npc or grounditem now and interact with it, but every time i want to try out something new like for instance check if the inventory is full i have no idea how to go about and find out what code i should use. 

 

 

like. i read from the API 

 

 

so naturally i put:

    public int onLoop() throws InterruptedException {
		switch (getState()) {
		case COLLECT:
			break;
		case DROP:
			public boolean dropAllExcept(526);
			break;
		case WAIT:
			break;
		}
		return random(200, 300);

 but it gives me an error... tell me what im doing wrong.

 

It might be worth taking a look at some basic java. This will give you understanding of these kinds of things.

 

public and boolean are what the method is defined by. But you want to use the name of the method to call it

so it would be

 

inventory.dropAllExcept(id);

 

boolean tells you it returns true or false, much like if it said int it would return 1, 2, 3 etc.

 

apa

Link to comment
Share on other sites

ah wait so the class is inventory, and the method im calling is dropAllExcept(526)

 

so i should do : class.methodtocall()  ??

 

Pretty much yea :)

 

so for example with bank:

bank.withdraw("rune boots"); //or whatever the item

and inventory:

inventory.dropAll("rune boots"); //or whatever the name of the item to drop

apa

Link to comment
Share on other sites

right, so if i find methods from parent classes i can use them on the subclass too? so the method "isfull" that is used on itemcontainer class, is inherited by inventory? so i can use inventory,isFull() which will return a bool?

 

edit: thanks for helping me out. I am starting my computer sciences stody next week and wanted to brush up on java before i started. i thought scripting might be a nice way to get into it. you've taught me something and i thank you for it. 

I was able to create a simple Bone collector + burier script that detects when it picks up something odd and drops it. 

 

source

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


import java.awt.*;


@ScriptManifest(author = "Levvyy", info = "Boneburierv1.0", name = "Bone Burier", version = 0, logo = "")
public class main extends Script {


    @Override
    public void onStart() {
        log("Initializing Script");
    }
    
private enum State {
COLLECT, DROP, FULL, WAIT
};


private State getState() {
if (inventory.isFull())
return State.FULL;
if (!inventory.isEmptyExcept(526))
return State.DROP;
if (inventory.isEmptyExcept(526))
return State.COLLECT;
return State.WAIT;
}


    @Override
    public int onLoop() throws InterruptedException {
GroundItem BONES = groundItems.closest("bones");
switch (getState()) {
case COLLECT:
BONES.interact("take");
break;
case DROP:
inventory.dropAllExcept("bones");
break;
case FULL:
while(!inventory.isEmpty()){
inventory.interact("bury", "bones");
}
break;
case WAIT:
break;
}
return random(200, 300);
    }


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


    @Override
    public void onPaint(Graphics2D g) {


    }


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

Hey man thanks for the awesome tutorial! I am just now getting back in to coding with osbot and im having an issue where scripts that i run dont really start. i even copied the code in your tutorial line for line to see if it was an issue with my code and still the same error. Have you ever heard of this and do you know of a fix?

  • Like 1
Link to comment
Share on other sites

Hey man thanks for the awesome tutorial! I am just now getting back in to coding with osbot and im having an issue where scripts that i run dont really start. i even copied the code in your tutorial line for line to see if it was an issue with my code and still the same error. Have you ever heard of this and do you know of a fix?

 

Hey, there have recently been some server errors due to ddos attacks. Maybe this problem you're experiencing is related? otherwise i'm not too sure as my stuff seems to be working ok :o

 

apa

Link to comment
Share on other sites

  • Alek unpinned this topic

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...