Chris

[Video Tutorial] Introduction To RSBot Scripting (IDE set-up & your first combat script) ~ Video 1

Recommended Posts



Biafra   
On 7/14/2018 at 1:59 PM, Chris said:

you missed a space 

Thank You very much. Everything works fine now. I have two more questions:

 

1. How do i go about making sure that bot doesnt go to far off of the starting position?

 

2. Is there high chance of ban using similar script but with random wait times between killing npcs, and using it only couple hours here and there?

Share this post


Link to post
iDzn   
4 minutes ago, Biafra said:

Thank You very much. Everything works fine now. I have two more questions:

 

1. How do i go about making sure that bot doesnt go to far off of the starting position?

 

2. Is there high chance of ban using similar script but with random wait times between killing npcs, and using it only couple hours here and there?

1. Don’t tell it to, the bot will do what you tell it to do. There are lots of different ways.

1.1 only attack npcs inside a certain area

1.2 if you’re further away than X amount of tiles from starting position run back to the starting position etc

 

2. There is always a chance of being banned.

Edited by iDzn

Share this post


Link to post
Biafra   
7 minutes ago, iDzn said:

1. Don’t tell it to, the bot will do what you tell it to do. There are lots of different ways.

1.1 only attack npcs inside a certain area

1.2 if you’re further away than X amount of tiles from starting position run back to the starting position etc

 

2. There is always a chance of being banned.

Yea i know logically how to do it i asked about specific method names, or how i go about finding them?

Share this post


Link to post
iDzn   
54 minutes ago, Biafra said:

Any idea why this doesnt work? i get -1 value from stackSize().

 

https://imgur.com/dAIZHLT

You have to be on the equipment tab, unfortunately with rings and ammo you can’t get them without being on that tab.

 

Feel free to add me on discord for any more questions if you want, iDzn#7311

Share this post


Link to post
Zummy   

Hi, I already asked this on youtube under the video but I found inCombat to be very inconsistent, it sometimes outputs false eventhough it's true. Have you encountered this issue or know a work-around?

Share this post


Link to post
iDzn   
18 minutes ago, Zummy said:

Hi, I already asked this on youtube under the video but I found inCombat to be very inconsistent, it sometimes outputs false eventhough it's true. Have you encountered this issue or know a work-around?

inCombat only returns true if the local players hp bar is visible.

Share this post


Link to post
Zummy   
2 minutes ago, iDzn said:

inCombat only returns true if the local players hp bar is visible.

Yes I know that, but it still occasionally returns false eventhough the hp bar is visible. Chances are I'm doing something wrong since I just started scripting.

Here is my code:

package scripts;

import org.powerbot.script.Condition;
import org.powerbot.script.Filter;
import org.powerbot.script.PollingScript;
import org.powerbot.script.Script;
import org.powerbot.script.rt4.ClientContext;
import org.powerbot.script.rt4.GroundItem;
import org.powerbot.script.rt4.Npc;

import java.util.concurrent.Callable;

@Script.Manifest(name = "ChickenKiller", description = "Automatic killer", properties = "author=Zummy; topic=999; client=4;")

public class ChickenKiller extends PollingScript<ClientContext> {

    final static int NPC_IDS[] = {2692, 2693, 2819, 2821, 2820};
    final static int PICKUP_IDS[] = {314};

    @Override
    public void start() {
        System.out.println("Script has started.");
    }

    @Override
    public void stop() {
        System.out.println("Script has stopped.");
    }

    @Override
    public void poll() {
        if (shouldRun()) {
            ctx.movement.running(true);
        } else if (notFighting()) {
            System.out.println("Combat = False");
            pickup();
            attack();
        }
    }

    public boolean notFighting() {
        return !ctx.players.local().inCombat();
    }

    public boolean shouldRun() {
        return !ctx.movement.running() && ctx.movement.energyLevel() > 20;
    }

    public void attack() {
        System.out.println("Trying to attack");
        final Npc npcToAttack = ctx.npcs.select().id(NPC_IDS).select(new Filter<Npc>() {

            @Override
            public boolean accept(Npc npc) {
                return !npc.inCombat();
            }
        }).nearest().poll();

        npcToAttack.interact("Attack");

        Condition.wait(new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
                return ctx.players.local().inCombat();
            }
        }, 250, 12);
    }

    public void pickup() {
        final int currentNumber = ctx.inventory.select().id(PICKUP_IDS).count(true);
        GroundItem ItemToPickup = ctx.groundItems.select().id(PICKUP_IDS).nearest().poll();
        ItemToPickup.interact("Take", "Feather");

        Condition.wait(new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
                return ctx.inventory.select().id(PICKUP_IDS).count(true) != currentNumber;
            }
        }, 250, 12);
    }
}

 

Share this post


Link to post
On 7/28/2018 at 11:09 AM, Zummy said:

Yes I know that, but it still occasionally returns false eventhough the hp bar is visible. Chances are I'm doing something wrong since I just started scripting.

 

 

inCombat is generally not as useful as we'd like it to be. However NPCs and Players will be interacting when they're attacking or talking or following or anything like that. To check for interacting you could do something like

 

