Created
October 2, 2018 18:44
-
-
Save n1c/27dc159ad09740953ea760d7dc1f4ace to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const log = console.log; | |
import demofile = require("demofile"); | |
import * as fs from "fs"; | |
if (process.argv.length < 3) { | |
log("Specify the full path to a demo"); | |
log("e.g.: ./index.js ~/test.dem"); | |
process.exit(1); | |
} | |
const demoPath: string = process.argv[2]; | |
let grenades: { [userid: number]: any[] } = {}; | |
const demo = new demofile.DemoFile(); | |
demo.on("end", () => { | |
console.timeEnd("parseDemo"); | |
}); | |
demo.gameEvents.on("round_officially_ended", () => { | |
grenades = {}; | |
}); | |
demo.gameEvents.on("weapon_fire", (e: any) => { | |
if (e.weapon === "hegrenade") { | |
if (!grenades[e.userid]) { | |
grenades[e.userid] = []; | |
} | |
const player = demo.entities.getByUserId(e.userid); | |
const p = { | |
x: player.position.x, | |
y: player.position.y, | |
z: player.position.z, | |
}; | |
// log(`New throw at ${p.x},${p.y},${p.z}`); | |
grenades[e.userid].push(p); | |
} | |
}); | |
demo.gameEvents.on("hegrenade_detonate", (e: any) => { | |
if (grenades[e.userid]) { | |
const et = grenades[e.userid].shift(); | |
log(`Position at throw ${et.x},${et.y},${et.z} position detonate ${e.x},${e.y},${e.z}`); | |
} else { | |
log("Detonate with no matching throw :("); | |
} | |
}); | |
fs.readFile(demoPath, (err: NodeJS.ErrnoException, buffer: Buffer) => { | |
if (err) { | |
throw err; | |
} | |
log(`Processing ${demoPath}`); | |
demo.parse(buffer); | |
}); | |
console.time("parseDemo"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment