Bitburner: Time Calculation Script (How to Get the Time)

a script to using the formulas API to calculate how long we need to wait for a certain hacking level based only on the exp for our hacking scripts (if we have formulas API then our scripts are usually getting more exp than any other method can compare to by that point)
how to use

paste the code into a .js or .ns file

for example timetohack.js

then to use it go to your terminal and run it with your target level as an argument

for example

run timetohack.js 2500

it will print how long you will need to wait to the terminal

the code
function timeformat(input) {
	var sec_num = parseInt(input, 10); // don't forget the second param
	var hours = Math.floor(sec_num / 3600);
	var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
	var seconds = sec_num - (hours * 3600) - (minutes * 60);

	if (hours > 24) { return Math.floor(hours / 24) + " days" }
	if (hours < 0) { hours = 0; }
	if (hours < 10) { hours = "0" + hours; }
	if (minutes < 10) { minutes = "0" + minutes; }
	if (seconds < 10) { seconds = "0" + seconds; }
	return hours + ':' + minutes + ':' + seconds;
}
/** @param {NS} ns **/
export async function main(ns) {
	var skill = ns.args[0];
	var player = ns.getPlayer();
	var mult = player.hacking_mult;
	var sk = ns.formulas.skills;
	var target = sk.calculateExp(skill, mult);
	var left = target - player.hacking_exp;
	var time = left / ns.getScriptExpGain();
	ns.tprint(timeformat(time))
}
follow up

this version of the script is kinda basic because i’m lazy but it’s useful enough on it’s own.

because it’s basic you can use it as an example to make something more useful, some of the more advanced players could probably add a countdown clock to the user interface or something cool like that.

More Guides:

1 thought on “Bitburner: Time Calculation Script (How to Get the Time)”

Leave a Comment

ArabicEnglishFrenchGermanItalianJapaneseKoreanPortugueseSpanish