Smokeyjay 1 Share Posted November 12, 2018 What's up guys I'm fairly new to scripting bots for RS. I'm currently a CSC student at UNC Charlotte and I just started getting deep into java this semester. I'm trying to figure out a way to paint the number of logs my bot has collected and paste it in the client. I have xp tracker...etc, but I can't find a way to count the logs and return the value to use in the onPaint() method. Here's my code....any help would be great. Thanks @ScriptManifest(category = Category.WOODCUTTING, name = "Basic WoodCutter", version = 1.01, author = "Luke") public class Main extends AbstractScript implements PaintListener { Area bankArea = new Area(3092, 3240, 3097, 3246, 0); Area treeArea = new Area(3086, 3262, 3073, 3277, 0); Font font = new Font("Verdana", Font.BOLD, 14); private static final Tile BANK_TILE = new Tile(3092, 3245); private static final Tile TREE_TILE = new Tile(3083, 3270); private static final long startTime = System.currentTimeMillis(); private int startLvl; private int xp; public void onStart() { startLvl = getSkillTracker().getGainedLevels(Skill.WOODCUTTING); xp = (int)getSkillTracker().getGainedExperience(Skill.WOODCUTTING); } public int onLoop() { GameObject tree = getGameObjects().closest(gameObject -> gameObject != null && gameObject.getName().equals("Tree")); if (!getInventory().isFull()) { if (getLocalPlayer().isAnimating()) { // do nothing } else if (treeArea.contains(getLocalPlayer()) && !getInventory().isFull()) { tree.interact("Chop down"); int countLog = getInventory().count("Logs"); sleepUntil(() -> getInventory().count("Logs") > countLog, 8000); } else if (TREE_TILE.distance() > 10){ getWalking().walk(TREE_TILE); } else { } } else { if(bankArea.contains(getLocalPlayer())) { getBank().open(); getBank().depositAllExcept("Bronze axe"); } else { getWalking().walk(BANK_TILE); } } return 600; } public void onPaint(Graphics g) { long timeRan = System.currentTimeMillis() - startTime; int seconds = (int) (timeRan / 1000) % 60 ; int minutes = (int) ((timeRan / (1000*60)) % 60); int hours = (int) ((timeRan / (1000*60*60)) % 24); g.setFont(font); g.drawString("Runtime: " + hours + ":" + minutes + ":" + seconds, 300, 370); g.drawString("Current lvl: " + getSkillTracker().getGainedLevels(Skill.WOODCUTTING) + "(+" + (getSkillTracker().getGainedLevels(Skill.WOODCUTTING) - startLvl) + ")", 300, 390); g.drawString("XP Gained: " + ((getSkillTracker().getGainedExperience(Skill.WOODCUTTING) - xp)) , 300, 410); g.drawString("XP TNL: " + getSkills().getExperienceToLevel(Skill.WOODCUTTING), 300, 430); } public void onExit() { } } Link to comment Share on other sites More sharing options...
Nuclear Nezz 2051 Share Posted November 12, 2018 A few things. 1. You're using hte wrong skill tracker method in your onStart, you should be using getSkills().getRealLevel, you should also check if you're logged in before doing anything with XP as that is not set until you log in at least once. 2. For number of logs collected, one thing you can do is just take gainedExperience/logExperience where logExperience is the experience you gain per log cut on that tree (you can find it in the rs wiki) 3. You should try to rethink your login in your onLoop a bit, you're grabbing the tree every single loop when you don't have to. eg: if you're animating, (unless you're picky) you don't have to grab the tree, because you're already chopping it. (but sometimes the tree can disappear and you'll still animate for a few seconds, hence: picky) or if you're banking/dropping inventory, you definitely don't have to grab the nearest tree. Grabbing it every time is just a little inefficient, is all. I always try to break my scripts down into simple 1 step iterations, and base my logic on each step, using only the calls needed to determine the step it has to take, and the calls needed to process that step. Just my two cents. Link to comment Share on other sites More sharing options...
Smokeyjay 1 Author Share Posted November 12, 2018 10 minutes ago, Nuclear Nezz said: A few things. 1. You're using hte wrong skill tracker method in your onStart, you should be using getSkills().getRealLevel, you should also check if you're logged in before doing anything with XP as that is not set until you log in at least once. 2. For number of logs collected, one thing you can do is just take gainedExperience/logExperience where logExperience is the experience you gain per log cut on that tree (you can find it in the rs wiki) 3. You should try to rethink your login in your onLoop a bit, you're grabbing the tree every single loop when you don't have to. eg: if you're animating, (unless you're picky) you don't have to grab the tree, because you're already chopping it. (but sometimes the tree can disappear and you'll still animate for a few seconds, hence: picky) or if you're banking/dropping inventory, you definitely don't have to grab the nearest tree. Grabbing it every time is just a little inefficient, is all. I always try to break my scripts down into simple 1 step iterations, and base my logic on each step, using only the calls needed to determine the step it has to take, and the calls needed to process that step. Just my two cents. Could you give me an example (using my code if you can) of what you mean by rethinking my login in my loop. I'm just a little confused by what you mean . But, thanks for the other input I'm gonna take a look at it rn. Link to comment Share on other sites More sharing options...
Pseudo 179 Share Posted November 12, 2018 34 minutes ago, Smokeyjay said: Could you give me an example (using my code if you can) of what you mean by rethinking my login in my loop. I'm just a little confused by what you mean . But, thanks for the other input I'm gonna take a look at it rn. I'd wager Nezz probably meant to say logic, and login is a typo there. Link to comment Share on other sites More sharing options...
Smokeyjay 1 Author Share Posted November 12, 2018 2 minutes ago, Pseudo said: I'd wager Nezz probably meant to say logic, and login is a typo there. Haha I think so too but if he could id like to see an example of a good loop! Link to comment Share on other sites More sharing options...
Nuclear Nezz 2051 Share Posted November 14, 2018 On 11/12/2018 at 10:57 AM, Pseudo said: I'd wager Nezz probably meant to say logic, and login is a typo there. rip yeah typo xd I'll give you some quick pseudo code, the rest you'll have to figure out on your own though. onloop{ if(animating){return 600;} if(inventory full){drop all, return 600;} tree = getClosest("tree"); if(tree == null){wait or walk somewhere else idk, return 600;} if(tree.distance > 5){walk tree, return 600;} tree.interact("chop") } So in this case, while you're animating you're not grabbing the tree while you're dropping, you're not grabbing the tree it's only when you *need* the tree that you grab the tree. It saves on a small amount of cpu usage. Link to comment Share on other sites More sharing options...
Pseudo 179 Share Posted November 15, 2018 23 hours ago, Nuclear Nezz said: rip yeah typo xd I'll give you some quick pseudo code, the rest you'll have to figure out on your own though. pseudo code Link to comment Share on other sites More sharing options...
NovaGTX 106 Share Posted November 16, 2018 13 hours ago, Pseudo said: pseudo code Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.