Jump to content

First Script Help


Rhetoric

Recommended Posts

I have been reading some of your guides on creating scripts but I'm struggling with my first script and I am wondering if you would take some time to help me out. smile.png
 
Question 1:
I'm currently attempting to add anti-ban to my script and I'm getting the follow errors when adding the following:
 
this.client.rotateCameraPitch(50);
 
Error Message: The method this.client.rotateCameraPitch(int) is undefined for the type Client
I highlighted the text to indicate the red underline in Eclipse.
 
I get this message for rotateCameraPitch, rotateCameraAngle, and moveMouseOutsideScreen() (...for the type Main).
I'm assuming I need to import something but I can't find what (library?).

Current Imports:
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.script.MethodProvider;


 
Question 2:
The only current banking method I know of is bank.depositAll(); but I want to keep my rune axe in my inventory. How can I only deposit specific items (in this case yew logs)?
 
Question 3:

My bot spam clicks on Yew trees in the highlighted time frame and making a longer random time only delays the reaction time for the bot to move on to the next tree as well as spam clicks.

 

        case CHOP:
            if (!myPlayer().isAnimating()) {
                Entity yewTree = objects.closest(YEW_ID);
                if (yewTree != null) {
                    if (yewTree.interact("Chop down")) {
                        sleep(random(2500, 3500));    
                    }
                }
            }
 

Question 4:

Is there anyway to slow down mouse movements to make them look more human-like and a way to make them more curved rather than a straight line?

 

Thanks for any and all help! smile.png

Edited by Rhetoric
Link to comment
Share on other sites

1. getCamera().movePich(int);

getMouse().moveOutsideScreen();

2. getBank().depositAllExcept("rune axe");

3. What is your onLoop() return time? You should return atleast 600ms(1 in game tick);

4. Yes but you need to write your own mouse movements.

You should check out the api page too

Edited by Vilius
  • Like 3
Link to comment
Share on other sites

1. getCamera().movePich(int);

getMouse().moveOutsideScreen();

2. getBank().depositAllExcept("rune axe");

3. What is your onLoop() return time? You should return atleast 600ms(1 in game tick);

4. Yes but you need to write your own mouse movements.

You should check out the api page too

 

3. My code is sluggish when having to transfer to the next yew tree.

public int onLoop() throws InterruptedException {

        switch (getState()) {

        case CHOP:

            if (!myPlayer().isAnimating()) {

                Entity yewTree = objects.closest(YEW_ID);

                if (yewTree != null) {

                    if (yewTree.interact("Chop down")) {

                        sleep(random(2500, 3500));    

                    }

                }

            }

            while(myPlayer().isAnimating()) {

                Antiban();

            }

            break;

        case WALK_TO_BANK:

            localWalker.walkPath(path1);

            sleep(random(1500, 2500));

            break;

        case BANK:

            NPC bankBooth = npcs.closest("Bank booth");

            if (bankBooth != null) {

                if (bankBooth.interact("Bank")) {

                    while (!bank.isOpen()) {

                        sleep(250);

                    }

                    getBank().depositAllExcept("Rune axe");

                }

            }

            break;

        case WALK_TO_TREE:

            localWalker.walkPath(path2);

            sleep(random(1500, 2500));

            break;

        }

        return random(200, 300);

    }

 

4. Where can I learn to write my own mouse movements?

Link to comment
Share on other sites

1. to rotate the Camera check out this page in the api:

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

 

You'll most likely be needing the:

camera.movePitch(int);
        camera.moveYaw(int);

2. Check out hte banking api:

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

 

For this answer you'll need the

bank.depositAllExcept();

This method will take ids/string/objects. Look into the api for more information

 

 

3.

The problem is that the script is looping too quickly. There's about 600-800ms gap between you interacting with an item and then getting an animation from it. So increase your loop sleep from 100, to 700+.

 

4. I've just had a look at the api for mouse, and it looks like the mouse.setSpeed() has been depricated. Maybe you can make your own mouse events? I've never tried so I dunno, but here's the API page to get started:

http://osbot.org/api/org/osbot/rs07/input/mouse/MouseEvent.html

 

   

