forked from kamukrass/Bitburner
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustomHud.js
174 lines (138 loc) · 7.29 KB
/
customHud.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/** @param {NS} ns **/
export async function main(ns) {
/*
Original script by: u/I_hate_you_wasTaken, (https://www.reddit.com/r/Bitburner/comments/10urhbn/custom_overview_stats_but_better/)
UPDATE 2/25/2023:
After the v2.2.2 release was released on 2/21/2023, the findPlayer() method used in the original script for 'globalThis.webpackJsonp.push()' and payload_id, stopped working.
I refactored the script to use ns.getPlayer() and ns.gang.getGangInformation() as well as other methods to build out the previous and some new data fot the HUD.
The HUD now also shows the following:
• City
• Location
• Faction
• Gang Respect
• Gang Income
• Scripts Income $/sec
• Script Experience XP/sec
• Karma
• Kills
This hs been tested on v2.2.2 (d3f9554a), and it is working/stable.
- u/DukeNukemDad
*/
ns.disableLog("ALL");
// ns.clearLog();
// ns.tail();
const args = ns.flags([["help", false]]);
if (args.help) {
ns.tprint("This script will enhance your HUD (Heads up Display) with custom statistics.");
ns.tprint(`Usage: run ${ns.getScriptName()}`);
ns.tprint("Example:");
ns.tprint(`> run ${ns.getScriptName()}`);
return;
}
const doc = eval('document');
const removeByClassName = (sel) => doc.querySelectorAll(sel).forEach(el => el.remove());
const colorByClassName = (sel, col) => doc.querySelectorAll(sel).forEach(el => el.style.color = col);
const hook0 = doc.getElementById('overview-extra-hook-0');
const hook1 = doc.getElementById('overview-extra-hook-1');
var theme = ns.ui.getTheme()
while (true) {
try {
let player = ns.getPlayer();
var gangInfo = null;
var gangFaction = "";
var gangIncome = 0;
var gangRespect = 0;
let gangAPI = false;
try {
if (ns.gang.getGangInformation() != null) {
gangAPI = true;
}
} catch {
ns.print("gangAPI: " + false);
}
if (gangAPI != false) {
gangInfo = ns.gang.getGangInformation();
gangFaction = gangInfo.faction;
gangIncome = ns.formatNumber(ns.gang.getGangInformation().moneyGainRate * 5, 2); // A tick is every 200ms. To get the actual money/sec, multiple moneyGainRate by 5.
gangRespect = ns.formatNumber(ns.gang.getGangInformation().respect, 5);
}
var playerCity = player.city; // city
var playerLocation = player.location; // location
var playerKills = player.numPeopleKilled; // numPeopleKilled
var playerKarma = ns.heart.break().toFixed(3);
let purchased_servers = ns.getPurchasedServers(); // get every bought server if exists, else just create our blank array and add home to it.
purchased_servers.push("home"); // add home to the array.
let cumulative = 0;
for (let pserv of purchased_servers) {
let gains = 0;
for (var script of ns.ps(pserv)) {
var s = ns.getRunningScript(script.pid)
if (s.onlineRunningTime > 0) gains += s.onlineMoneyMade / s.onlineRunningTime
}
cumulative += gains;
}
var scriptIncome = ns.formatNumber(cumulative, 2); // $/sec
var scriptXP = ns.formatNumber(ns.getTotalScriptExpGain(), 2); // xp/sec
// End paramaters, begin CSS:
removeByClassName('.HUD_el');
var theme = ns.ui.getTheme();
removeByClassName('.HUD_sep');
hook0.insertAdjacentHTML('beforebegin', `<hr class="HUD_sep HUD_el">`);
hook1.insertAdjacentHTML('beforebegin', `<hr class="HUD_sep HUD_el">`);
// playerCity
hook0.insertAdjacentHTML('beforeend', `<element class="HUD_GN_C HUD_el" title="The name of the City you are currently in.">City </element><br class="HUD_el">`)
colorByClassName(".HUD_GN_C", theme['cha'])
hook1.insertAdjacentHTML('beforeend', `<element class="HUD_GN_C HUD_el">${playerCity + '<br class="HUD_el">'}</element>`)
colorByClassName(".HUD_GN_C", theme['cha'])
// playerLocation
hook0.insertAdjacentHTML('beforeend', `<element class="HUD_GN_L HUD_el" title="Your current location inside the city.">Location </element><br class="HUD_el">`)
colorByClassName(".HUD_GN_L", theme['cha'])
hook1.insertAdjacentHTML('beforeend', `<element class="HUD_GN_L HUD_el">${playerLocation + '<br class="HUD_el">'}</element>`)
colorByClassName(".HUD_GN_L", theme['cha'])
if (gangInfo != null) {
// gangFaction
hook0.insertAdjacentHTML('beforeend', `<element class="HUD_GN_F HUD_el" title="The name of your gang faction.">Faction </element><br class="HUD_el">`)
colorByClassName(".HUD_GN_F", theme['int'])
hook1.insertAdjacentHTML('beforeend', `<element class="HUD_GN_F HUD_el">${gangFaction + '<br class="HUD_el">'}</element>`)
colorByClassName(".HUD_GN_F", theme['int'])
// gangRespect
hook0.insertAdjacentHTML('beforeend', `<element class="HUD_GN_R HUD_el" title="The respect of your gang.">Gang Respect</element><br class="HUD_el">`)
colorByClassName(".HUD_GN_R", theme['int'])
hook1.insertAdjacentHTML('beforeend', `<element class="HUD_GN_R HUD_el">${gangRespect + '<br class="HUD_el">'}</element>`)
colorByClassName(".HUD_GN_R", theme['int'])
// gangIncome
hook0.insertAdjacentHTML('beforeend', `<element class="HUD_GN_I HUD_el" title="The income of your gang.">Gang Income</element><br class="HUD_el">`)
colorByClassName(".HUD_GN_I", theme['int'])
hook1.insertAdjacentHTML('beforeend', `<element class="HUD_GN HUD_el">${"$" + gangIncome + '/sec<br class="HUD_el">'}</element>`)
colorByClassName(".HUD_GN", theme['int'])
}
// scriptIncome
hook0.insertAdjacentHTML('beforeend', `<element class="HUD_ScrInc_H HUD_el" title="Money Gain from Scripts per Second.">ScrInc</element>`)
colorByClassName(".HUD_ScrInc_H", theme['money'])
hook1.insertAdjacentHTML('beforeend', `<element class="HUD_ScrInc HUD_el">${"$" + scriptIncome + '/sec'}</element>`)
colorByClassName(".HUD_ScrInc", theme['money'])
// scriptXP
hook0.insertAdjacentHTML('beforeend', `<element class="HUD_ScrExp_H HUD_el" title="XP Gain from Scripts per Second."><br>ScrExp </element>`)
colorByClassName(".HUD_ScrExp_H", theme['hack'])
hook1.insertAdjacentHTML('beforeend', `<element class="HUD_ScrExp HUD_el"><br>${scriptXP + ' XP/sec'}</element>`)
colorByClassName(".HUD_ScrExp", theme['hack'])
// playerKarma
hook0.insertAdjacentHTML('beforeend', `<element class="HUD_Karma_H HUD_el" title="Your karma."><br>Karma </element>`)
colorByClassName(".HUD_Karma_H", theme['hp'])
hook1.insertAdjacentHTML('beforeend', `<element class="HUD_Karma HUD_el"><br>${playerKarma}</element>`)
colorByClassName(".HUD_Karma", theme['hp'])
removeByClassName('.HUD_Kills_H')
// playerKills
hook0.insertAdjacentHTML('beforeend', `<element class="HUD_Kills_H HUD_el" title="Your kill count, increases every successful homicide."><br>Kills </element>`)
colorByClassName(".HUD_Kills_H", theme['hp'])
removeByClassName('.HUD_Kills')
hook1.insertAdjacentHTML('beforeend', `<element class="HUD_Kills HUD_el"><br>${playerKills}</element>`)
colorByClassName(".HUD_Kills", theme['hp'])
var theme = ns.ui.getTheme()
} catch (err) {
ns.print("ERROR: Update Skipped: " + String(err));
}
ns.atExit(function () { removeByClassName('.HUD_el'); })
await ns.sleep(200);
}
}