CrimeMonitor!
This commit is contained in:
@@ -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];
|
||||
}
|
||||
Reference in New Issue
Block a user