3. My code is sluggish when having to transfer to the next yew tree.

public int onLoop() throws InterruptedException {
        switch (getState()) {
        case CHOP:
            if (!myPlayer().isAnimating()) {
                Entity yewTree = objects.closest(YEW_ID);
                if (yewTree != null) {
                    if (yewTree.interact("Chop down")) {
                        sleep(random(2500, 3500));    
                    }
                }
            }
            while(myPlayer().isAnimating()) {
                Antiban();
            }
            break;
        case WALK_TO_BANK:
            localWalker.walkPath(path1);
            sleep(random(1500, 2500));
            break;
        case BANK:
            NPC bankBooth = npcs.closest("Bank booth");
            if (bankBooth != null) {
                if (bankBooth.interact("Bank")) {
                    while (!bank.isOpen()) {
                        sleep(250);
                    }
                    getBank().depositAllExcept("Rune axe");
                }
            }
            break;
        case WALK_TO_TREE:
            localWalker.walkPath(path2);
            sleep(random(1500, 2500));
            break;
        }
        return random(200, 300);
    }

 

4. Where can I learn to write my own mouse movements?

 

You see your final return random(200,300)? Replace that with return random(700,800);

 

 

Edit: sorry didn't see Vil had already replied

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

3. My code is sluggish when having to transfer to the next yew tree.

public int onLoop() throws InterruptedException {

switch (getState()) {

case CHOP:

if (!myPlayer().isAnimating()) {

Entity yewTree = objects.closest(YEW_ID);

if (yewTree != null) {

if (yewTree.interact("Chop down")) {

sleep(random(2500, 3500));

}

}

}

while(myPlayer().isAnimating()) {

Antiban();

}

break;

case WALK_TO_BANK:

localWalker.walkPath(path1);

sleep(random(1500, 2500));

break;

case BANK:

NPC bankBooth = npcs.closest("Bank booth");

if (bankBooth != null) {

if (bankBooth.interact("Bank")) {

while (!bank.isOpen()) {

sleep(250);

}

getBank().depositAllExcept("Rune axe");

}

}

break;

case WALK_TO_TREE:

localWalker.walkPath(path2);

sleep(random(1500, 2500));

break;

}

return random(200, 300);

}

4. Where can I learn to write my own mouse movements?

3. Well you see you got return random(200,300)

You should change it to return random(600, 700)

4. I have no idea to be honest.

  • Like 1
Link to comment
Share on other sites

You guys are really helpful, thanks! smile.png

 

My script doesn't seem to function very well at all, it doesn't seem to switch states properly and just breaks down and afks...

I guess I might as well post all of the code and see if anyone can help point out my flaws.

 

It was made to chop yews at Varrock Palace and bank at G.E.

 

import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.script.MethodProvider;


import java.awt.*;

@ScriptManifest(author = "yumii", info = "My First Script", name = "Yew Cutter", version = 0, logo = "")
public class main extends Script {
    
    private static final int[] YEW_ID = { 27255 };
    
    private Position[] path1 = {
            new Position (3207, 3502, 0),
            new Position (3196, 3495, 0),
            new Position (3182, 3490, 0),
            new Position (3171, 3490, 0),
            new Position (3167, 3490, 0)
    };
    
    private Position[] path2 = {
            new Position (3167, 3490, 0),
            new Position (3171, 3490, 0),
            new Position (3182, 3490, 0),
            new Position (3196, 3495, 0),
            new Position (3207, 3502, 0)
    };
    
    private static final Area TREE_AREA = new Area(3201, 3506, 3224, 3498);
    private static final Area BANK_AREA = new Area(3168, 3493, 3161, 3486);

    @Override
    public void onStart() {
        log("Script started.");
    }

    private enum State {
        CHOP, WALK_TO_BANK, BANK, WALK_TO_TREE
    };

    private State getState() {
        if (inventory.isFull() && TREE_AREA.contains(myPlayer())) {
            return State.WALK_TO_BANK;
        }
        if (inventory.isFull() && BANK_AREA.contains(myPlayer())) {
            return State.BANK;
        }
        if (!inventory.isFull() && BANK_AREA.contains(myPlayer())) {
            return State.WALK_TO_TREE;
        }
        return State.CHOP;
    }

