Crime script

What It Does

It commits a crime as long as you have 100% chance of succeding. It only works if you progresed enough into the game ( bitnode 4 ) to make it work.

Code:

/** @param {NS} ns **/ export async function main(ns) { let num = 0.3;// chance of success eg: 1=100%, ns.tail(); let time; let i = 0; let crime; let crimes = ["heist", "assassination", "kidnap", "grand theft auto", "homicide", "larceny", "mug someone", "rob store", "shoplift"]; while (true) { while (!ns.isBusy() ) { crime = crimes;

if (i > crimes.length)

i = 0;

if (ns.getCrimeChance(crime) >= num) {

ns.commitCrime(crime);

i = 0;

time=ns.commitCrime(crime);

}

else

i++;

}

await ns.sleep(time);

}

}[/code]

(old)Code:

/** @param {NS} ns **/ export async function main(ns) { let num = 1;// chance of success ns.tail(); let time; while (true) { if (ns.isBusy() == false) { switch (num) { case ns.getCrimeChance('Heist'): ns.commitCrime('Heist'); time=ns.commitCrime('Heist'); break; case ns.getCrimeChance('Assassination'): ns.commitCrime('Assassination'); time=ns.commitCrime('Assassination'); break; case ns.getCrimeChance('Kidnap'): ns.commitCrime('Kidnap'); time=ns.commitCrime('Kidnap'); break; case ns.getCrimeChance('Grand Theft Auto'): ns.commitCrime('Heist'); time=ns.commitCrime('Heist'); break; case ns.getCrimeChance('Homicide'): ns.commitCrime('Homicide'); time=ns.commitCrime('Homicide'); break; case ns.getCrimeChance('Larceny'): ns.commitCrime('Larceny'); time=ns.commitCrime('Larceny'); break; case ns.getCrimeChance('Mug Someone'): ns.commitCrime('Mug Someone'); time=ns.commitCrime('Mug Someone'); break; case ns.getCrimeChance('Rob Store'): ns.commitCrime('Rob Store'); time=ns.commitCrime('Rob Store'); break; case 1: ns.commitCrime('Shoplift'); time=ns.commitCrime('Shoplift') break; } } await ns.sleep(time);// waits for the crime to finish } }

Afterwords:

I'd be glad to know if there are ways to improve it, like not focusing on the crime or something, I'm new to java so dont be harsh.

Source: https://steamcommunity.com/sharedfiles/filedetails/?id=2709319135					

More Bitburner guilds