mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-23 16:13:49 +01:00
13 KiB
13 KiB
NS interface
Collection of all functions passed to scripts
Signature:
export interface NS
Remarks
Basic ns1 usage example:
// Basic ns functions can be used directly
getHostname();
// Some related functions are gathered within a common namespace
stock.getPrice();
Basic ns2 usage example:
export async function main(ns) {
// Basic ns functions can be accessed on the ns object
ns.getHostname();
// Some related functions are gathered under a sub-property of the ns object
ns.stock.getPrice();
// Some functions need to be awaited
await ns.hack('n00dles');
}
Properties
Property | Type | Description |
---|---|---|
args | (string | number | boolean)[] | Arguments passed into the script. |
bladeburner | Bladeburner | Namespace for bladeburner functions. |
codingcontract | CodingContract | Namespace for codingcontract functions. |
corporation | Corporation | Namespace for corporation functions. RAM cost: 0 GB |
enums | NSEnums | |
formulas | Formulas | Namespace for formulas functions. |
gang | Gang | Namespace for gang functions. |
grafting | Grafting | Namespace for grafting functions. |
hacknet | Hacknet | Namespace for hacknet functions. |
singularity | Singularity | Namespace for singularity functions. RAM cost: 0 GB |
sleeve | Sleeve | Namespace for sleeve functions. |
stanek | Stanek | Namespace for stanek functions. RAM cost: 0 GB |
stock | TIX | Namespace for stock functions. |
ui | UserInterface | Namespace for user interface functions. RAM cost: 0 GB |
Methods
Method | Description |
---|---|
alert(msg) | Open up a message box. |
asleep(millis) | Suspends the script for n milliseconds. Doesn't block with concurrent calls. |
atExit(f) | Add callback function when the script dies |
brutessh(host) | Runs BruteSSH.exe on a server. |
clear(handle) | Clear data from a file. |
clearLog() | Clears the script’s logs. |
clearPort(handle) | Clear data from a port. |
deleteServer(host) | Delete a purchased server. |
disableLog(fn) | Disables logging for the given function. |
enableLog(fn) | Enable logging for a certain function. |
exec(script, host, numThreads, args) | Start another script on any server. |
exit() | Terminates the current script immediately. |
fileExists(filename, host) | Check if a file exists. |
flags(schema) | Parse command line flags. |
ftpcrack(host) | Runs FTPCrack.exe on a server. |
getBitNodeMultipliers() | Get the current Bitnode multipliers. |
getFavorToDonate() | Returns the amount of Faction favor required to be able to donate to a faction. |
getGrowTime(host) | Get the execution time of a grow() call. |
getHackingLevel() | Returns the player’s current hacking level. |
getHackingMultipliers() | Get hacking related multipliers. |
getHacknetMultipliers() | Get hacknet related multipliers. |
getHackTime(host) | Get the execution time of a hack() call. |
getHostname() | Returns a string with the hostname of the server that the script is running on. |
getOwnedSourceFiles() | Get a list of acquired Source-Files. |
getPlayer() | Get information about the player. |
getPortHandle(port) | Get all data on a port. |
getPurchasedServerCost(ram) | Get cost of purchasing a server. |
getPurchasedServerLimit() | Returns the maximum number of servers you can purchase. |
getPurchasedServerMaxRam() | Returns the maximum RAM that a purchased server can have. |
getPurchasedServers() | Returns an array with the hostnames of all of the servers you have purchased. |
getRecentScripts() | Get an array of recently killed scripts across all servers. |
getRunningScript(filename, hostname, args) | Get general info about a running script. |
getScriptExpGain() | Get the exp gain of a script. |
getScriptExpGain(script, host, args) | Get the exp gain of a script. |
getScriptIncome() | Get the income of a script. |
getScriptIncome(script, host, args) | Get the income of a script. |
getScriptLogs(fn, host, args) | Get all the logs of a script. |
getScriptName() | Returns the current script name. |
getScriptRam(script, host) | Get the ram cost of a script. |
getServer(host) | Returns a server object for the given server. Defaults to the running script's server if host is not specified. |
getServerBaseSecurityLevel(host) | |
getServerGrowth(host) | Get a server growth parameter. |
getServerMaxMoney(host) | Get maximum money available on a server. |
getServerMaxRam(host) | Get the max RAM on a server. |
getServerMinSecurityLevel(host) | Returns the minimum security level of the target server. |
getServerMoneyAvailable(host) | Get money available on a server. |
getServerNumPortsRequired(host) | Returns the number of open ports required to successfully run NUKE.exe on the specified server. |
getServerRam(host) | |
getServerRequiredHackingLevel(host) | Returns the required hacking level of the target server. |
getServerSecurityLevel(host) | Get server security level. |
getServerUsedRam(host) | Get the used RAM on a server. |
getSharePower() | Calculate your share power. Based on all the active share calls. |
getTimeSinceLastAug() | Returns the amount of time in milliseconds that have passed since you last installed Augmentations. |
getWeakenTime(host) | Get the execution time of a weaken() call. |
grow(host, opts) | Spoof money in a servers bank account, increasing the amount available. |
growthAnalyze(host, growthAmount, cores) | Calculate the number of grow thread needed to grow a server by a certain multiplier. |
growthAnalyzeSecurity(threads, hostname, cores) | Calculate the security increase for a number of thread. |
hack(host, opts) | Steal a servers money. |
hackAnalyze(host) | Get the part of money stolen with a single thread. |
hackAnalyzeChance(host) | Get the chance of successfully hacking a server. |
hackAnalyzeSecurity(threads, hostname) | Get the security increase for a number of thread. |
hackAnalyzeThreads(host, hackAmount) | Predict the effect of hack. |
hasRootAccess(host) | Check if your have root access on a server. |
httpworm(host) | Runs HTTPWorm.exe on a server. |
isLogEnabled(fn) | Checks the status of the logging for the given function. |
isRunning(script, host, args) | Check if a script is running. |
kill(script) | Terminate another script. |
kill(script, host, args) | Terminate another script. |
killall(host) | Terminate all scripts on a server. |
ls(host, grep) | List files on a server. |
mv(host, source, destination) | Move a file on the target server. |
nFormat(n, format) | Format a number |
nuke(host) | Runs NUKE.exe on a server. |
peek(port) | Get a copy of the data from a port without popping it. |
print(args) | Prints one or move values or variables to the script’s logs. |
printf(format, args) | Prints a formatted string to the script’s logs. |
prompt(txt, options) | Prompt the player with an input modal. |
ps(host) | List running scripts on a server. |
purchaseServer(hostname, ram) | Purchase a server. |
read(handle) | Read content of a file. |
readPort(port) | Read data from a port. |
relaysmtp(host) | Runs relaySMTP.exe on a server. |
rm(name, host) | Delete a file. |
run(script, numThreads, args) | Start another script on the current server. |
scan(host) | Get the list of servers connected to a server. |
scp(files, destination) | Copy file between servers. |
scp(files, source, destination) | Copy file between servers. |
scriptKill(script, host) | Kill all scripts with a filename. |
scriptRunning(script, host) | Check if any script with a filename is running. |
serverExists(host) | Returns a boolean denoting whether or not the specified server exists. |
share() | Share your computer with your factions. |
sleep(millis) | Suspends the script for n milliseconds. |
spawn(script, numThreads, args) | Terminate current script and start another in 10s. |
sprintf(format, args) | Format a string. |
sqlinject(host) | Runs SQLInject.exe on a server. |
tail(fn, host, args) | Open the tail window of a script. |
tFormat(milliseconds, milliPrecision) | Format time to readable string |
toast(msg, variant, duration) | Queue a toast (bottom-right notification). |
tprint(args) | Prints one or more values or variables to the Terminal. |
tprintf(format, values) | Prints a raw value or a variable to the Terminal. |
tryWritePort(port, data) | Attempt to write to a port. |
vsprintf(format, args) | Format a string with an array of arguments. |
weaken(host, opts) | Reduce a server security level. |
weakenAnalyze(threads, cores) | Predict the effect of weaken. |
wget(url, target, host) | Download a file from the internet. |
write(handle, data, mode) | Write data to a file. |
writePort(port, data) | Write data to a port. |