-
I am missing 2 player KDA from parsing the demo file. Here is my code:
Here is the link to the demo file: https://www.hltv.org/download/demo/68581 or https://www.hltv.org/matches/2352714/sprout-vs-rezist-united-pro-series-2021 Here is the link to the expected result: https://www.hltv.org/stats/matches/mapstatsid/130190/sprout-vs-rezist In my case, I am missing the stats for player: What could be the possible reason for this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The reason is because the players disconnected before the demo finished recording. What you should do is capture player stats at the time they disconnect - see below for a complete example: import * as assert from "assert";
import { Player, DemoFile } from "demofile";
import * as fs from "fs";
interface PlayerStats {
team: string;
steamId: string;
playerName: string;
kills: number;
assists: number;
deaths: number;
}
function parseDemoFile(path: string) {
fs.readFile(path, (err, buffer) => {
assert.ifError(err);
const demoFile = new DemoFile();
const stats: Record<string, PlayerStats> = {};
function capturePlayerStats(player: Player) {
// Skip over bots and GOTV
if (player.isFakePlayer) return;
stats[player.steamId] = {
team: player.team!.teamName,
steamId: player.steamId,
playerName: player.name,
kills: player.kills,
assists: player.assists,
deaths: player.deaths
};
}
demoFile.gameEvents.on("player_disconnect", ({ userid }) => {
const player = demoFile.entities.getByUserId(userid)!;
console.log(`Player ${player.name} disconnected`);
capturePlayerStats(player);
});
demoFile.on("end", e => {
if (e.error) {
console.error("Error during parsing:", e.error);
process.exitCode = 1;
} else {
demoFile.players.forEach(capturePlayerStats);
console.table(stats);
}
console.log("Finished.");
});
// Start parsing the buffer now that we've added our event listeners
demoFile.parse(buffer);
});
}
parseDemoFile(process.argv[2]!); Full output:
|
Beta Was this translation helpful? Give feedback.
The reason is because the players disconnected before the demo finished recording. What you should do is capture player stats at the time they disconnect - see below for a complete example: