Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Improve 0s_defuser.js
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak authored Aug 20, 2020
1 parent 9b53463 commit 314a747
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions netcon_stuff/0s_defuser/0s_defuser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: ";
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 314a747

Please sign in to comment.