-
Finished my first script and was looking for a little feedback
thanks for that. ill be sure to use it next time good! do let me know how it gets on. I ran it for about 90 mins earlier with no problems so lemme know if something does come up. thanks man that does make sense. ill make sure I get the types right next time thanks a lot man!
-
Finished my first script and was looking for a little feedback
hi guys, I made a chicken killer to try and familiarise myself with the API and learn how to do stuff and I think its just about done. It just ran for 2 hours no problem so im wanting to move on and make something else now. before I do I was wondering if anyone could have a really quick look at the code to see if theres anything I should do differently next time import org.osbot.rs07.api.filter.Filter; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; import java.util.concurrent.TimeUnit; @ScriptManifest(name = "EmpiresChickenKiller", author = "Empires", version = 1.0, info = "Basic Chicken Killer for Falador Farm", logo = "") public class EmpiresChickenKiller extends Script { private long timeBegan; private long timeRan; private int beginningXp; private int currentXp; private int xpGained; private int currentLevel; private int beginningLevel; final Area CHICKEN_COOP = new Area(3014,3298,3020,3282); @Override public void onStart() { log("Welcome to EmpiresChickenKiller."); log("Lets get started..."); timeBegan = System.currentTimeMillis(); beginningXp = skills.getExperience(Skill.STRENGTH); beginningLevel = skills.getStatic(Skill.STRENGTH); } private enum State { ATTACK, WAIT }; private State getState(){ if(myPlayer().isMoving() || combat.isFighting() || myPlayer().isUnderAttack()) return State.WAIT; else return State.ATTACK; } @SuppressWarnings("unchecked") private NPC getTarget(){ NPC targetChicken = npcs.closest(new Filter<NPC>(){ public boolean match(NPC theChicken){ return theChicken != null && theChicken.getName().equals("Chicken") && theChicken.isAttackable() && (theChicken.getHealth() != 0) && CHICKEN_COOP.contains(theChicken); } }); return targetChicken; } @Override public int onLoop() throws InterruptedException { switch(getState()) { case ATTACK: NPC chickenToKill = getTarget(); if(!chickenToKill.isOnScreen()) camera.toEntity(chickenToKill); chickenToKill.interact("Attack"); sleep(random(600,1000)); if(chickenToKill.isInteracting(myPlayer())) sleep(random(1200,2100)); else break; case WAIT: sleep(random(400,600)); break; } return 100; } @Override public void onExit() { log("Thanks for using my script!"); } @Override public void onPaint(Graphics2D g) { timeRan = System.currentTimeMillis() - this.timeBegan; g.drawString("Runtime: " + ft(timeRan), 561,221); currentXp = skills.getExperience(Skill.STRENGTH); xpGained = currentXp - beginningXp; g.drawString("XP Gained: " + xpGained, 561,246); currentLevel = skills.getStatic(Skill.STRENGTH); g.drawString("Lvl Started: " + beginningLevel, 561,271); g.drawString("Current Lvl: " + currentLevel, 561,296); g.drawString("Lvls Gained: " + (beginningLevel - currentLevel), 561,321); } private String ft(long duration) { String res = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS .toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(duration)); if (days == 0) { res = (hours + ":" + minutes + ":" + seconds); } else { res = (days + ":" + hours + ":" + minutes + ":" + seconds); } return res; } } I basically copy/pasted the paint stuff from a different tutorial btw, but I understand it
-
Basic Scripting, Classes, and Good Code
Thanks a lot for this, really easy to understand and helped me out )
-
Basic Scripting, Classes, and Good Code
Lol its a bit of a habit its how they have us explain everything in my CS course, ill tone it down next time :L
-
Trouble Burying Bones
chill. well it is my first time writing one so its obviously gonna be a bit meh, but I did just ask you why it sucks so if you can list stuff can you let me know what about it that makes it bad?
-
Trouble Burying Bones
omg it works hahaha thanks so much ) been stuck for literally like 2 hours -_-
-
Trouble Burying Bones
Thanks for reply, would you be able to hint me on how to do that? I tried using playerInventory.initializeModule() at the start of my onLoop() and it compiled but still crashed. Am I doing that right? sorry for basic bitch question, first time scripting ://
- Trouble Burying Bones
-
Trouble Burying Bones
I'm trying to make a basic chicken killer that collects feathers and buries bones. I had it attacking and collecting feathers fine but as soon as I added the bury option/case it breaks completely as it just stands there doing nothing. On top of this the client is also unresponsive forcing me to use task manager to close down the bot. Any ideas? Thanks import org.osbot.rs07.api.Inventory; import org.osbot.rs07.api.model.Character; import org.osbot.rs07.api.model.GroundItem; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(name = "EmpiresChickenKiller", author = "Empires", version = 1.0, info = "", logo = "") public class EmpiresChickenKiller extends Script { @Override public void onStart() { log("Welcome to EmpiresChickenKiller."); log("Lets get started..."); } private enum State { ATTACK, WAIT, BURY }; private Inventory playerInventory; private State getState(){ if(myPlayer().isMoving() || combat.isFighting() || myPlayer().isUnderAttack()) return State.WAIT; else if(playerInventory.getEmptySlotCount() > 0) return State.ATTACK; else return State.BURY; } @Override public int onLoop() throws InterruptedException { switch(getState()) { case ATTACK: GroundItem featherCollect = groundItems.closest("Feather"); if(featherCollect != null) featherCollect.interact("Take"); sleep(random(500,700)); GroundItem bonesCollect = groundItems.closest("Bones"); if(bonesCollect != null) bonesCollect.interact("Take"); sleep(random(400,600)); NPC targetChicken = npcs.closest("Chicken"); if(!targetChicken.isOnScreen()) camera.toEntity(targetChicken); if(targetChicken != null && !targetChicken.isUnderAttack() && (targetChicken.getHealth() != 0)) targetChicken.interact("Attack"); sleep(random(500,800)); break; case WAIT: sleep(random(300,500)); break; case BURY: playerInventory.dropAllExcept("Feathers", "Bones"); while(playerInventory.contains("Bones")) playerInventory.interact("Bury", "Bones"); sleep(random(200,310)); break; } return 100; } @Override public void onExit() { log("Thanks for using my script!"); } @Override public void onPaint(Graphics2D g) { //This is where you will put your code for paint(s) } }
-
Basic Scripting, Classes, and Good Code
Hi guys, I'm new to scripting, and since this is my first time programming without guidance I had a quick question to try and get me off to a good start. Lets say I had a basic chicken killer script that kills chickens in either Lumbridge or Falador depending on what the user selects in the GUI. How would I structure this program into classes to minimise the redundant code regarding the methods between the two locations would be slightly different. Would I be able to build a class hierarchy based around the two locations and then inherit from the class that matches the users needs based on the location selected? Basically I'm just wanting to know what functionality should I be grouping together in my classes to allow minimum processing time and redundant code, and if I'm able to inherit from specific classes based on the GUI input (unless this isnt necessary/possible or theres a better way). Sorry for the noob question, I just want to be off to a good start, tyty:)