HunterRS Posted September 9, 2017 Share Posted September 9, 2017 hi guys, so I am new to writing scripts and i have kind of a stupid question. I wrote this basic goblin killing script and added some draws, for some reason though my timer always starts at 2 hrs. Anyone knows why? here is the code: int totalXp = 0; for(final Skill skill : new Skill[]{Skill.ATTACK, Skill.STRENGTH, Skill.DEFENCE, Skill.RANGED, Skill.MAGIC}) { totalXp += getExperienceTracker().getGainedXP(skill); } Date date = new Date(getExperienceTracker().getElapsed(Skill.ATTACK)); DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); String dateFormatted = formatter.format(date); g.drawString("Time Running: " + dateFormatted, 20, 300); g.drawString("Total XP: " + Integer.toString(totalXp), 20, 330); Quote Link to comment Share on other sites More sharing options...
GPSwap Posted September 9, 2017 Share Posted September 9, 2017 Never used the get elapsed on tracker, this is what I use for time and its always spot on public void onStart(){ startTime = System.currentTimeMillis(); } public void onPaint(){ final long runTime = System.currentTimeMillis() - startTime; g.drawString("Time running: " + formatTime(runTime), 320, 400); } public final String formatTime(final long ms) { long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24; s %= 60; m %= 60; h %= 24; return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) : h > 0 ? String.format("%02d:%02d:%02d", h, m, s) : String.format("%02d:%02d", m, s); } Quote Link to comment Share on other sites More sharing options...
HunterRS Posted September 9, 2017 Author Share Posted September 9, 2017 Just now, GPSwap said: Never used the get elapsed on tracker, this is what I use for time and its always spot on public void onStart(){ startTime = System.currentTimeMillis(); } public void onPaint(){ final long runTime = System.currentTimeMillis() - startTime; g.drawString("Time running: " + formatTime(runTime), 320, 400); } public final String formatTime(final long ms) { long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24; s %= 60; m %= 60; h %= 24; return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) : h > 0 ? String.format("%02d:%02d:%02d", h, m, s) : String.format("%02d:%02d", m, s); } ty though if anyone knows why it is adding 2 hrs I would appriciate it might just do it like that if i dont find an answer Quote Link to comment Share on other sites More sharing options...
GPSwap Posted September 9, 2017 Share Posted September 9, 2017 1 minute ago, HunterRS said: ty though if anyone knows why it is adding 2 hrs I would appriciate it might just do it like that if i dont find an answer wish i had a answer for ya Quote Link to comment Share on other sites More sharing options...
liverare Posted September 9, 2017 Share Posted September 9, 2017 The ExperienceTracker has a function start. You should run that for all of your skills onStart. Quote Link to comment Share on other sites More sharing options...
HunterRS Posted September 9, 2017 Author Share Posted September 9, 2017 (edited) 1 hour ago, liverare said: The ExperienceTracker has a function start. You should run that for all of your skills onStart. I did :), here is also the onStart: public void onStart() { log("Goblin killer has started"); for(final Skill skill : new Skill[]{Skill.ATTACK, Skill.STRENGTH, Skill.DEFENCE, Skill.RANGED, Skill.MAGIC}) { getExperienceTracker().start(skill); } } EDIT: just to be clear, it was all ready done before so that is not the problem. Edited September 9, 2017 by HunterRS Quote Link to comment Share on other sites More sharing options...
Super Posted September 9, 2017 Share Posted September 9, 2017 (edited) you're over complicating things imo for runtime: public long startTime = System.currentTimeMillis(); public void onPaint(Graphics2D g) { g.drawString("Runtime: " + Time.msToString(System.currentTimeMillis() - startTime), x, y); } public static String msToString(long ms) { int time = (int) (ms / 1000L); int h = time / 3600; int m = time / 60 % 60; int s = time % 60; return (h < 10 ? "0" + h : Integer.valueOf(h)) + ":" + (m < 10 ? "0" + m : Integer.valueOf(m)) + ":" + (s < 10 ? "0" + s : Integer.valueOf(s)); } for xp trackers just use: getExperienceTracker().getGainedXP() getExperienceTracker().getGainedXPPerHour() getExperienceTracker().getTimeToLevel() Edited September 9, 2017 by superuser Quote Link to comment Share on other sites More sharing options...
Lemons Posted September 9, 2017 Share Posted September 9, 2017 (edited) 1 hour ago, superuser said: A simpler msToString method (takes seconds tho, so need to do ms/1000 first): /** * Formats seconds into a H:MM:SS timestamp * @param seconds * @return */ public static String formatTime(long seconds) { if (seconds <= 0) return "00:00:00"; return String.format("%d:%02d:%02d", seconds / 3600, (seconds % 3600) / 60, (seconds % 60)); } Edited September 9, 2017 by Lemons 1 Quote Link to comment Share on other sites More sharing options...