Jump to content

Basic Paint problem


HunterRS

Recommended Posts

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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