Open DaZzler86 opened 2 years ago
I found the issue. the issue is in the purchase of the upgraded server. He is creating a new UUID for the server instead of updating with the old UUID. So the new server is not getting added to the list of purchased servers. I am looking into a fix for this.
Here is the fix:
`
if (targetRam > ns.getServerMaxRam(purchasedServers[0])) {
if (ns.getServerMoneyAvailable('home') * settings.totalMoneyAllocation >= targetRam * settings.gbRamCost) {
let myOldUUID = purchasedServers[0].substring(12,purchasedServers[0].length)
let hostname = `pserv-${targetRam}-${myOldUUID}`
await ns.killall(purchasedServers[0])
await ns.sleep(10)
let serverDeleted = await ns.deleteServer(purchasedServers[0])
if (serverDeleted) {
hostname = await ns.purchaseServer(hostname, targetRam)
if (hostname) {
ns.tprint(`[${localeHHMMSS()}] Upgraded: ${purchasedServers[0]} into server: ${hostname} (${targetRam} GB)`)
purchasedServers[0] = hostname
updateServer(ns, serverMap, hostname)
didChange = true
}
}
}
`
Just locate the section and update the code. I pulled the old UUID and added it to the new host name. Then I updated the Server name in the purchasedServers array so that the updateServers function would be able to find it.
Thanks for your investigations @darklingduck! Could you paste/upload your whole playerserver.js file? For me the script still keeps buying servers.
The problem ist the calculation of the RAM. The script calculates the RAM of a purchased server by add the free RAM and the used RAM by a deprecated function. This cause the script to calaculate f.e. 63.5 GB RAM instead of 64. This again causes an upgrade loop, because the script tries to replace the 63.5 GB server by a 64 GB server. Buying server manually or by another script will cause the same issue just with different values.
In which BitNodes are you guys? I'm in BitNode 3.
For me, it was a bug in the Ram Cost calculation: GB * 550000 works in BitNode 1 just fine, but later in other BitNodes there could be multipliers which makes ram more expensive and so my script tried to upgrade a server (deleted the target server prior to this) but could not afford the new one. So it switched to the buy mode, buys a new server and repeats this steps. See getPurchaseServerCost(ram: number)
I fixed this in my dev-repo, please give it a try: https://github.com/ComictypX/bitburner/blob/dev/src/playerServers.js
Problem with "buying / upgrade" Server -loop