    public void Antiban() throws InterruptedException {
        switch (random(1, 30)) {
        case 1:
            getCamera().movePitch(random(35, 65));
            break;
        case 2:
            getCamera().moveYaw(100 + (random(1, 70)));
            break;
        case 3:
            sleep(MethodProvider.gRandom(8500, 12500));
            getTabs().open(Tab.SKILLS);
            sleep(MethodProvider.gRandom(375, 725));
            getSkills().hoverSkill(Skill.WOODCUTTING);
            break;
        case 4:
            sleep(MethodProvider.gRandom(4500, 9500));
            getMouse().moveRandomly();
            break;
        case 5:
            getCamera().movePitch(50 + random(1, 70));
            break;
        case 6:
            getCamera().moveYaw(150 + (random(30, 70)));
            break;
        case 7:
            getTabs().open(Tab.CLANCHAT);
            break;
        case 8:
            getTabs().open(Tab.FRIENDS);
            break;
        case 9:
            getMouse().moveOutsideScreen();
            sleep(random(2500, 4000));
            break;
            // Add player right clicking later
        }
        sleep(random(700, 1800));
        getTabs().open(Tab.INVENTORY); //RETURNS TO THE INVENTORY TAB AFTER EVERY ANTIBAN INSTANCE
    }
    
    @SuppressWarnings("deprecation")
    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case CHOP:
            if (!myPlayer().isAnimating()) {
                Entity yewTree = objects.closest(YEW_ID);
                if (yewTree != null) {
                    if (yewTree.interact("Chop down")) {
                        sleep(random(2500, 3500));    
                    }
                }
            }
            while(myPlayer().isAnimating()) {
                Antiban();
            }
            break;
        case WALK_TO_BANK:
            localWalker.walkPath(path1);
            sleep(random(1500, 2500));
            break;
        case BANK:
            NPC bankBooth = npcs.closest("Bank booth");
            if (bankBooth != null) {
                if (bankBooth.interact("Bank")) {
                    while (!bank.isOpen()) {
                        sleep(250);
                    }
                    getBank().depositAllExcept("Rune axe");
                }
            }
            break;
        case WALK_TO_TREE:
            localWalker.walkPath(path2);
            sleep(random(1500, 2500));
            break;
        }
        return random(700, 800);
    }

    @Override
    public void onExit() {
        log("Script terminated.");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}

Edited by Rhetoric
Link to comment
Share on other sites

You guys are really helpful, thanks! smile.png

 

My script doesn't seem to function very well at all, it doesn't seem to switch states properly and just breaks down and afks...

I guess I might as well post all of the code and see if anyone can help point out my flaws.

 

It was made to chop yews at Varrock Palace and bank at G.E.

 

import org.osbot.rs07.api.ui.Tab;

import org.osbot.rs07.api.map.Area;

import org.osbot.rs07.api.ui.Skill;

import org.osbot.rs07.api.model.NPC;

import org.osbot.rs07.api.map.Position;

import org.osbot.rs07.api.model.Entity;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

import org.osbot.rs07.script.MethodProvider;

import java.awt.*;

@ScriptManifest(author = "yumii", info = "My First Script", name = "Yew Cutter", version = 0, logo = "")

public class main extends Script {

    

    private static final int[] YEW_ID = { 27255 };

    

    private Position[] path1 = {

            new Position (3207, 3502, 0),

            new Position (3196, 3495, 0),

            new Position (3182, 3490, 0),

            new Position (3171, 3490, 0),

            new Position (3167, 3490, 0)

    };

    

    private Position[] path2 = {

            new Position (3167, 3490, 0),

            new Position (3171, 3490, 0),

            new Position (3182, 3490, 0),

            new Position (3196, 3495, 0),

            new Position (3207, 3502, 0)

    };

    

    private static final Area TREE_AREA = new Area(3201, 3506, 3224, 3498);

    private static final Area BANK_AREA = new Area(3168, 3493, 3161, 3486);

