### Complete Event Listening Example Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/events.md This example sets up an Express server to receive GSI data, digests it, and then listens for various game events. Ensure you have express and csgogsi installed. The server listens on port 3000. ```typescript import express from 'express'; import { CSGOGSI } from 'csgogsi'; const app = express(); const gsi = new CSGOGSI(); app.use(express.urlencoded({ extended: true })); app.post('/gsi', (req, res) => { gsi.digest(req.body); res.sendStatus(200); }); // Listen to all events gsi.on('data', (data) => { console.log(`[DATA] Round ${data.map.round}, Phase: ${data.phase_countdowns.phase}`); }); gsi.on('roundEnd', (score) => { console.log(`[ROUND] ${score.winner.name} wins! ${score.winner.score}-${score.loser.score}`); }); gsi.on('bombPlant', (player) => { console.log(`[BOMB] ${player.name} planted at ${gsi.current?.bomb?.site}`); }); gsi.on('kill', (kill) => { let info = `[KILL] ${kill.victim.name} <- ${kill.killer?.name}`; if (kill.headshot) info += ' [HS]'; console.log(info); }); gsi.on('timeoutStart', (team) => { console.log(`[TIMEOUT] ${team.name} has ${team.timeouts_remaining - 1} left`); }); app.listen(3000, () => { console.log('GSI server listening on port 3000'); }); ``` -------------------------------- ### Minimal CSGOGSI Setup Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/MANIFEST.md This snippet shows the most basic setup for the CSGOGSI library. It requires no constructor parameters and minimal configuration. ```typescript import CSGOGSI from "csgogsi"; const gsi = new CSGOGSI(); gsi.on("data", (state) => { console.log(state); }); gsi.on("error", (err) => { console.error(err); }); ``` -------------------------------- ### Full CSGOGSI Configuration Example Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/MANIFEST.md This example illustrates a comprehensive configuration for CSGOGSI, including custom team and player data, and specific round counts. ```typescript import CSGOGSI from "csgogsi"; const gsi = new CSGOGSI({ teams: { Terrorist: { name: "Team Alpha", flag: "DE", score: 0, id: "1" }, CounterTerrorist: { name: "Team Bravo", flag: "US", score: 0, id: "2" } }, players: { // Custom player data }, regulationMR: 9, overtimeMR: 3 }); ``` -------------------------------- ### Install csgogsi Package Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Install the csgogsi library using npm. This is the first step to integrating game state data into your application. ```bash npm install csgogsi ``` -------------------------------- ### Full CSGOGSI Configuration Example Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/configuration.md A comprehensive example demonstrating full CSGOGSI configuration, including extended overtimes, team and player data injection, and event listeners for round end. ```typescript import express from 'express'; import { CSGOGSI } from 'csgogsi'; const app = express(); const gsi = new CSGOGSI(); // Configure for extended overtimes gsi.regulationMR = 15; gsi.overtimeMR = 5; gsi.setMaxListeners(50); // Configure teams gsi.teams.left = { id: 'team_a', name: 'Team A', country: 'US', logo: null, map_score: 0, extra: {} }; gsi.teams.right = { id: 'team_b', name: 'Team B', country: 'SE', logo: null, map_score: 0, extra: {} }; // Configure players gsi.players = [ { id: 'player_1', steamid: '76561198000000001', name: 'Player1', realName: 'John Doe', country: 'US', avatar: null, extra: { team: 'Team A' } } ]; app.use(express.urlencoded({ extended: true })); app.post('/gsi', (req, res) => { gsi.digest(req.body); res.sendStatus(200); }); // Listen to events with custom logic gsi.on('roundEnd', (score) => { console.log(`${score.winner.name} wins!`); console.log(`Regulation rounds: ${gsi.regulationMR}`); }); app.listen(3000); ``` -------------------------------- ### Freezetime Start Source: https://github.com/osztenkurden/csgogsi/blob/master/README.md Triggered at the beginning of the freezetime period. ```APIDOC ## Event: freezetimeStart ### Description This event is triggered at the start of the freezetime period. ### Callback Signature `() => {}` ``` -------------------------------- ### Minimal CSGOGSI Setup Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/configuration.md Set up a basic CSGOGSI instance and integrate it with an Express server to receive game state data. Listen for 'data' events to process updates. ```typescript const gsi = new CSGOGSI(); app.post('/gsi', (req, res) => { gsi.digest(req.body); res.sendStatus(200); }); gsi.on('data', (data) => { console.log('Game state updated'); }); ``` -------------------------------- ### Timeout Start Source: https://github.com/osztenkurden/csgogsi/blob/master/README.md Triggered when a team starts a timeout. ```APIDOC ## Event: timeoutStart ### Description This event is triggered when a team begins a timeout. ### Callback Signature `(team: Team) => {}` ``` -------------------------------- ### Intermission Start Source: https://github.com/osztenkurden/csgogsi/blob/master/README.md Triggered at the beginning of the intermission. ```APIDOC ## Event: intermissionStart ### Description This event is triggered at the start of the intermission. ### Callback Signature `() => {}` ``` -------------------------------- ### Defuse Start Source: https://github.com/osztenkurden/csgogsi/blob/master/README.md Triggered when a player begins defusing the bomb. ```APIDOC ## Event: defuseStart ### Description This event is triggered when a player starts the defuse process. ### Callback Signature `(player: Player) => {}` ``` -------------------------------- ### Node.js Express Server Setup for CS2 GSI Source: https://github.com/osztenkurden/csgogsi/blob/master/README.md Set up an Express server to receive and process CS:GO/CS2 Game State Integration data. This snippet demonstrates how to initialize the CSGOGSI library, handle incoming POST requests, and listen for specific game events like round end and bomb plants. ```javascript import express from 'express'; import { CSGOGSI } from 'csgogsi'; const app = express(); const GSI = new CSGOGSI(); app.use(express.urlencoded({ extended: true })); app.use(express.json({ limit: '10Mb' })); app.post('/', (req, res) => { GSI.digest(req.body); res.sendStatus(200); }); GSI.on('roundEnd', score => { console.log(`Team ${score.winner.name} win!`); }); GSI.on('bombPlant', player => { console.log(`${player.name} planted the bomb`); }); app.listen(3000); ``` -------------------------------- ### Instantiate CSGOGSI Client Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Create a new instance of the CSGOGSI class to start processing game state data. This object will be used for all subsequent operations. ```typescript const gsi = new CSGOGSI(); ``` -------------------------------- ### Bomb Plant Start Source: https://github.com/osztenkurden/csgogsi/blob/master/README.md Triggered when a player begins planting the bomb. ```APIDOC ## Event: bombPlantStart ### Description This event is triggered when a player starts planting the bomb. ### Callback Signature `(player: Player) => {}` ``` -------------------------------- ### Defuse Start Event Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/events.md Emitted when a player begins defusing the bomb. The callback receives the player object. ```APIDOC ## Defuse Start Event ### Description Emitted when a player begins defusing the bomb. ### Method Signature `on('defuseStart', (player: Player) => void)` ### Callback Parameters - `player` (Player) - The player defusing the bomb. ### Fired When `bomb.state` changes from non-'defusing' to 'defusing'. ### Example ```typescript gsi.on('defuseStart', (player) => { const defuseTime = player.state.defusekit ? '20s' : '40s'; console.log(`${player.name} is defusing (${defuseTime})!`); }); ``` ``` -------------------------------- ### Listen for Defuse Start Event Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/events.md Emitted when a player begins defusing the bomb. The callback receives the player object initiating the defuse. ```typescript gsi.on('defuseStart', (player) => { const defuseTime = player.state.defusekit ? '20s' : '40s'; console.log(`${player.name} is defusing (${defuseTime})!`); }); ``` -------------------------------- ### Bomb Plant Start Event Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/events.md Emitted when a player begins planting the bomb. The callback receives the player object. ```APIDOC ## Bomb Plant Start Event ### Description Emitted when a player begins planting the bomb. ### Method Signature `on('bombPlantStart', (player: Player) => void)` ### Callback Parameters - `player` (Player) - The player planting the bomb. ### Fired When `bomb.state` changes from non-'planting' to 'planting'. ### Example ```typescript gsi.on('bombPlantStart', (player) => { console.log(`${player.name} is planting the bomb!`); }); ``` ``` -------------------------------- ### Listen for Bomb Plant Start Event Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/events.md Emitted when a player begins planting the bomb. The callback receives the player object initiating the plant. ```typescript gsi.on('bombPlantStart', (player) => { console.log(`${player.name} is planting the bomb!`); }); ``` -------------------------------- ### Example GSI Payload Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/raw-types.md This JSON object represents a typical Game State Integration (GSI) payload from Counter-Strike: Global Offensive. It contains detailed information about the game state, including map details, player statistics, round information, and bomb status. This payload is often used by external applications to receive real-time game data. ```json { "provider": { "name": "Counter-Strike: Global Offensive", "appid": 730, "version": 13918, "steamid": "76561198012345678", "timestamp": 1234567890 }, "map": { "mode": "competitive", "name": "de_mirage", "phase": "live", "round": 5, "team_ct": { "score": 3, "consecutive_round_losses": 0, "timeouts_remaining": 1, "matches_won_this_series": 0, "name": "Team A" }, "team_t": { "score": 2, "consecutive_round_losses": 3, "timeouts_remaining": 2, "matches_won_this_series": 0, "name": "Team B" }, "num_matches_to_win_series": 1, "current_spectators": 0, "souvenirs_total": 0, "round_wins": { "1": "ct_win_time", "2": "t_win_elimination", "3": "ct_win_elimination", "4": "ct_win_defuse", "5": "t_win_bomb" } }, "round": { "phase": "live" }, "player": { "steamid": "76561198000000001", "name": "Player1", "team": "CT", "activity": "playing", "state": { "health": 87, "armor": 50, "helmet": true, "flashed": 0, "smoked": 0, "burning": 0, "money": 2400, "round_kills": 2, "round_killhs": 1, "round_totaldmg": 85, "equip_value": 3100 }, "spectarget": "free", "position": "100, -700, 0", "forward": "0, 1, 0" }, "allplayers": { "76561198000000001": { "name": "Player1", "team": "CT", "observer_slot": 1, "match_stats": { "kills": 8, "assists": 2, "deaths": 1, "mvps": 2, "score": 1650 }, "weapons": { "0": { "name": "weapon_ak47", "paintkit": "default", "ammo_clip": 30, "ammo_clip_max": 30, "ammo_reserve": 60, "state": "active" } }, "state": { "health": 87, "armor": 50, "helmet": true, "flashed": 0, "smoked": 0, "burning": 0, "money": 2400, "round_kills": 2, "round_killhs": 1, "round_totaldmg": 85, "equip_value": 3100 }, "position": "100, -700, 0", "forward": "0, 1, 0" } }, "bomb": { "state": "carried", "player": "76561198000000002", "position": "100, -700, 0" }, "phase_countdowns": { "phase": "live", "phase_ends_in": "60.0" } } ``` -------------------------------- ### Create a Basic GSI Server with Express Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Set up an Express server to listen for POST requests at the /gsi endpoint. This server will digest the incoming game state data and can emit custom events. ```typescript import express from 'express'; import { CSGOGSI } from 'csgogsi'; const app = express(); const gsi = new CSGOGSI(); app.use(express.urlencoded({ extended: true })); app.post('/gsi', (req, res) => { gsi.digest(req.body); res.sendStatus(200); }); gsi.on('roundEnd', (score) => { console.log(`${score.winner.name} wins! ${score.winner.score}-${score.loser.score}`); }); gsi.on('bombPlant', (player) => { console.log(`${player.name} planted the bomb!`); }); app.listen(3000); ``` -------------------------------- ### on('event', callback) Source: https://github.com/osztenkurden/csgogsi/blob/master/README.md Sets up a listener for specific game events. When an event occurs, the provided callback function is executed with the event data. ```APIDOC ## on(event, callback) ### Description Sets listener for given event (check them below). ### Method Event Listener ### Endpoint N/A ### Parameters #### Path Parameters - **event** (string) - Required - The name of the event to listen for (e.g., 'roundEnd', 'bombPlant'). - **callback** (function) - Required - The function to execute when the event is triggered. ### Request Example ```javascript GSI.on('roundEnd', score => { console.log(`Team ${score.winner.name} win!`); }); ``` ### Response N/A (This method sets up event listeners, it does not return data directly.) ``` -------------------------------- ### Kill Source: https://github.com/osztenkurden/csgogsi/blob/master/README.md Triggered when a player gets a kill. ```APIDOC ## Event: kill ### Description This event is triggered when a player achieves a kill. ### Callback Signature `(kill: KillEvent) => {}` ``` -------------------------------- ### Build CSGOGSI Project Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Commands to compile, test, and lint the CSGOGSI project. ```bash npm run build # Compiles tsc/ to dist/index.mjs npm test # Runs test suite npm run lint # Lints code ``` -------------------------------- ### Main Methods Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/INDEX.md Core methods available for interacting with the CSGOGSI library. ```APIDOC ## Main Methods ### `new CSGOGSI()` **Description**: Creates a new instance of the CSGOGSI parser. ### `digest(raw)` **Description**: Parses raw GSI data into a structured `CSGO` object. **Parameters**: - `raw` (string): The raw JSON data received from the game. **Returns**: - `CSGO | null`: The parsed game state object, or null if parsing fails. ### `digestMIRV(raw, type)` **Description**: Parses kill or damage event data, typically from MIRV. **Parameters**: - `raw` (string): The raw event data. - `type` (string): The type of event ('kill' or 'hurt'). **Returns**: - `KillEvent | HurtEvent | null`: The parsed event object, or null if parsing fails. ### `on(event, handler)` **Description**: Registers an event listener. **Parameters**: - `event` (string): The name of the event to listen for. - `handler` (Function): The callback function to execute when the event is fired. **Returns**: - `this`: The CSGOGSI instance for chaining. ### `once(event, handler)` **Description**: Registers a one-time event listener that will be removed after the first execution. **Parameters**: - `event` (string): The name of the event to listen for. - `handler` (Function): The callback function to execute. **Returns**: - `this`: The CSGOGSI instance for chaining. ### `off(event, handler)` **Description**: Removes an event listener. **Parameters**: - `event` (string): The name of the event to remove. - `handler` (Function): The specific handler function to remove. **Returns**: - `this`: The CSGOGSI instance for chaining. ### `findSite(map, pos)` **Description**: Detects the bomb site ('A', 'B', or null) based on the map and player position. **Parameters**: - `map` (string): The name of the current map. - `pos` (object): The player's position object. **Returns**: - `'A' | 'B' | null`: The detected bomb site, or null if not within a known site area. ``` -------------------------------- ### CSGOGSI Constructor Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/api-reference.md Initializes a new instance of the CSGOGSI class with default settings. ```APIDOC ## Constructor CSGOGSI ### Description Creates a new CSGOGSI instance with default settings. ### Parameters None ### Returns `CSGOGSI` - A new instance of the CSGOGSI class. ### Example ```typescript import { CSGOGSI } from 'csgogsi'; const gsi = new CSGOGSI(); ``` ``` -------------------------------- ### Configure Counter-Strike for GSI Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Create a gamestate_integration_gsi.cfg file in the specified Counter-Strike directory. This file configures which game state data is sent to your server. ```cfg "CS:GO GSI Configuration" { "uri" "http://localhost:3000/gsi" "data" { "provider" "1" "map" "1" "round" "1" "player_id" "1" "allplayers_id" "1" "allplayers_state" "1" "allplayers_weapons" "1" "allplayers_match_stats" "1" "bomb" "1" "phase_countdowns" "1" } } ``` -------------------------------- ### Get Raw Listener Descriptors Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/api-reference.md The `rawListeners` method returns an array of raw event descriptors for a specific event. ```typescript const killListeners = gsi.rawListeners('kill'); ``` -------------------------------- ### Get Registered Listeners for an Event Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/api-reference.md Use `listeners` to retrieve an array of all registered listener functions for a given event name. ```typescript const roundEndListeners = gsi.listeners('roundEnd'); ``` -------------------------------- ### Project File Dependencies Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/MANIFEST.md Visualizes the file dependencies within the CSGOGSI project, showing which files reference others and for what purpose. Useful for understanding project structure and relationships. ```text 00-START-HERE.md ├── References all other files └── Links to specific sections INDEX.md ├── References all other files └── Provides navigation maps README.md ├── Uses types.md for data structure overview ├── Uses events.md for event architecture └── Uses configuration.md for setup api-reference.md ├── Describes classes and methods ├── Uses types.md for parameter/return types └── Uses configuration.md for properties types.md ├── Defines all exported types └── Uses raw-types.md as input reference events.md ├── Uses types.md for event parameter types └── References api-reference.md for event triggering configuration.md ├── Describes instance properties ├── Uses types.md for type definitions └── Uses README.md for context raw-types.md ├── Defines raw Counter-Strike types └── References types.md for parsed equivalents ``` -------------------------------- ### Get Maximum Event Listeners Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/configuration.md Retrieve the current maximum listener setting per event using the `getMaxListeners` method. ```typescript getMaxListeners(): number ``` ```typescript console.log(`Max listeners: ${gsi.getMaxListeners()}`); ``` -------------------------------- ### Listen for freezetimeStart Event Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/events.md Use this event to execute code when freezetime begins, typically between rounds. No callback parameters are provided. ```typescript gsi.on('freezetimeStart', () => { console.log('Freezetime! Prepare your positions.'); }); ``` -------------------------------- ### Initialize CSGOGSI Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/configuration.md Instantiate the CSGOGSI class. All configuration is done via property assignment after creation. ```typescript import { CSGOGSI } from 'csgogsi'; const gsi = new CSGOGSI(); // Configure after construction gsi.overtimeMR = 5; // Custom overtime rounds gsi.regulationMR = 15; // Custom regulation rounds ``` -------------------------------- ### Configure CSGOGSI Instance Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/README.md Instantiate CSGOGSI without parameters and configure it post-construction. Set regulation and overtime rounds, custom team/player data, and event listener limits. ```typescript const gsi = new CSGOGSI(); // Regulation and overtime rounds (for round history calculation) gsi.regulationMR = 15; // Matches regulation rounds gsi.overtimeMR = 3; // Matches overtime structure // Custom team data gsi.teams.left = { id: '...', name: '...', ... }; gsi.teams.right = { id: '...', name: '...', ... }; // Custom player data gsi.players = [ { steamid: '...', name: '...', ... } ]; // Event listener limits gsi.setMaxListeners(50); ``` -------------------------------- ### Handle Kill Events in TypeScript Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/events.md Listen for 'kill' events to get details about player deaths. The event is triggered by digestMIRV with 'player_death'. ```typescript gsi.on('kill', (kill) => { let info = `${kill.victim.name} killed by ${kill.killer?.name}`; if (kill.headshot) info += ' [HS]'; if (kill.wallbang) info += ' [WB]'; if (kill.noscope && kill.weapon.includes('sniper')) info += ' [NS]'; console.log(info); }); ``` -------------------------------- ### freezetimeStart Event Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/events.md Emitted when freezetime begins, typically between rounds. It does not have any callback parameters. ```APIDOC ## Event: freezetimeStart ### Description Emitted when freezetime begins (between rounds). ### Callback Parameter None ### Fired When `phase_countdowns.phase` becomes `'freezetime'` ### Example ```typescript gsi.on('freezetimeStart', () => { console.log('Freezetime! Prepare your positions.'); }); ``` ``` -------------------------------- ### Digest CSGOGSI Raw Data Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/raw-types.md Example of how to process raw GSI data received from a POST request. It checks if the parsed data is complete before proceeding. ```typescript const raw = req.body; // From POST request const parsed = gsi.digest(raw); if (!parsed) { // Incomplete data (e.g., in menu) return; } ``` -------------------------------- ### Basic CSGOGSI Usage with Express Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/README.md Set up an Express server to receive and process GSI data, and listen for game events like round end, bomb plants, and kills. ```typescript import express from 'express'; import { CSGOGSI } from 'csgogsi'; const app = express(); const gsi = new CSGOGSI(); app.use(express.urlencoded({ extended: true })); // Receive GSI data from Counter-Strike app.post('/gsi', (req, res) => { const state = gsi.digest(req.body); if (state) { console.log(`Round ${state.map.round}: ${state.phase_countdowns.phase}`); } res.sendStatus(200); }); // Listen to events gsi.on('roundEnd', (score) => { console.log(`${score.winner.name} wins! Score: ${score.winner.score}-${score.loser.score}`); }); gsi.on('bombPlant', (player) => { console.log(`${player.name} planted the bomb!`); }); gsi.on('kill', (kill) => { console.log(`${kill.victim.name} killed by ${kill.killer?.name}`); }); app.listen(3000); ``` -------------------------------- ### Initialize CSGOGSI Instance Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/INDEX.md Create a new instance of the CSGOGSI class. You can also configure properties like regulation and overtime rounds per half. ```typescript const gsi = new CSGOGSI(); gsi.regulationMR = 15; gsi.overtimeMR = 3; ``` -------------------------------- ### Get Event Names Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/api-reference.md Retrieves an array of all event names that currently have at least one listener attached. Useful for debugging or understanding active event subscriptions. ```typescript eventNames(): EventNames[] ``` -------------------------------- ### Utility Functions for Data Mapping and Calculations Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Demonstrates the usage of utility functions for mapping Steam IDs to player objects, calculating game-specific values like half or round win status, and finding bomb sites on a given map. ```typescript // Parse raw data into typed objects const mapper = mapSteamIDToPlayer(raw.allplayers, teams, extensions); const player: Player = mapper('76561198012345678'); // Utility calculations const half: number = getHalfFromRound(round, 15, 3); const wonRound: boolean = didTeamWinThatRound(team, round, side, current, 15, 3); // Find bomb sites const site: 'A' | 'B' | null = CSGOGSI.findSite('de_mirage', [100, -700, 0]); ``` -------------------------------- ### Handle Round End Event Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Listen for the 'roundEnd' event to get the final score of a round. The handler receives a Score object containing winner and loser details. ```typescript gsi.on('roundEnd', (score: Score) => { console.log(`Winner: ${score.winner.name}`); console.log(`Score: ${score.winner.score}-${score.loser.score}`); }); ``` -------------------------------- ### CSGORaw Type Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/types.md Raw game state directly from Counter-Strike GSI. Fields are optional as they may not be sent in menu/loading states. ```APIDOC ## Type: CSGORaw ### Description Raw game state directly from Counter-Strike GSI. Fields are optional as they may not be sent in menu/loading states. ### Fields - `provider` (Provider): Game provider metadata - `map` (MapRaw): Raw map state - `round` (RoundRaw): Raw round state - `player` (PlayerObservedRaw): Raw observed player data - `allplayers` (PlayersRaw): Raw all players dictionary - `bomb` (BombRaw): Raw bomb state - `grenades` ({ [key: string]: GrenadeRaw }): Raw grenades by ID - `phase_countdowns` (PhaseRaw): Raw phase information - `auth` ({ token: string }): Optional auth token **Used By:** `digest()` method parameter, `raw` event ``` -------------------------------- ### on Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/api-reference.md Registers a listener for a specific event. The listener will be called every time the event is emitted. Returns the instance for chaining. ```APIDOC ## on ### Description Registers a listener for an event. ### Method Signature ```typescript on(eventName: K, listener: Callback): this ``` ### Parameters #### Path Parameters - **eventName** (EventNames) - Required - Event name from the Events interface - **listener** (Callback) - Required - Callback function matching the event signature ### Returns `this` — Returns the instance for chaining ### Example ```typescript gsi.on('roundEnd', (score) => { console.log(`Team ${score.winner.name} wins round!`); }).on('matchEnd', (score) => { console.log(`Match over! Winner: ${score.winner.name}`); }); ``` ``` -------------------------------- ### Get Round Outcome Information Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/api-reference.md Extracts and parses detailed information about a specific round's outcome from the GSI round history. Returns null if the specified round is not found in the history. ```typescript getRoundWin( mapRound: number, teams: { ct: Team; t: Team }, roundWins: RoundWins, round: number, regulationMR: number, overtimeMR: number ): RoundInfo | null ``` -------------------------------- ### Import CSGOGSI Utility Functions Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/INDEX.md Import utility functions for common tasks such as mapping Steam IDs to player objects, parsing team data, determining game halves, checking round wins, and parsing grenade information. ```typescript import { mapSteamIDToPlayer, parseTeam, getHalfFromRound, didTeamWinThatRound, getRoundWin, parseGrenades } from 'csgogsi'; ``` -------------------------------- ### Process MIRV Kill and Hurt Events Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/README.md Use digestMIRV() to process kill and hurt events from the MIRV GSI plugin for more reliable data. Ensure the MIRV plugin is installed and prior digest() calls have established player context. ```typescript // From MIRV kill event const kill = gsi.digestMIRV(mirvData, 'player_death'); ``` ```typescript // From MIRV hurt event const hurt = gsi.digestMIRV(mirvData, 'player_hurt'); ``` -------------------------------- ### All Events Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/INDEX.md List of all events that can be listened to, along with their callbacks and triggers. ```APIDOC ## All Events ### `data` **Description**: Fired when the game state has been updated and processed. **Callback**: `(data: CSGO) => void` ### `raw` **Description**: Fired with the raw, unprocessed data received from the game, before any parsing. **Callback**: `(data: CSGORaw) => void` ### `roundEnd` **Description**: Fired when the current round ends. **Callback**: `(score: Score) => void` ### `matchEnd` **Description**: Fired when the entire match (map) ends. **Callback**: `(score: Score) => void` ### `freezetimeStart` **Description**: Fired when the freezetime period begins. **Callback**: `() => void` ### `freezetimeEnd` **Description**: Fired when the freezetime period ends. **Callback**: `() => void` ### `intermissionStart` **Description**: Fired when the intermission (halftime) begins. **Callback**: `() => void` ### `intermissionEnd` **Description**: Fired when the intermission ends and the second half starts. **Callback**: `() => void` ### `timeoutStart` **Description**: Fired when a team calls a timeout. **Callback**: `(team: Team) => void` ### `timeoutEnd` **Description**: Fired when a timeout ends. **Callback**: `() => void` ### `mvp` **Description**: Fired when a Most Valuable Player (MVP) is awarded. **Callback**: `(player: Player) => void` ### `bombPlantStart` **Description**: Fired when a player begins planting the bomb. **Callback**: `(player: Player) => void` ### `bombPlant` **Description**: Fired when the bomb has been successfully planted. **Callback**: `(player: Player) => void` ### `bombPlantStop` **Description**: Fired when the bomb plant action is interrupted. **Callback**: `(player: Player) => void` ### `bombExplode` **Description**: Fired when the bomb explodes. **Callback**: `() => void` ### `defuseStart` **Description**: Fired when a player begins defusing the bomb. **Callback**: `(player: Player) => void` ### `defuseStop` **Description**: Fired when the bomb defuse action is interrupted. **Callback**: `(player: Player) => void` ### `bombDefuse` **Description**: Fired when the bomb has been successfully defused. **Callback**: `(player: Player) => void` ### `kill` **Description**: Fired when a kill event occurs, typically parsed from MIRV data. **Callback**: `(kill: KillEvent) => void` ### `hurt` **Description**: Fired when a damage event occurs, typically parsed from MIRV data. **Callback**: `(hurt: HurtEvent) => void` ### `newListener` **Description**: Fired when a new event listener is added. **Callback**: `(event: string, fn: Function) => void` ### `removeListener` **Description**: Fired when an event listener is removed. **Callback**: `(event: string, fn: Function) => void` ``` -------------------------------- ### Provider Type Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/types.md Game version and authentication information. ```APIDOC ## Type: Provider ### Description Game version and authentication information. ### Fields - `name` (string): Always `'Counter-Strike: Global Offensive'` - `appid` (number): Always `730` (CS:GO app ID) - `version` (number): Game version number - `steamid` (string): Spectator's Steam ID - `timestamp` (number): Unix timestamp when data was sent ``` -------------------------------- ### intermissionStart Event Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/events.md Emitted when intermission begins, typically at halftime. It does not have any callback parameters. ```APIDOC ## Event: intermissionStart ### Description Emitted when intermission begins (halftime). ### Callback Parameter None ### Fired When `map.phase` becomes `'intermission'` ### Example ```typescript gsi.on('intermissionStart', () => { console.log('Intermission! Teams swap sides.'); }); ``` ``` -------------------------------- ### Listen for intermissionStart Event Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/events.md Emitted when the intermission phase begins, usually at halftime. This event does not include callback parameters. ```typescript gsi.on('intermissionStart', () => { console.log('Intermission! Teams swap sides.'); }); ``` -------------------------------- ### on(event, handler) Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Registers an event listener. The handler function will be called when the specified event is triggered. Returns the CSGOGSI instance for chaining. ```typescript /** * Registers an event listener. * @param event The name of the event to listen for. * @param handler The callback function to execute when the event is triggered. * @returns The CSGOGSI instance for chaining. */ gsi.on(event: string, handler: Function): this; ``` -------------------------------- ### PlayerRaw Interface Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/raw-types.md Represents detailed raw data for a single player. Includes match statistics, weapons, and current in-game state. Note that 'steamid' may be missing for coaches. ```typescript interface PlayerRaw { steamid?: string; name: string; clan?: string; observer_slot?: number; team: Side; match_stats: { kills: number; assists: number; deaths: number; mvps: number; score: number; }; weapons: { [key: string]: WeaponRaw; }; state: { health: number; armor: number; helmet: boolean; defusekit?: boolean; flashed: number; smoked?: number; burning: number; money: number; round_kills: number; round_killhs: number; round_totaldmg: number; equip_value: number; }; position: string; forward: string; } ``` -------------------------------- ### Data incoming Source: https://github.com/osztenkurden/csgogsi/blob/master/README.md Triggered when new game data is received. ```APIDOC ## Event: data ### Description This event is triggered when new game state data is incoming from CS:GO. ### Callback Signature `(data: CSGO Parsed) => {}` ``` -------------------------------- ### Real-Time Spectator Overlay with CS:GO GSI Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/README.md Listen for 'data' events to receive game state updates and emit them via WebSocket for a spectator overlay. Requires a WebSocket server to be running. ```typescript gsi.on('data', (state) => { webSocket.emit('update', { map: state.map.name, round: state.map.round, score: [state.map.team_ct.score, state.map.team_t.score], players: state.players.map(p => ({ name: p.name, health: p.state.health, money: p.state.money })) }); }); ``` -------------------------------- ### Real-time Spectator Feed with CSGOGSI Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Listen for 'data' events to process real-time game state. Requires the CSGO type definition. ```typescript gsi.on('data', (state: CSGO) => { broadcast({ map: state.map.name, round: state.map.round, phase: state.phase_countdowns.phase, players: state.players.map(p => ({ name: p.name, team: p.team.side, health: p.state.health, money: p.state.money })) }); }); ``` -------------------------------- ### Counter-Strike GSI Configuration Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/README.md Configuration file for Counter-Strike: Global Offensive to send GSI data to a local server. Ensure this file is placed in the correct CS:GO config directory. ```cfg "CS:GO GSI Configuration" { "uri" "http://localhost:3000/gsi" "timeout" "5.0" "buffer" "0.1" "throttle" "0.016" "heartbeat" "10.0" "data" { "provider" "1" "map" "1" "round" "1" "player_id" "1" "allplayers_id" "1" "allplayers_state" "1" "allplayers_weapons" "1" "allplayers_match_stats" "1" "bomb" "1" "phase_countdowns" "1" "grenades" "1" } } ``` -------------------------------- ### Initialize and Parse GSI Data Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Instantiate the CSGOGSI class and use the digest method to parse incoming game state data. Listen for various game events using the .on() method. ```typescript const gsi = new CSGOGSI(); // Parse GSI data from Counter-Strike const state: CSGO | null = gsi.digest(req.body); // Listen to events gsi.on('roundEnd', (score: Score) => { }); gsi.on('kill', (kill: KillEvent) => { }); gsi.on('bombPlant', (player: Player) => { }); ``` -------------------------------- ### Import CSGOGSI Types Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/INDEX.md Import all available types for working with CSGO game state data. This includes types for the overall game state, raw data, teams, players, scores, and various events. ```typescript import type { CSGO, CSGORaw, Team, Player, Score, KillEvent, HurtEvent, Bomb, Grenade, // ... and 40+ more } from 'csgogsi'; ``` -------------------------------- ### prependListener Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/api-reference.md Adds a listener to the beginning of the listener list for a given event, ensuring it is called before any other listeners for that event. Returns the instance for chaining. ```APIDOC ## prependListener ### Description Adds a listener to the beginning of the listener list, so it fires before other listeners. ### Method Signature ```typescript prependListener(eventName: K, listener: Callback): this ``` ### Parameters #### Path Parameters - **eventName** (EventNames) - Required - Event name - **listener** (Callback) - Required - Callback function ### Returns `this` — Returns the instance for chaining ``` -------------------------------- ### CSGOGSI with Player Extensions Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/configuration.md Extend player data by mapping fetched player information to the expected CSGOGSI player object structure. This includes fields like ID, SteamID, name, and custom metadata. ```typescript const gsi = new CSGOGSI(); // Inject player data from your database const players = await fetchPlayersFromDB(); gsi.players = players.map(p => ({ id: p.id, steamid: p.steamid, name: p.name, realName: p.realName, country: p.country, avatar: p.avatar, extra: p.metadata })); ``` -------------------------------- ### Utility Functions Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/INDEX.md Helper functions for parsing and analyzing game state data. ```APIDOC ## Utility Functions ### `mapSteamIDToPlayer(steamID: string, team: Team): Player` **Description:** Creates a `Player` object mapper using a SteamID and team context. **Method:** Utility Function **Parameters:** - `steamID` (string) - Required - The SteamID of the player. - `team` (Team) - Required - The team the player belongs to. **Returns:** `Player` - A player object. ### `parseTeam(teamData: any, allPlayers: Player[]): Team` **Description:** Parses raw team data into a structured `Team` object. **Method:** Utility Function **Parameters:** - `teamData` (any) - Required - The raw data for the team. - `allPlayers` (Player[]) - Required - An array of all player objects for context. **Returns:** `Team` - The parsed team object. ### `getHalfFromRound(roundPhase: string): 1 | 2 | null` **Description:** Determines the half of the match based on the current round phase. **Method:** Utility Function **Parameters:** - `roundPhase` (string) - Required - The current phase of the round (e.g., 'live', 'freezetime'). **Returns:** `1 | 2 | null` - The half number (1 or 2), or null if not applicable. ### `didTeamWinThatRound(team: Team, roundInfo: Round): boolean` **Description:** Checks if a given team won the specified round. **Method:** Utility Function **Parameters:** - `team` (Team) - Required - The team to check. - `roundInfo` (Round) - Required - Information about the round. **Returns:** `boolean` - True if the team won the round, false otherwise. ### `getRoundWin(roundInfo: Round): RoundOutcome` **Description:** Extracts the outcome of a round from the round information. **Method:** Utility Function **Parameters:** - `roundInfo` (Round) - Required - Information about the round. **Returns:** `RoundOutcome` - The outcome of the round. ### `parseGrenades(grenadeData: any): Grenade[]` **Description:** Parses raw grenade data into an array of `Grenade` objects. **Method:** Utility Function **Parameters:** - `grenadeData` (any) - Required - The raw data object containing grenade information. **Returns:** `Grenade[]` - An array of parsed grenade objects. ``` -------------------------------- ### prependOnceListener Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/api-reference.md Adds a one-time listener to the beginning of the listener list for a given event. This listener will be called only once, before any other listeners, and then removed. Returns the instance for chaining. ```APIDOC ## prependOnceListener ### Description Adds a one-time listener to the beginning of the listener list. ### Method Signature ```typescript prependOnceListener(eventName: K, listener: Callback): this ``` ### Parameters #### Path Parameters - **eventName** (EventNames) - Required - Event name - **listener** (Callback) - Required - Callback function ### Returns `this` — Returns the instance for chaining ``` -------------------------------- ### Utility Functions Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/MANIFEST.md Helper functions for parsing and processing game state data. ```APIDOC ## Utility Functions - **mapSteamIDToPlayer(steamID, players)** - Description: Maps a SteamID to a player object from a given player list. - Parameters: `steamID` (string), `players` (object) - Return Type: `object | null` - **parseTeam(teamData)** - Description: Parses raw team data into a structured format. - Parameters: `teamData` (object) - Return Type: `object` - **getHalfFromRound(roundNumber)** - Description: Determines the half of the match based on the round number. - Parameters: `roundNumber` (number) - Return Type: `number` - **didTeamWinThatRound(team, round)** - Description: Checks if a specific team won the given round. - Parameters: `team` (object), `round` (object) - Return Type: `boolean` - **getRoundWin(round)** - Description: Determines the winner of a round. - Parameters: `round` (object) - Return Type: `string` - **parseGrenades(grenadesData)** - Description: Parses raw grenade data into a structured format. - Parameters: `grenadesData` (object) - Return Type: `object[]` ``` -------------------------------- ### once(event, handler) Source: https://github.com/osztenkurden/csgogsi/blob/master/_autodocs/00-START-HERE.md Registers a one-time event listener. The handler function will be called only the first time the specified event is triggered. Returns the CSGOGSI instance for chaining. ```typescript /** * Registers a one-time event listener. * @param event The name of the event to listen for. * @param handler The callback function to execute once when the event is triggered. * @returns The CSGOGSI instance for chaining. */ gsi.once(event: string, handler: Function): this; ```