From 314a747d9299c83ee5d8f96c91caf61f1ce6b2b1 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Thu, 20 Aug 2020 18:14:59 +0200 Subject: [PATCH] Improve `0s_defuser.js` --- netcon_stuff/0s_defuser/0s_defuser.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/netcon_stuff/0s_defuser/0s_defuser.js b/netcon_stuff/0s_defuser/0s_defuser.js index 76a684b..eb66638 100644 --- a/netcon_stuff/0s_defuser/0s_defuser.js +++ b/netcon_stuff/0s_defuser/0s_defuser.js @@ -10,7 +10,6 @@ const config = { pingMultiplier: 1, // If you get 0.02 instead of 0.000, you can try setting this to -10. - // If it doesn't help, change the `pingMultiplier` to 0.5 or lower. pingOffset: 0, ms: { @@ -63,6 +62,8 @@ let timeout5s; let explosionTime = 0; +let isSafeNow = false; + const sendOnConnect = `developer 1; con_filter_enable 2; con_filter_text "Time until explosion: "; @@ -73,19 +74,16 @@ name; `; const onChange = data => { - const hasPrevious = data.Name in previousNetStats; - - if (!hasPrevious) { - previousNetStats[data.Name] = data; + if ((data.Name in previousNetStats) && previousNetStats[data.Name].In === data.In) { return; } - if (previousNetStats[data.Name].In === data.In) { + previousNetStats[data.Name] = data; + + if (!isSafeNow) { return; } - previousNetStats[data.Name] = data; - if (data.Name === 'bomb_planted') { if (explosionTime !== 0) { return; @@ -148,6 +146,10 @@ const socket = net.connect(port, '127.0.0.1', async () => { socket.write(`clear\n${pingCommand}net_dumpeventstats\necho "${constants.autodefuse.timeUntilExplosion}: ${timeUntilExplosion}s ${constants.autodefuse[config.defuseMode]}"\n`); }, config.ms.tick).unref(); + + setTimeout(() => { + isSafeNow = true; + }, 10 * config.ms.tick).unref(); } // Read data