Modules

Docs / API / Modules / votes

Votes

Admin & chat

@s2script/sdk/votes

chat-ballot voting with revote + an optional live center tally.

5 exports

Import

import { VoteResult } from "@s2script/sdk/votes";

Author-time types ship in the npm package; the engine injects the runtime at plugin load. Add @s2script/sdk to your plugin's dependencies.

API reference

Generated from the shipped type definitions.

interface
VoteResult

The outcome delivered to VoteConfig.onEnd when a vote ends.

readonly winner: number | null
0-based index of the winning option, or null on a tie or zero votes.
readonly counts: number[]
Per-option vote counts, parallel to VoteConfig.options.
readonly total: number
Total votes cast.
interface
VoteConfig

Configuration for Vote.start.

question: string
The question shown to voters.
options: string[]
2..9 options (chat votes are single-digit).
duration: number
seconds.
showLiveTally?: boolean
show a live center tally (default false — the SM chat-only way).
onEnd: (result: VoteResult) => void
Called once when the vote ends (or is exhausted), with the tallied VoteResult. It may start a new vote (the lock is released first).
interface
VoteTally

A per-tick snapshot of an in-progress vote, handed to a VoteTallyRenderer.

question: string
The question being voted on.
options: { label: string; count: number }[]
Each option's label and current vote count.
total: number
Total votes cast so far.
secondsLeft: number
Seconds remaining before the vote ends.
interface
VoteTallyRenderer

A live-tally display backend for votes — registered via Vote.registerTallyRenderer.

show(slot: number, tally: VoteTally): void
Show/update the running tally for slot.
clear(slot: number): void
Remove the tally display for slot (the vote ended or the player left).
const
Vote

The voting entry point — one active chat-ballot vote at a time, tallied on close.

import { Vote } from "@s2script/sdk/votes";
Vote.start({
  question: `Kick ${name}?`,
  options: ["Yes", "No"],
  duration: 20,
  showLiveTally: true,
  onEnd: (r) => {
    if (r.winner === 0 && r.counts[0] > r.total / 2) kick(name);
  },
});
start(config: VoteConfig): boolean
Start a vote (chat ballot to all connected players). Returns false if one is already active.
isActive(): boolean
True while a vote is running (the single-vote lock is held).
cancel(): void
Abort the active vote (no onEnd).
registerTallyRenderer(renderer: VoteTallyRenderer): void
Register the live-tally renderer (the CS2 center-HTML renderer).
Back to modules All packages

s2script — Source 2 plugin framework

GitHub