isystem32 0 Share Posted July 28, 2021 (edited) Hi I'm working on my first script. It's a basic willow power cutter. I can't seem to get a functional timer (Hours:Minutes:Seconds) running on the paint. Can someone give me any tips or point me to the right direction. Thanks! Source code below: import org.dreambot.api.methods.skills.Skill; import org.dreambot.api.methods.skills.Skills; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.script.listener.PaintListener; import org.dreambot.api.wrappers.interactive.GameObject; import java.awt.*; @ScriptManifest(author = "iSystem", name = "Willow Cutter", version = 1.0, description = "Woodcutter", category = Category.WOODCUTTING) public class Woodcutter extends AbstractScript implements PaintListener { public int getTime() { int seconds = 1000; int minutes = seconds / 60; int hours = minutes / 60; int days = hours / 24; return seconds; } @Override public void onPaint(Graphics g) { g.drawString("Experience remaining to level " +(Skills.getExperienceToLevel(Skill.WOODCUTTING)), 10, 10); g.drawString("Time ran " + getTime(), 15, 15); } public void onStart() { log("starting"); } @Override public int onLoop() { if (getInventory().isFull()) { getInventory().dropAll("Willow Logs"); sleep(300, 500); } else { GameObject willow = getGameObjects().closest("Willow"); if (willow != null) { willow.interact("Chop down"); sleep(500, 600); sleepUntil(() -> !getLocalPlayer().isAnimating() , 15000); } } return 300; } public void onExit() { log("finished"); } } Edited July 28, 2021 by isystem32 Link to comment Share on other sites More sharing options...
ethan45 4 Share Posted July 28, 2021 1 hour ago, isystem32 said: Hi I'm working on my first script. It's a basic willow power cutter. I can't seem to get a functional timer (Hours:Minutes:Seconds) running on the paint. Can someone give me any tips or point me to the right direction. Thanks! Source code below: import org.dreambot.api.methods.skills.Skill; import org.dreambot.api.methods.skills.Skills; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.script.listener.PaintListener; import org.dreambot.api.wrappers.interactive.GameObject; import java.awt.*; @ScriptManifest(author = "iSystem", name = "Willow Cutter", version = 1.0, description = "Woodcutter", category = Category.WOODCUTTING) public class Woodcutter extends AbstractScript implements PaintListener { public int getTime() { int seconds = 1000; int minutes = seconds / 60; int hours = minutes / 60; int days = hours / 24; return seconds; } @Override public void onPaint(Graphics g) { g.drawString("Experience remaining to level " +(Skills.getExperienceToLevel(Skill.WOODCUTTING)), 10, 10); g.drawString("Time ran " + getTime(), 15, 15); } public void onStart() { log("starting"); } @Override public int onLoop() { if (getInventory().isFull()) { getInventory().dropAll("Willow Logs"); sleep(300, 500); } else { GameObject willow = getGameObjects().closest("Willow"); if (willow != null) { willow.interact("Chop down"); sleep(500, 600); sleepUntil(() -> !getLocalPlayer().isAnimating() , 15000); } } return 300; } public void onExit() { log("finished"); } } Not on computer But onStart you need to get time Link to comment Share on other sites More sharing options...
Hosfad 154 Share Posted July 28, 2021 3 hours ago, ethan45 said: Not on computer But onStart you need to get time Hello @ethan45 , you can use this class public class Time { public long startTime; public Time() { } public static String eclapsedtime(Long startTime) { long elapsed; elapsed = ((System.currentTimeMillis() - startTime) / 1000); return String.format("%02d:%02d:%02d", elapsed / 3600, (elapsed % 3600) / 60, (elapsed % 60)); } public static long eclapsedsec(Long startTime) { long elapsed; elapsed = ((System.currentTimeMillis() - startTime) / 1000); return elapsed; } public long getStartTime() { return startTime; } public void setStartTime(long startTime) { this.startTime = startTime; } } Link to comment Share on other sites More sharing options...
Bonfire 323 Share Posted July 28, 2021 Doesn't the Timer class' .formatTime() method do exactly this? Initialize a new Timer in your onStart and then just paint Timer.formatTime() Floryda 1 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