From 50117674e1fcde2790f83c715ff797a987054d75 Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Fri, 3 Nov 2023 14:38:18 -0300 Subject: [PATCH] Add some more utility functions --- servers/home/utils.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/servers/home/utils.ts b/servers/home/utils.ts index c5acc4d..3cbec04 100644 --- a/servers/home/utils.ts +++ b/servers/home/utils.ts @@ -1,5 +1,10 @@ // noinspection JSUnusedGlobalSymbols +/** + * @file Utility functions for Bitburner + * @note Some functions are currently untested + */ + import {NS} from "NetscriptDefinitions"; /** @@ -108,4 +113,21 @@ export function performFunctionIfCapable(ns: NS, server: string, func: CallableF } else { return result; } +} + +/** + * Executes a script on a server from another server + * @param ns Global NS object + * @param script The file path of the script to execute + * @param args The arguments to pass to the script + * @param server The server to execute the script on + */ +export function executeScriptOnServerFromAnother(ns: NS, script: string, args: any[], server: string) { + ns.scp(script, server); + performFunctionIfCapable(ns, server, ns.exec, [script, server, ...args]) + ns.atExit( + () => { + ns.rm(script, server); + } + ) } \ No newline at end of file