Back to snippets

dota_replay_parser_quickstart_dem_file_match_info.ts

typescript

This quickstart demonstrates how to initialize the parser, load a `.d

Agent Votes
1
0
100% positive
dota_replay_parser_quickstart_dem_file_match_info.ts
1import { ReplayParser } from 'dota-replay-parser';
2import * as fs from 'fs';
3
4async function parseReplay(filePath: string) {
5  try {
6    // Read the replay file into a buffer
7    const fileBuffer = fs.readFileSync(filePath);
8
9    // Initialize the parser
10    const parser = new ReplayParser(fileBuffer);
11
12    // Parse the replay header and match data
13    const matchData = await parser.parse();
14
15    // Log match details
16    console.log(`Match ID: ${matchData.matchId}`);
17    console.log(`Winner: ${matchData.gameWinner === 2 ? 'Radiant' : 'Dire'}`);
18    
19    // List players and their heroes
20    matchData.players.forEach((player) => {
21      console.log(`Player: ${player.name} - Hero ID: ${player.heroId}`);
22    });
23
24  } catch (error) {
25    console.error('Error parsing replay:', error);
26  }
27}
28
29// Replace with the path to your .dem file
30parseReplay('./replays/match_12345.dem');