diff --git a/netcon_stuff/0s_defuser/0s_defuser.js b/netcon_stuff/0s_defuser/0s_defuser.js index 5effe21..99a73dc 100644 --- a/netcon_stuff/0s_defuser/0s_defuser.js +++ b/netcon_stuff/0s_defuser/0s_defuser.js @@ -3,7 +3,12 @@ const net = require('net'); const readline = require('readline'); const path = require('path'); +// Change this to 2 if it fails for you +// This should NOT be greater than 6 +const pingMultiplier = 1.5; + const TICK_RATE = 64; +const PING_DELIMITER = ' ms : '; let previous = {}; let timeout10s; @@ -12,6 +17,8 @@ let counter = 0; let defuseMode = 0; let explosionTime = 0; +let ping = 1; +let username = 'unnamed'; const sendOnConnect = `developer 1; con_filter_enable 2; @@ -32,23 +39,21 @@ const onChange = data => { previous[data.Name] = data; if (counter === 2) { - explosionTime = Date.now() + 40000; + explosionTime = Date.now() + 40000 - pingMultiplier * ping - 1; clearTimeout(timeout10s); clearTimeout(timeout5s); - - // This should be set between 29970 - 29980 timeout10s = setTimeout(() => { if (defuseMode === 1) { socket.write(`+use\n`); } - }, 29970); + }, 30000 - pingMultiplier * ping - 1); timeout5s = setTimeout(() => { if (defuseMode === 2) { socket.write(`+use\n`); } - }, 29970 + 5000); + }, 30000 - pingMultiplier * ping - 1 + 5000); } } else if (data.Name === 'round_start') { previous[data.Name] = data; @@ -89,7 +94,7 @@ if (process.argv.length !== 3 || !port) { const socket = net.connect(port, '127.0.0.1', async () => { console.log('Connected! Press CTRL+C to abort.'); - socket.write(`${sendOnConnect}\n`); + socket.write(`${sendOnConnect}\nname\n`); const reader = readline.createInterface({ input: socket, @@ -101,7 +106,16 @@ const socket = net.connect(port, '127.0.0.1', async () => { for await (const line of reader) { const processedLine = line.replace(whitespaceRegExp, ' ').trim(); - if (processedLine === 'defuse_0s_0') { + if (processedLine.startsWith(`"name" = "`)) { + const end = `" ( def. "unnamed" ) archive server_can_execute user ss`; + username = processedLine.slice(10, processedLine.indexOf(end)); + } else if (processedLine.includes(PING_DELIMITER)) { + const data = processedLine.split(PING_DELIMITER); + + if (data[1] === username) { + ping = Number(data[0]); + } + } if (processedLine === 'defuse_0s_0') { defuseMode = 0; } else if (processedLine === 'defuse_0s_1') { defuseMode = 1; @@ -149,11 +163,11 @@ const socket = net.connect(port, '127.0.0.1', async () => { } }); +let lastPingTime = 0; + setInterval(() => { - socket.write(`clear\n${COMMAND}\n`); - const diff = Math.max(explosionTime - Date.now(), 0); - + let mode; if (defuseMode === 0) { mode = '[NO AUTODEFUSE]'; @@ -162,8 +176,15 @@ setInterval(() => { } else if (defuseMode === 2) { mode = '[AUTODEFUSE 5s]'; } - - socket.write(`echo "Time until explosion: ${(diff / 1000).toFixed(3)}s ${mode}"\n`); + + let pingCommand = ''; + const now = Date.now(); + if ((now - lastPingTime) > 100) { + lastPingTime = now; + pingCommand = 'ping\n'; + } + + socket.write(`clear\n${pingCommand}${COMMAND}\necho "Time until explosion: ${(diff / 1000).toFixed(3)}s ${mode}"\n`); }, Math.floor(1000 / TICK_RATE)).unref(); socket.setEncoding('utf8'); diff --git a/netcon_stuff/0s_defuser/README.md b/netcon_stuff/0s_defuser/README.md index 2a4b139..991a089 100644 --- a/netcon_stuff/0s_defuser/README.md +++ b/netcon_stuff/0s_defuser/README.md @@ -24,9 +24,13 @@ Key description: - `-` - enables 10s autodefuse (IOW without defuse kit), - `=` - enables 5s autodefuse (IOW with defuse kit). -What's an autodefuse? If you have killed all of your enemies and have plenty of time, you can enable autodefuse. It starts defusing automatically so you will have a `0.000s` defuse time. +What's an autodefuse? If you have killed all of your enemies and have plenty of time, you can enable autodefuse. It starts defusing automatically so you will have a defuse time very close to `0.000s`. For example, you can use this script to get the `Second to None` achievement that looks like this: -**Note:** Your crosshair must be pointed at the bomb. +![](https://user-images.githubusercontent.com/36894700/82358940-81b82900-9a07-11ea-8a2e-f62465af8ad4.png) + +**Note #1:** Your crosshair must be pointed at the bomb. + +**Note #2:** If the autodefuse fails, please increase the `pingMultiplier` to `2` (well you can go with `6` but you shouldn't go higher than that). ### Requirements