ctx.npcs.select().select(n -> n.interacting.equals(ctx.players.local()).size > 0;

This will create a query of NPCs, then filter based on if any of them are interacting with you. If the size of that query is more than 0 it means someone is interacting (e.g. attacking) you.

Share this post


Link to post
On 8/4/2018 at 1:18 AM, ShowtimeScripts said:

 

inCombat is generally not as useful as we'd like it to be. However NPCs and Players will be interacting when they're attacking or talking or following or anything like that. To check for interacting you could do something like

 


ctx.npcs.select().select(n -> n.interacting.equals(ctx.players.local()).size > 0;

This will create a query of NPCs, then filter based on if any of them are interacting with you. If the size of that query is more than 0 it means someone is interacting (e.g. attacking) you.

"interacting" seems to throw an error for me, I'm probably not incorporating it correctly. Where/how should I go about adding this? 

Share this post


Link to post
iDzn   
1 minute ago, Jenna Talia said:

"interacting" seems to throw an error for me, I'm probably not incorporating it correctly. Where/how should I go about adding this? 

You should probably post your code.. Otherwise how do we know where your going wrong.

Share this post


Link to post
Chris   
10 minutes ago, Jenna Talia said:

"interacting" seems to throw an error for me, I'm probably not incorporating it correctly. Where/how should I go about adding this? 

you likely followed the video and your project is set to java 6, which doesn't include lambdas 

 

thus n is meaningless and .interacting is also meaningless

Share this post


Link to post
8 minutes ago, Chris said:

you likely followed the video and your project is set to java 6, which doesn't include lambdas 

 

thus n is meaningless and .interacting is also meaningless

I've changed it to java 8 because it wouldn't compile in java 6. Here's my code, the "public boolean hold()" is what I've been trying to tamper with

package scripts;

import org.powerbot.script.Condition;
import org.powerbot.script.Filter;
import org.powerbot.script.PollingScript;
import org.powerbot.script.Script;
import org.powerbot.script.rt4.ClientContext;
import org.powerbot.script.rt4.Item;
import org.powerbot.script.rt4.Npc;

import java.util.concurrent.Callable;

@Script.Manifest(name = "Goblin Killer", description = "Kills Goblins", properties = "author=me; topic=999; client=4;")

public class HelloWorld extends PollingScript<ClientContext> {

    final static int GOBLIN_IDS[] = { 3029, 3030, 3031, 3032, 3033, 3034, 3035 };
    final static int FOOD_ID[] = { 315 };

    @Override
    public void start() {
        System.out.println("Started");
    }

    @Override
    public void stop() {
        System.out.println("Stopped");
    }

    @Override
    public void poll() {

        if(hadFood()) {
            if(needsHeal()) {
                heal();
                if(hold());
            } else if(shouldAttack()) {
                attack();
            }
        }
    }

    public boolean needsHeal() {
        return ctx.combat.health() < 6;
    }

    public boolean shouldAttack() {
        return !ctx.players.local().inCombat();
    }

    public boolean hadFood() {
        return ctx.inventory.select().id(FOOD_ID).count() > 0;
    }

    public boolean hold() {
        return ctx.npcs.select().select(n -> n.interacting.equals(ctx.players.local()).size > 0);
    }

    public void attack() {
        final Npc goblinToAttack = ctx.npcs.select().id(GOBLIN_IDS).select(new Filter<Npc>() {

            @Override
            public boolean accept(Npc npc) {
                return !npc.inCombat();
            }
        }).nearest().poll();

        goblinToAttack.interact("Attack");

        Condition.wait(new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
                return ctx.players.local().inCombat();
            }
        }, 200, 20);
    }

    public void heal() {
        Item foodToEat = ctx.inventory.id(FOOD_ID).poll();
        foodToEat.interact("Eat");

        final int startingHealth = ctx.combat.health();

        Condition.wait(new Callable<Boolean>() {
            @Override
            public Boolean call() throws Exception {
                final int currentHealth = ctx.combat.health();
                return currentHealth != startingHealth;
            }
        }, 150, 20);

    }

}

 

Share this post


Link to post
Chris   
2 minutes ago, Jenna Talia said:

I've changed it to java 8 because it wouldn't compile in java 6. Here's my code, the "public boolean hold()" is what I've been trying to tamper with

 

interacting is a method not a field so you need interacting() not interacting.

Share this post


Link to post
Chris   
Just now, Jenna Talia said:

that causes "size" to not be able to be resolved

.equals isnt a filter, it returns a boolean

 

you cant have size and equals, 1 or the other

Share this post


Link to post
6 minutes ago, Chris said:

.equals isnt a filter, it returns a boolean

 

you cant have size and equals, 1 or the other

So I removed equals and size still can't be resolved, when I remove size it tells me '>' can't be applied to a boolean.

Sorry for all the beginner questions to this, just trying to get a grasp on it.

Share this post


Link to post
iDzn   
3 minutes ago, Jenna Talia said:

So I removed equals and size still can't be resolved, when I remove size it tells me '>' can't be applied to a boolean.

Sorry for all the beginner questions to this, just trying to get a grasp on it.

You're not closing the parenthesis on your second select so currently you have

ctx.npcs.select().select(n -> n.interacting().equals(ctx.players.local()).size
//if you count your closing brackets you'll notice that you've not finished off your .select(n->

So instead you want:

ctx.npcs.select().select(n -> n.interacting().equals(ctx.players.local())).size()>0
//Notice the extra bracket after .local()))

 

Share this post


Link to post

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.

Loading...