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
  • How to make loot all items of current enemy after they die?


    Yattas

    Recommended Posts

    Hello,

    I'm currently trying to make a very basic killer/looter bot that kills giant rats in lumby and loots everything they have.  I'm struggling greatly with getting a looting system to work.  The current code that I have is...

    package RatKiller;
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.container.impl.equipment.EquipmentSlot;
    import org.dreambot.api.methods.filter.Filter;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.map.Tile;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.NPC;
    import org.dreambot.api.wrappers.items.GroundItem;
    import org.dreambot.api.script.Category;
    
    @ScriptManifest(author = "You", name = "Rat Killer", version = 1.0, description = "Rat Killer", category = Category.COMBAT)
    public class RatKiller extends AbstractScript {
    
    	private final Area ratArea = new Area(3202, 3189, 3228, 3169);
    	public static final String RAT = "Giant rat";
    
    	public static final Filter<NPC> RAT_FILTER = new Filter<NPC>() {
    		@Override
    		public boolean match(NPC npc) {
    			if (npc == null) {
    				return false;
    			}
    
    			if (npc.getName().equals(RAT) && !npc.isHealthBarVisible()) {
    				return true;
    			} else {
    				return false;
    			}
    		}
    	};
    
    	@Override
    	public int onLoop() {
    		GroundItem bones = getGroundItems().closest("Bones");
    		NPC rat = getNpcs().closest(RAT_FILTER);
    		Tile lootTile;
    
    
    		if (getLocalPlayer().isInCombat()) {
    			lootTile = rat.getTile();
    			if (!getLocalPlayer().isInCombat()) {
    				GroundItem[] groundItems = getGroundItems().getGroundItems(lootTile);
    				
    				for (GroundItem curItem : groundItems) {
    					curItem.interact("Take");
    				}
    			}
    		} 
    		else if (ratArea.contains(getLocalPlayer())) {
    			if (!getLocalPlayer().isInCombat()) {
    				if (rat != null) {
    					rat.interact("Attack");
    				}
    			}
    		} else {
    			getWalking().walk(ratArea.getRandomTile());
    		}
    
    		return Calculations.random(500, 600);
    	}

     

    Link to comment
    Share on other sites

    Looks to me like your loot tile is being reinitalized every loop cycle, so if you're not in combat then it's being set to null. Declare the tile outside your loop, see if that works. 

    Link to comment
    Share on other sites

    That did work, however, it's simply going right to attacking another rat instead of picking up its items.  Do you happen to know where i'd place the looting logic?

    Link to comment
    Share on other sites

    @Pseudo 

    That did work, however, it's simply going right to attacking another rat instead of picking up its items.  Do you happen to know where i'd place the looting logic?

     
    Link to comment
    Share on other sites

    I would suggest you look into proper structure of a script rather than using a bunch of nested if statements. This is a common mistake for beginners. For someone who isn't as well versed in scripting structure I would recommend you use a State structure rather than Nodes which is more complicated.
    Here's an excerpt i've posted before that should help you:

    On 2/25/2019 at 2:38 PM, NovaGTX said:

    Your overall layout could be improved by using an enum for the state you want to execute. I could get into nodes, this is probably out of scope for you currently, but I digress.

    Using enums for states is a less complicated and more entry-level method to sectioning your script rather than have it loop through conditionals in the onLoop each time.

    Declare your state:

    
    Private State state;


    Declare the enums:
     

    
    enum State {
    		WALKING, TELEPORT
    	}

    Next you need to define them using a function:
     

    
    private State getState() {
    	if(!getLocalPlayer().isAnimating() && checkQP == 69){
    		return State.TELEPORT;
    	} else if(!getLocalPlayer().getTile().equals(lumb)){ //You really should have a verification for teleporting, but for simplicity im omitting that
    		return State.WALK;
    	} else {
    		return State.SLEEP;
    	}
    }

     

    Then within your onloop you can use a Switch statement to check your state.

    
    public int onLoop() {
    state = getState(); //this is to avoid issues with calling the getState() function directly, can cause lag.
    
    switch(state){
    
    	case TELEPORT:
    		//teleport here
    		break;
    
    	case WALK:
    		//walk here
    		break;
    }
    return 100;
    }



    Hopefully, this quick and dirty example can give you some insight that you can improve upon.

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

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