Jump to content

Agility Script


protectedboolean

Recommended Posts

Hi folks,

 

I took an advanced Java course almost a year ago and made good marks, but haven't touched an IDE since then.. I thought I would try my hand at scripting, so I would appreciate any feedback on this script!

 

Thanks!

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import java.awt.*;

@ScriptManifest(name = "Draynor Agility Course", author = "", version = 1.0, info = "", logo = "")

public class Draynor_Agility extends Script{

    RS2Object RoughWall =  getObjects().closest("Rough Wall");//'Climb'
    RS2Object Tightrope =  getObjects().closest("Tightrope");//'Cross'
    RS2Object Tightrope2 =  getObjects().closest("Tightrope");//'Cross'
    RS2Object NarrowWall =  getObjects().closest("Narrow Wall");//'Balance
    RS2Object Wall =  getObjects().closest("Wall");//'Jump-up'
    RS2Object Gap =  getObjects().closest("Gap");//'Jump'
    RS2Object Crate =  getObjects().closest("Crate");//'Climb-down'

    int checkPoint = 0;

    @Override

    public void onStart(){
        log("Started Successfully");
        //Code here will execute before the loop is started
    }

    @Override

    public void onExit(){
        log("Ended Successfully");
        //Code here will execute after script ends
    }

    @Override

    public int onLoop() throws InterruptedException{

            if (checkPoint == 0 && RoughWall != null && !myPlayer().isAnimating()) {
                RoughWall.interact("Climb");
                checkPoint++;
            }
            else if(checkPoint == 1 && Tightrope != null && !myPlayer().isAnimating()){
                Tightrope.interact("Cross");
                checkPoint++;
            }
            else if(checkPoint == 2 && Tightrope2 != null && !myPlayer().isAnimating()){
                Tightrope2.interact("Cross");
                checkPoint++;
            }
            else if(checkPoint == 3 && NarrowWall != null && !myPlayer().isAnimating()){
                NarrowWall.interact("Balance");
                checkPoint++;
            }
            else if(checkPoint == 4 && Wall != null && !myPlayer().isAnimating()){
                Wall.interact("Jump-up");
                checkPoint++;
            }
            else if(checkPoint == 5 && Gap != null && !myPlayer().isAnimating()){
                Gap.interact("Jump");
                checkPoint++;
            }
            else if(checkPoint == 6 && Crate != null && !myPlayer().isAnimating()){
                Crate.interact("Climb-down");
                checkPoint = 0;
            }
            else return random(200,300);



        return random(200,300); //the amount of time before the loop starts over
    }

    public void onPaint(Graphics2D g){}
        //This is where you will put your code for paint(s)
}

 

Link to comment
Share on other sites

Well for starters your script won't even show up in the selector, nevermind run.

You can't make API calls:
 

RS2Object RoughWall =  getObjects().closest("Rough Wall");//'Climb'
RS2Object Tightrope =  getObjects().closest("Tightrope");//'Cross'
RS2Object Tightrope2 =  getObjects().closest("Tightrope");//'Cross'
RS2Object NarrowWall =  getObjects().closest("Narrow Wall");//'Balance
RS2Object Wall =  getObjects().closest("Wall");//'Jump-up'
RS2Object Gap =  getObjects().closest("Gap");//'Jump'
RS2Object Crate =  getObjects().closest("Crate");//'Climb-down'

Before onStart() has been called.

You should also only make a getObjects().closest() call when you actually want to use the object you are "getting".

Why put a 

!myPlayer().isAnimating()

Call in every if statement, when you can just do it once at the start of onLoop():

if (myPlayer().isAnimating()) {
  // sleep until player is not animating
} else {
  // do other stuff 
}


You should make sure that you check interactions are successful, the interact() function returns a boolean for a reason. It will return true if the interaction is successful, false if not. Currently, if an interaction fails your script will mess up, because you are incrementing your checkPoint variable. It should be:
 

if (gap.interact("Jump")) {
  checkPoint++;
}


In Java, variables should start with a lowercase first letter, e.g. roughWall, not RoughWall

Your logic will probably work for that agility course, but won't work for any other agility course, as you may need to walk to the next obstacle.

Using tonnes of if statements is fine, but if you want to support more agility courses, you should think of a different way to do it.
 

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

8 minutes ago, Explv said:

Well for starters your script won't even show up in the selector, nevermind run.

To go off of this since he didn't give any real info.

You need a manifest for it to show up in the selector (Look at the API)

It wont ever actually run cus you are only getting the objects once, you need to get them every loop to ensure you have the most up-to-date information to work with.

Also your checkpoint idea is gonna fail as soon as the bot misclicks once

Link to comment
Share on other sites

2 minutes ago, QBots said:

To go off of this since he didn't give any real info.

You need a manifest for it to show up in the selector (Look at the API)

It wont ever actually run cus you are only getting the objects once, you need to get them every loop to ensure you have the most up-to-date information to work with.

Also your checkpoint idea is gonna fail as soon as the bot misclicks once


I updated my answer with more detail.

He does have a manifest, that isn't the reason why I say it won't show up in the selector.

Link to comment
Share on other sites

it shows up in selector

https://i.imgur.com/v4UFUzD.png

 

16 minutes ago, QBots said:

To go off of this since he didn't give any real info.

You need a manifest for it to show up in the selector (Look at the API)

It wont ever actually run cus you are only getting the objects once, you need to get them every loop to ensure you have the most up-to-date information to work with.

Also your checkpoint idea is gonna fail as soon as the bot misclicks once

why would the bot misclick?

excuse my ignorance

 

how about this? can i have my checkPoint up there?

public class Draynor_Agility extends Script{

    private int checkPoint = 0;

 

 

THANK YOU EVERYONE i am just tryna learn :)

 

 

 

 

EDIT: I was looking off the tea thiever bot when making this :(

[ERROR][Bot #1][07/19 02:38:36 PM]: Error in bot executor!
java.lang.AbstractMethodError: client.getMouseX()I
    at org.osbot.rs07.api.Mouse.getPosition(hi:497)
    at org.osbot.rs07.event.InteractionEvent.iiIiiiiiIiiI(yi:217)
    at org.osbot.rs07.event.InteractionEvent.execute(yi:479)
    at org.osbot.rs07.event.EventExecutor$2.run(ch:252)
    at org.osbot.rs07.event.EventExecutor.execute(ch:213)
    at org.osbot.rs07.api.model.WallDecoration.interact(cn:25)
    at Draynor_Agility.onLoop(Draynor_Agility.java:38)
    at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(kl:223)
    at java.lang.Thread.run(Unknown Source)

Edited by protectedboolean
Link to comment
Share on other sites

17 minutes ago, protectedboolean said:

[ERROR][Bot #1][07/19 02:38:36 PM]: Error in bot executor!
java.lang.AbstractMethodError: client.getMouseX()I
    at org.osbot.rs07.api.Mouse.getPosition(hi:497)
    at org.osbot.rs07.event.InteractionEvent.iiIiiiiiIiiI(yi:217)
    at org.osbot.rs07.event.InteractionEvent.execute(yi:479)
    at org.osbot.rs07.event.EventExecutor$2.run(ch:252)
    at org.osbot.rs07.event.EventExecutor.execute(ch:213)
    at org.osbot.rs07.api.model.WallDecoration.interact(cn:25)
    at Draynor_Agility.onLoop(Draynor_Agility.java:38)
    at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(kl:223)
    at java.lang.Thread.run(Unknown Source)

The bot is not working right now, so there's no point trying to test scripts.

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