andrewda / hltv-livescore

A Node.js wrapper for the HLTV scorebot
MIT License
71 stars 8 forks source link
csgo hacktoberfest hltv scoreboard

Due to a lack of resources, this project has been mostly abandoned. Please see gigobyte/HLTV for a popular and more up-to-date HLTV API. If anyone would like to take over maintenance for this project, please contact me.


HLTV Livescore

A simple Node.js library to interface with HLTV's live scorebot.

NPM Version Downloads Build Codacy Steam Donate

Contents

Introduction

This module is based on @Nols1000's original version, created back in May of 2015. It is packed full of features, but was never updated to the newest version of HLTV's scorebot. The purpose of this version is to be more of a wrapper for HLTV, and to incorporate all of the features available with the new scorebot.

Getting Started

Install with npm:

$ npm install hltv-livescore

Usage:

var Livescore = require('hltv-livescore');
var live = new Livescore({
    listid: 2299033
});

live.on('kill', function(data) {
    console.log(data.killer.name, 'killed', data.victim.name, 'with', data.weapon, data.headshot ? '(headshot)' : '');
});

Methods

Constructor([options])

Constructs a new Livescore. You will be automatically connected to the HLTV scorebot server. The game with the specified listid will be automatically started if provided. If not provided, you must specify them using them using the start() method.

start([options][, callback])

Start the game with the specified listid. If provided in the Constructor, the listid is not required. An error will be thrown if you are not connected to the HLTV scorebot server before calling this method.

getPlayers(callback)

Retrieve all players connected to the server.

getTeams(callback)

Retrieve both teams connected to the server.

setTime(time)

Set the scoreboard to a new time.

getTime(callback)

Retrieve the time remaining.

Events

Events emit an object containing the parameters listed under each event.

connected

Emitted when we successfully connect to the HLTV Socket.io server.

started

Emitted immediately before the first scoreboard event is emitted.

log

Emitted whenever HLTV feels like giving us logs (after kills, round events, etc).

time

Emitted every time the timer on the scoreboard is updated.

scoreboard

Emitted whenever HLTV sends us a scoreboard update. The scoreboard may not be any different from the last update.

kill

Emitted after every kill.

suicide

Emitted after a player commits suicide.

bombPlanted

Emitted when the bomb is planted.

bombDefused

Emitted when the bomb is defused.

roundStart

Emitted at the start of every round.

roundEnd

Emitted at the end of every round.

playerJoin

Emitted when a player joins the server.

playerQuit

Emitted when a player leaves the server.

mapChange

Emitted when the map is changed.

restart

Emitted when the score is restarted

Classes

Player

Example:

Player {
    steamid: [Object],
    hltvid: 11654,
    name: 'almazer1',
    alive: true,
    money: 12300,
    rating: 1.16,
    kills: 19,
    assists: 4,
    deaths: 17,
    team: [Object]
}

Team

Example:

Team {
    id: 6921,
    name: 'Vesuvius',
    score: 16,
    side: 1,
    players: [Array],
    history: [Object]
}

Round

Example:

Round {
    type: 6
    round: 12
}

Enums

There are numerous enums available for your use. All enums are located in the /resources/ directory.

EOption

Primarily for internal use. Specifies options about the module.

ERoundType

Specifies how a team ended the round.

ESide

Specifies team constants.

Examples