booya Posted April 13 Share Posted April 13 Doing a quest script, currently need to kill a rat for meat to burn it. i just want it to sleep until it sees meat on floor then pick it. but currently, it is returning true on everything ive tried for when on combat in rat, it seems to be if the rats far away..... I have tried every combo you can think of but it skips and comes back to "AT RATS" ive tried || and &&................. anoyying. Quote if (!players.myPlayer().isMoving() && RATS.contains(myPosition())) { log("AT RATS"); sleep(random(500, 1250)); if (!players.myPlayer().isAnimating() && !players.myPlayer().isMoving() && npcs.closest("Giant rat") != null && RATS.contains(myPosition())) { npcs.closest("Giant rat").interact("Attack"); log("ATTACKING RAT"); sleep(random(500,1200)); mouse.moveOutsideScreen(); log("MOVE MOUSE OF SCREEN & SLEEPING"); new ConditionalSleep(120000, 500) { @Override public boolean condition() { log("INCOMBAT3"); return !getPlayers().myPlayer().isMoving() || !getPlayers().myPlayer().isInteracting(getNpcs().closest("Giant Rat")) || !getCombat().isFighting(); } }.sleep(); } if (groundItems.closest("Raw rat meat") != null) { log("RAW MEAT IS ON FLOOR"); groundItems.closestThatContains("Raw rat meat").interact("Take"); sleep(random(200, 800)); new ConditionalSleep(6000) { @Override public boolean condition() throws InterruptedException { return inventory.contains("Raw rat meat"); } }.sleep(); } if (getInventory().contains("Raw rat meat")) { sleep(random(500, 1250)); Onion(); } else { sleep(random(200, 800)); Meat(); Quote Link to comment Share on other sites More sharing options...
Czar Posted April 14 Share Posted April 14 Need to put the block of code checking for ground items, just below "AT RATS" so it takes priority over every action Quote Link to comment Share on other sites More sharing options...
yfoo Posted April 19 Share Posted April 19 When a npc is killed, its loot doesn't appear immediately. Death animation plays first. Change if (groundItems.closest("Raw rat meat") != null) { To a ConditionalSleep, sleep until you see your raw meat drop. Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted May 22 Share Posted May 22 On 4/13/2024 at 11:47 AM, booya said: Doing a quest script, currently need to kill a rat for meat to burn it. i just want it to sleep until it sees meat on floor then pick it. but currently, it is returning true on everything ive tried for when on combat in rat, it seems to be if the rats far away..... I have tried every combo you can think of but it skips and comes back to "AT RATS" ive tried || and &&................. anoyying. Here's a quick example on how you could refactor your code to make it a little more readable and predicatable. First declare an enum class that specifies the current state that your bot should be in. Spoiler public enum BotState { WALK_TO_FIGHT_AREA, PICKUP_LOOT, ATTACK_TARGET, IDLE } Then create a method to determine the state that the bot should be in. Spoiler public BotState calculateBotState() { if (getNpcs().closest("Giant rat") == null && myPlayer().getInteracting() == null) return BotState.WALK_TO_FIGHT_AREA; else if (getGroundItems().closest("Raw rat meat") != null && myPlayer().getInteracting() == null && !getInventory().isFull()) return BotState.PICKUP_LOOT; else if (getNpcs().closest("Giant rat") != null && myPlayer().getInteracting() == null) return BotState.ATTACK_TARGET; return BotState.IDLE; } Then create methods for each of those states. Spoiler public boolean walkToFightArea(Area fightArea) { return getWalking().webWalk(fightArea); } public boolean pickupLoot() { GroundItem loot = getGroundItems().closest(item -> item.getName().equals("Raw rat meat")); int oldEmptyInventorySlotCount = getInventory().getEmptySlots(); if (loot != null && loot.interact("Take")) { ConditionalSleep2.sleep(10000, () -> getInventory().getEmptySlots() < oldEmptyInventorySlotCount || !loot.exists()); return getInventory().getEmptySlots() < oldEmptyInventorySlotCount; } return false; } public boolean attackTarget() { NPC target = getNpcs().closest(npc -> npc.getName().equals("Giant rat") && npc.isAttackable()); if (target != null && target.interact("Attack")) { ConditionalSleep2.sleep(10000, () -> myPlayer().getInteracting() != null); return myPlayer().getInteracting() == target; } return false; } public void idle() { getMouse().moveOutsideScreen(); ConditionalSleep2.sleep(15000, () -> myPlayer().getInteracting() == null); } Once you have all of that completed, create a variable that will hold the current bot state. Spoiler private BotState botState; Lastly, you just have to setup the main loop of your script. First set that variable using the calculateBotState method. Spoiler @Override public int onLoop() throws InterruptedException { botState = calculateBotState(); return random(300, 2500); } Then implement a switch statement that will call the methods when the bot is in its various states. Spoiler @Override public int onLoop() throws InterruptedException { botState = calculateBotState(); switch (botState) { case WALK_TO_FIGHT_AREA: walkToFightArea(ratsArea); break; case PICKUP_LOOT: pickupLoot(); break; case ATTACK_TARGET: attackTarget(); break; case IDLE: idle(); break; } return random(300, 2500); } Hopefully this helps you out in your scripting adventures! Quote Link to comment Share on other sites More sharing options...