Jump to content

Basic Paint problem


Recommended Posts

Posted

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);

 

Posted

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);
	}

 

Posted
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

Posted (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 by HunterRS
Posted (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 by superuser
Posted (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 by Lemons
  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...