    @Override

    public void onStart() {

        log("Script started.");

    }

    private enum State {

        CHOP, WALK_TO_BANK, BANK, WALK_TO_TREE

    };

    private State getState() {

        if (inventory.isFull() && TREE_AREA.contains(myPlayer())) {

            return State.WALK_TO_BANK;

        }

        if (inventory.isFull() && BANK_AREA.contains(myPlayer())) {

            return State.BANK;

        }

        if (!inventory.isFull() && BANK_AREA.contains(myPlayer())) {

            return State.WALK_TO_TREE;

        }

        return State.CHOP;

    }

    public void Antiban() throws InterruptedException {

        switch (random(1, 30)) {

        case 1:

            getCamera().movePitch(random(35, 65));

            break;

        case 2:

            getCamera().moveYaw(100 + (random(1, 70)));

            break;

        case 3:

            sleep(MethodProvider.gRandom(8500, 12500));

            getTabs().open(Tab.SKILLS);

            sleep(MethodProvider.gRandom(375, 725));

            getSkills().hoverSkill(Skill.WOODCUTTING);

            break;

        case 4:

            sleep(MethodProvider.gRandom(4500, 9500));

            getMouse().moveRandomly();

            break;

        case 5:

            getCamera().movePitch(50 + random(1, 70));

            break;

        case 6:

            getCamera().moveYaw(150 + (random(30, 70)));

            break;

        case 7:

            getTabs().open(Tab.CLANCHAT);

            break;

        case 8:

            getTabs().open(Tab.FRIENDS);

            break;

        case 9:

            getMouse().moveOutsideScreen();

            sleep(random(2500, 4000));

            break;

            // Add player right clicking later

        }

        sleep(random(700, 1800));

        getTabs().open(Tab.INVENTORY); //RETURNS TO THE INVENTORY TAB AFTER EVERY ANTIBAN INSTANCE

    }

    

    @SuppressWarnings("deprecation")

    @Override

    public int onLoop() throws InterruptedException {

        switch (getState()) {

        case CHOP:

            if (!myPlayer().isAnimating()) {

                Entity yewTree = objects.closest(YEW_ID);

                if (yewTree != null) {

                    if (yewTree.interact("Chop down")) {

                        sleep(random(2500, 3500));    

                    }

                }

            }

            while(myPlayer().isAnimating()) {

                Antiban();

            }

            break;

        case WALK_TO_BANK:

            localWalker.walkPath(path1);

            sleep(random(1500, 2500));

            break;

        case BANK:

            NPC bankBooth = npcs.closest("Bank booth");

            if (bankBooth != null) {

                if (bankBooth.interact("Bank")) {

                    while (!bank.isOpen()) {

                        sleep(250);

                    }

                    getBank().depositAllExcept("Rune axe");

                }

            }

            break;

        case WALK_TO_TREE:

            localWalker.walkPath(path2);

            sleep(random(1500, 2500));

            break;

        }

        return random(700, 800);

    }

    @Override

    public void onExit() {

        log("Script terminated.");

    }

    @Override

    public void onPaint(Graphics2D g) {

    }

}

 

 

The problem is that you're using a depricated function and then supressing the warning so you don't know about it lol.

make the following changes:

 Delete Line 100:

@SuppressWarnings("deprecation")

Change all calls of

localWalker.walkPath

too

walking.webWalk

(Line 117, 132)

 

Note with webwalker: you no longer need to plan a path out, such as what you have done. All it requires is the final position + OSBot will map the path. So you can replace line 117 and 132's path call with the respective final position destinations. You'll need to make this change as webwalker will only take the one position.

 

 

Edited by Zapster
Link to comment
Share on other sites

What's wrong with it?

 

 

It likes to obnoxiously rotate the camera and take a very odd path when banking/returning from G.E. to Varrock Palace. It looks a lot like this..

 

0e211159c3.png

Red: Using walking.webWalk

Blue: Using walking.walk

 

I'm currently using walking.walk(Position position); as I find it much neater (uses less spam clicking + more accurate clicks) and faster.

  • Like 1
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...