Yattas 4 Share Posted December 14, 2019 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 More sharing options...
Pseudo 178 Share Posted December 14, 2019 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 More sharing options...
Yattas 4 Author Share Posted December 14, 2019 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 More sharing options...
Yattas 4 Author Share Posted December 14, 2019 @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 More sharing options...
NovaGTX 106 Share Posted December 15, 2019 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. Semper Fi 1 Link to comment Share on other sites More sharing options...
Pseudo 178 Share Posted December 15, 2019 Because you're telling it to attack a rat if it isn't in combat, irrespective of whether loot is valid or not. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now