CrimeMonitor!

This commit is contained in:
2024-10-18 13:35:58 +02:00
parent aac2a5e884
commit 4c320ab609
7 changed files with 171 additions and 2 deletions

View File

@@ -422,4 +422,30 @@ export async function drun(ns, ...args ){
nFreeRAM = ns.getServerMaxRam(entry.serverName) - ns.getServerUsedRam(entry.serverName);
}
});
}
/** @param {NS} ns */
export function GetCrimeStat(ns, sCrime, sStat) {
const sCrimeStatsFile = "CrimeStats.txt";
// Read the crime stats file
let aCrimeStatsList = JSON.parse(ns.read(sCrimeStatsFile));
// Search for the crime in the list
let oCrimeStats = aCrimeStatsList.find(crime => crime.name === sCrime);
// If the crime was not found, return undefined or an error message
if (!oCrimeStats) {
ns.tprint(`Crime "${sCrime}" not found.`);
return undefined;
}
// Check if the stat exists for the given crime
if (!(sStat in oCrimeStats)) {
ns.tprint(`Stat "${sStat}" not found for crime "${sCrime}".`);
return undefined;
}
// Return the value of the specified stat
return oCrimeStats[sStat];
}