737 Posted June 2 Share Posted June 2 (edited) This is the second script I wrote for OSBot. This script is incomplete from the end goal but will operate without issues unsupervised. I've been on a break from script writing but will be releasing scripts I have already made over some period of time. Perhaps I will start scripting again if I find my own use for these scripts, or others find use for them. 737 Chickens Features Attacks Chickens at Lumbridge Chicken farm Loots Chicken your character has killed Buries bones Cooks Chickens at cooking pot Goes "AFK" at certain intervals Missing Features Configuration - cannot skip actions like bury, cooking More locationsXp tracking doesn't do range or mage, however, the script should still perform Source Spoiler package Chickens; import org.osbot.rs07.api.filter.Filter; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.api.ui.Message; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; import java.awt.*; import java.util.ArrayList; import java.util.List; @ScriptManifest( author = "737", info = "Kills Chickens, buries bones, cooks chicken", logo = "", name = "737 Chickens", version = 1 ) public class Chickens extends Script { private final Area AREA_COOK = new Area(3226, 3290, 3228, 3291); private final Area AREA_KILL = new Area(3225, 3296, 3236, 3300); private final String NPC_CHICKEN = "Chicken"; private final String ITEM_FEATHER = "Feather"; private final String ITEM_BONE = "Bones"; private final String ITEM_CHICKEN = "Cooked chicken"; private final String ITEM_RAW_CHICKEN = "Raw chicken"; private final String ITEM_BURNT_CHICKEN = "Burnt chicken"; private final String ITEM_EGG = "Egg"; private final String ACTION_ATTACK = "Attack"; private final String ACTION_TAKE = "Take"; private final String ACTION_BURY = "Bury"; private final String ACTION_USE = "Use"; private final String OBJECT_COOKING_POT = "Cooking pot"; private final String MESSAGE_BONE_BURIED = "You bury the bones."; int baseSleepMs = 50; int afkChance = 0; boolean manageInventory = false; boolean buryBones = false; boolean pickUpFeathers = false; boolean cookChickens = false; private long startTime; private String status = "loading..."; Position killedChickenPosition; List<String> groundItemsToLoot = new ArrayList<>(); Filter<NPC> chickenFilter; Filter<GroundItem> lootFilter; int enableRunAt = 50; @Override public void onStart() { startTime = System.currentTimeMillis(); enableRunAt = random(40, 75); manageInventory = false; baseSleepMs = random(50, 75); buryBones = true; pickUpFeathers = true; cookChickens = true; afkChance = random(5,30); if (buryBones) { groundItemsToLoot.add(ITEM_BONE); } if (pickUpFeathers) { groundItemsToLoot.add(ITEM_FEATHER); } if (cookChickens) { groundItemsToLoot.add(ITEM_RAW_CHICKEN); } groundItemsToLoot.add("Bronze dart"); groundItemsToLoot.add("Iron dart"); chickenFilter = npc -> npc.getName().equals(NPC_CHICKEN) && !npc.isUnderAttack() && npc.isAttackable() && AREA_KILL.contains(npc.getPosition()) && npc.isVisible(); lootFilter = groundItem -> groundItem.getPosition().equals(killedChickenPosition) && groundItemsToLoot.contains(groundItem.getName()); for (final Skill skill : new Skill[] { Skill.ATTACK, Skill.STRENGTH, Skill.DEFENCE, Skill.HITPOINTS, Skill.PRAYER, Skill.COOKING }) { getExperienceTracker().start(skill); } } @Override public int onLoop() throws InterruptedException { rSleep(); afkOpportunity(); if (dialogues.isPendingContinuation()) { dialogues.clickContinue(); sleep(1000); } if (getSettings().getRunEnergy() > enableRunAt && !getSettings().isRunning()) { getSettings().setRunning(true); } if (getInventory().isFull()) { killedChickenPosition = null; manageInventory = true; } if (manageInventory) { if (getInventory().contains(ITEM_BONE)) { status = "Burying Bones"; buryBone(); return 0; } else if (getInventory().contains(ITEM_RAW_CHICKEN)) { status = "Cooking Chicken"; cookChicken(); return 0; } else if (getInventory().contains(ITEM_CHICKEN, ITEM_BURNT_CHICKEN)) { status = "Cleaning out Inventory"; getInventory().dropAll(ITEM_CHICKEN, ITEM_BURNT_CHICKEN, ITEM_EGG); return 0; } manageInventory = (getInventory().contains(ITEM_RAW_CHICKEN, ITEM_BONE, ITEM_CHICKEN, ITEM_BURNT_CHICKEN)); return 0; } List<GroundItem> loot = getGroundItems().filter(lootFilter); if (killedChickenPosition != null && AREA_KILL.contains(killedChickenPosition) && !loot.isEmpty()) { lootItem(loot.get(0)); return 0; } killChicken(); return 0; } private void buryBone() throws InterruptedException { long boneCount = getInventory().getAmount(ITEM_BONE); getInventory().interact(ACTION_BURY, ITEM_BONE); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return boneCount > getInventory().getAmount(ITEM_BONE); } }.sleep(); } public void afkOpportunity() throws InterruptedException { if(afkChance > random(0,1000)){ status = "afk"; getMouse().moveOutsideScreen(); sleep(random(5000,90000)); } } public void cookChicken() throws InterruptedException { if (AREA_COOK.contains(myPosition())) { if (getInventory().isItemSelected()) { RS2Object cookingPot = getObjects().closest(OBJECT_COOKING_POT); if(cookingPot.interact()){ new ConditionalSleep(random(4000,10000)) { @Override public boolean condition() throws InterruptedException { return getDialogues().inDialogue(); } }.sleep(); return; } } if (dialogues.inDialogue()) { getKeyboard().typeKey(' '); sleep(1000); int cookingLevel = getSkills().getStatic(Skill.COOKING); new ConditionalSleep(25000) { @Override public boolean condition() throws InterruptedException { return !getInventory().contains(ITEM_RAW_CHICKEN) || cookingLevel != getSkills().getStatic(Skill.COOKING); } }.sleep(); return; } getInventory().interact(ACTION_USE, ITEM_RAW_CHICKEN); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getInventory().isItemSelected() && !myPlayer().isMoving(); } }.sleep(); return; } else { walking.webWalk(AREA_COOK); } } private void lootItem(GroundItem item) throws InterruptedException { if (AREA_KILL.contains(myPosition())) { if (item != null && item.isVisible() && item.hasAction(ACTION_TAKE)) { item.interact(ACTION_TAKE); new ConditionalSleep(random(1500, 3000)) { @Override public boolean condition() throws InterruptedException { return !item.exists(); } }.sleep(); } else { getCamera().toEntity(item); } } else { walking.webWalk(AREA_KILL); } } private void killChicken() throws InterruptedException { status = "Killing Chickens"; if (!AREA_KILL.contains(myPosition())) { walking.webWalk(AREA_KILL.getRandomPosition()); return; } NPC chicken = getNpcs().closest(chickenFilter); if (chicken != null && chicken.isVisible()) { logger.info("Chicken found " + chicken.getName()); if(chicken.interact(ACTION_ATTACK)){ for (int i = 0; i < 45; i++) //conditional rest... but we need to keep an eye on our chicken { if (!chicken.exists()) { break; } killedChickenPosition = chicken.getPosition(); sleep(random(300,1100)); } } } if(!chicken.isVisible()) { getCamera().toEntity(chicken); } } @Override public void onMessage(Message message) { } @Override public void onPaint(Graphics2D g) { //paint stuff - shout out https://osbot.org/forum/topic/87697-explvs-dank-paint-tutorial/ Color background = new Color(0f, 0f, 0f, 0.2f); g.setColor(background); g.fillRect(5, 20, 300, 210); Color fontColor = new Color(1f, 1f, 1f, 0.8f); g.setColor(fontColor); Font fontTitle = new Font("Consolas", Font.BOLD, 16); Font font = new Font("Consolas", Font.PLAIN, 16); g.setFont(fontTitle); g.drawString("737 Chicken Killer v1.0", 20, 40); g.setFont(font); g.drawString("Status: " + status, 20, 60); g.drawString("Time Elapsed: " + formatTime(System.currentTimeMillis() - startTime), 20, 80); long attackXP = getExperienceTracker().getGainedXP(Skill.ATTACK); long strengthXP = getExperienceTracker().getGainedXP(Skill.STRENGTH); long defenceXP = getExperienceTracker().getGainedXP(Skill.DEFENCE); long hitPointsXP = getExperienceTracker().getGainedXP(Skill.HITPOINTS); long prayerXP = getExperienceTracker().getGainedXP(Skill.PRAYER); long cookingXP = getExperienceTracker().getGainedXP(Skill.COOKING); long attackXPPerHour = getExperienceTracker().getGainedXPPerHour(Skill.ATTACK); long strengthXPPerHour = getExperienceTracker().getGainedXPPerHour(Skill.STRENGTH); long defenceXPPerHour = getExperienceTracker().getGainedXPPerHour(Skill.DEFENCE); long hitPointsXPPerHour = getExperienceTracker().getGainedXPPerHour(Skill.HITPOINTS); long prayerXPPerHour = getExperienceTracker().getGainedXPPerHour(Skill.PRAYER); long cookingXPPerHour = getExperienceTracker().getGainedXPPerHour(Skill.COOKING); int nextPaintYCoord = 100; if (attackXP > 0) { g.drawString("Atk XP Gained: " + formatValue(attackXP) + " Hourly: " + formatValue(attackXPPerHour), 20, nextPaintYCoord); nextPaintYCoord += 20; } if (strengthXP > 0) { g.drawString("Str XP Gained: " + formatValue(strengthXP) + " Hourly: " + formatValue(strengthXPPerHour), 20, nextPaintYCoord); nextPaintYCoord += 20; } if (defenceXP > 0) { g.drawString("Def XP Gained: " + formatValue(defenceXP) + " Hourly: " + formatValue(defenceXPPerHour), 20, nextPaintYCoord); nextPaintYCoord += 20; } if (hitPointsXP > 0) { g.drawString("Hit XP Gained: " + formatValue(hitPointsXP) + " Hourly: " + formatValue(hitPointsXPPerHour), 20, nextPaintYCoord); nextPaintYCoord += 20; } if (prayerXP > 0) { g.drawString("Pray XP Gained: " + formatValue(prayerXP) + " Hourly: " + formatValue(prayerXPPerHour), 20, nextPaintYCoord); nextPaintYCoord += 20; } if (cookingXP > 0) { g.drawString("Cook XP Gained: " + formatValue(cookingXP) + " Hourly: " + formatValue(cookingXPPerHour), 20, nextPaintYCoord); } Point mP = getMouse().getPosition(); g.setColor(Color.red); g.drawLine(mP.x - 5, mP.y + 5, mP.x + 5, mP.y - 5); g.drawLine(mP.x + 5, mP.y + 5, mP.x - 5, mP.y - 5); } public void rSleep() throws InterruptedException { sleep(baseSleepMs + random(0, 50)); } public void rSleep(int min, int max) throws InterruptedException { sleep(random(min, max)); } public final String formatTime(final long ms) { long s = ms / 1000, m = s / 60, h = m / 60; s %= 60; m %= 60; h %= 24; return String.format("%02d:%02d:%02d", h, m, s); } public final String formatValue(final long l) { return (l > 1_000_000) ? String.format("%.2fm", ((double) l / 1_000_000)) : (l > 1000) ? String.format("%.1fk", ((double) l / 1000)) : l + ""; } } I can post Jar if people desire it, it doesn't look the forum has an option to upload it unless I'm missing something Edited June 2 by 737 1 1 Quote Link to comment Share on other sites More sharing options...
TheCongregation Posted June 3 Share Posted June 3 Nice simple script, integrating combat and looting and cooking! Quote Link to comment Share on other sites More sharing options...
yfoo Posted June 3 Share Posted June 3 Very useful for new accounts, all gain, negligible impact in case of ban. I might ctrl c/v this for f2p fun later. Quote Link to comment Share on other sites More sharing options...
BeeZZy Posted August 16 Share Posted August 16 Im new to scripting, how do i use this with osbot? Quote Link to comment Share on other sites More sharing options...