Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Goblin Killer help


    scape2code
     Share

    Recommended Posts

    New to this so if you have suggestions just going to practice a bit each day and have people critique my code so hopefully I learn something. I did some programming in college 4/5 years ago, all introductory classes, so I need to read up on it some. My eat method which I hoped would allow me to eat a trout if my hp percent was lower then 95 just as a test closest() returns null even tho I have trout in my inventory. I also never heard of a lambda today so if you could explain that better and also why keep the methods private instead of public I remember had something to do with data hiding. Also how does the paint method run when its not called and it also has a problem that sometimes it will attack a goblin that's not in area that I need to be in, I guess id have tochange that in the filter, and it runs off to attack it sometimes it does and then while being attacked by it I go and try to attack something else even tho im being attacked. 

    import org.dreambot.api.methods.filter.Filter;
    import org.dreambot.api.methods.interactive.GameObjects;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.NPC;
    
    import java.awt.*;
    @ScriptManifest(category = Category.MISC,name="goblin killer",description ="",author="scape2code",version=1.0)
    
    public class Main extends AbstractScript {
        private static final Area GOBLINAREA = new Area(3245,3232,3255,3239);
        private static final String GOBLIN ="Goblin";
        private static final Filter<NPC>GOBLINFILTER = npc -> npc != null && npc.getName().equals(GOBLIN) && !npc.isHealthBarVisible();
    
        public void onStart() {
            int state = 0; // was thinking about using
            int attackLevel = getSkills().getRealLevel(Skill.ATTACK);
            log("Attack Level: "+attackLevel);
        }
    
        @Override
        public int onLoop() {
            locationCheck();
            if(!getLocalPlayer().isInCombat())
            {
                killGoblin();
                if(getCombat().getHealthPercent() < 95){
                    eat();
                }
    
            }
            return 1000;
        }
        private void locationCheck(){
            if (!GOBLINAREA.contains(getLocalPlayer())) {
                getWalking().walk(GOBLINAREA.getRandomTile());
            }
        }
        private void killGoblin(){
            NPC goblin = getNpcs().closest(GOBLINFILTER);
            goblin.interact("Attack");
    
    
    
        }
        private void eat(){
            if(getInventory().contains("Trout")){
                log("Should be eating");
                GameObject food = getGameObjects().closest("Trout");
                log(""+food);
                food.interact("Eat");
            }
    
        }
    
        @Override
        public void onPaint(Graphics graphics) {
            super.onPaint(graphics);
            int defenceLevel = getSkills().getRealLevel(Skill.DEFENCE);
            int healthPercent = getCombat().getHealthPercent();
            graphics.drawString("Current defence level"+defenceLevel,20,40);
            graphics.drawString("Current Health Percentage" + healthPercent,20,55);
        }
    }
    
    Link to comment
    Share on other sites

    Well first off, items in the inventory aren't GameObjects. You would do:

    private void eat(){
    	if(getInventory().contains("Trout")){
    		getInventory().get("Trout").interact("Eat");
    	}
    }

    Which would get the Item from the inventory and interact with it.

    GameObjects are things like trees or doors.

    Making the method private only allows the method to be called inside the class it is in. For a one file script, you really don't need to worry about that. You can just put void eat(){

    The onPaint method is called automatically behind the scenes.

    Lambdas are pretty hard to explain, this should give you a better idea. https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html

    Edited by Milasoft
    Link to comment
    Share on other sites

    54 minutes ago, scape2code said:

    thx for the help is there a list of all the gameobjects anywhere?

    Just anything like built into the map like I said trees and doors, a range, a furnace, a ladder, etc.

    Link to comment
    Share on other sites

    12 hours ago, scape2code said:

    thx for the help is there a list of all the gameobjects anywhere?

    You can find nearby gameobjects by going to "tools->debugging->game debugger->game objects" in the client.

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.