Jump to content

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


Apaec

Recommended Posts

  • 3 weeks later...

Replace this:

 

With this:

		if (Willow != null) {
				if (Willow.isVisible()) {
					Willow.interact("Chop down");
				} else {
					sleep(random(500, 700));
				}
			}

The Willow.isVisible will check if the willow actually is visible. If it's visible, then chop. Else, it's gonna sleep for 500 till 700 milliseconds. Randomly. Hope that works buddy.

 

 

 

 

Nope, the name for a willow tree is Willow. But i'm sure you already knew that.

 

interact already has visibility and camera handling checks and methods, so there's no need to call willow#isVisible at all. Infact, what kitiria had originally was probably much better, as your method will get in a continuous sleep loop if the willow isn't null but is off the screen.

 

@Kitiria:

 

If you really wanted to make it more efficient and not get permanently stuck, you can use a filter (a neat way of doing this is with streams, like so):

objects.getAll().stream().filter(obj -> (obj.exists() && obj.getName().equals("Willow") && obj.hasAction("Chop-down") && getMap().distance(obj) <= 10)).collect(Collectors.toList());

which will reasonably efficiently generate a collection of all the nearby objects with the name willow and the interaction option chop down within a distance of 10 tiles from the player. you can then proceed to iterate through this collection and further filter it to find your desired tree, and then interact with it like so

if (tree != null && tree.exists()) {
tree.interact();
}

~apa

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

Don't worry about pestering me!: )

 

As for the code, FORMAT IT! 

 

From first glance it looks like you've got the bracket alignment wrong in the getState() switch. It's quite hard to read tho as it's all over the place. but generally, an NPE is an easy error to fix. It just means you forgot to null check something - in this case specifically on line 52 (as it says in the stacktrace). Take a look at that line and see if you can figure out what's wrong! smile.png (hint - nullcheck the cupboard biggrin.png)

 

apa

See a lot of new questions and answers analysis code, I have also been able to write a simple script that just need to walk with the bank study using this code structure, but the code I clicked him, pages have been removed, impatient, you could get him that code issued to, or send a similar walk to the bank's case it Thank you

Link to comment
Share on other sites

如果(cow.getHealth()<8)// IM假设你取名为牛牛人大变量。
//基本上这将检查奶牛的健康,如果其在8也不会攻击它。
{
cow.interact(“攻击”);
}


你可以添加额外的检查也一样,如果(cow.getHealth()<8 &&!cow.isUnderAttack)

这样你可以有2个检查,看看,如果牛没有损坏,如果牛是不是underattack。如果你想添加第三个检查,您可以使用消息listenter让这句话在客舱“全国人大代表已经受到攻击”或什么做

@覆盖
	公共无效的onMessage(消息消息)抛出InterruptedException的
	{
	如果(message.getMessage()。toString()方法。包括(“已受到攻击。”))//确保这一具有完全一样的短语,情况sensetive所有
	{
	日志(“这牛是已经受到攻击!”);
	 //然后让你的角色到其他地方或有它做其他操作就得到这个之后。
	}
	}

我不是最好的osbot API / java中一般,但是这应该有点帮助,apaec可能会能够给你更多的建议虽然。

 

我误解你的问题我不好,要离开,有柜面,虽然其他人是好奇。

 

你可以做的就是让你杀奶牛在cowpen的一个区域,然后你可以这样做

区COWPEN =新的区域(右上方X,右上方Y,左下方X,左下方Y);
如果(cow.isUnderAttack)
{
localWalker.walk(COWPEN.getRandomPosition(0)); //将获得一个随机的区域,在牛笔地跑了出去,然后将杀牛是不受到攻击,或者继续这样做,直到它找到一个。
}

挑衅更好的方法,但是这是后话,将工作。

 

      I can write to you, know that the problem exists, but I can not own power or correction. I would like to write in a small area to move the script will not be attacked when there is no cow to walk around to find the target range set me please help me modify

  Thank you
 
 
 
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.NPC;
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 {
WALK, WAIT
};
 
private State getState() {
Area COWPEN = new Area(422, 62,51, 332);
NPC  cow = npcs.closest("Cow");
 
if(cow.isUnderAttack() && cow.getHealth()<8 )
 
 
return State.WALK;
return State.WAIT;
}
 
@Override
public int onLoop() throws InterruptedException {
switch (getState()) {
 
case WALK:
NPC  cow = npcs.closest("Cow");
if(cow.isUnderAttack() )
{
localWalker.walk(COWPEN.getRandomPosition(0));//will get a random area in the cow pen to run off to, then will kill cows that aren't under attack, or keep doing this until it finds one.
//}
}
break;
case WAIT:
sleep(random(500, 700));
break;
}
return random(200, 300);
}
 
@Override
public void onExit() {
log("Thanks for running my Tea Thiever!");
}
 
@Override
public void onPaint(Graphics2D g) {
 
}
 
Link to comment
Share on other sites

final Area BONE_AREA = new Area(3092,3298,3092,3512);
final Area BANK_AREA = new Area(3097,3497,3093,3494);
 
    @Override
    public void onStart() { 
        log("Initializing Script");
    }
 
    
private enum State {
COLLECT, FULL, WAIT
};
 
 
private State getState() {
if (inventory.isFull())
return State.FULL;
if (!inventory.isFull())
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 FULL:
 
walk(BANK_AREA);
 
 
~~~~~~~~~~~~~
 
 walk is underlined red and wants me to create a method, i tried following a guide and theirs doesn't come up with an error, what am i doing wrong?
 
 and i have this for paint so far.
 
 
  Graphics2D gr = (Graphics2D)g;
   
    gr.setColor(Color.MAGENTA);
    gr.setFont(new Font("comic sans",Font.PLAIN,12));
    gr.drawString("Bones Collected", 25, 50);
    
 
the guide i was following uses chat messages to grab the information for paint, there is no chat message in my script so, how would i get mine?
 
 
case COLLECT:
BONES.interact("take");
 
 Id assume something in this bit
 
 Maybe something like 
 
 if BONES.interact("take")
(insert code for ++ paint here)
 
 ??
  

 

 

 meant to message this.. lol

Edited by sonda
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   1 member

×
×
  • Create New...