isystem32 0 Share Posted July 28, 2021 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"); } } 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 333 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() Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.