Scripting API
Jump to navigation
Jump to search



This is the cs_script API for Counter-Strike 2.
Classes
Instance
The top level API provided to scripts attached to a point_script entity.
Access these functions by importing Instance
from "cs_script/point_script".
Methods
Function | Signature | Description |
---|---|---|
ClientCommand | ClientCommand(slot: number, command: string): void
|
Issue the specified command to the specified client. |
ConnectOutput | ConnectOutput(target: Entity, output: string, callback: (arg: EntIOValue, context: EntIOContext) => any): number | undefined
|
Connect the output of an entity to a callback. The return value is a connection id that can be used in DisconnectOutput
|
DebugScreenText | DebugScreenText(text: string, x: number, y: number, duration: number, color: Color): void
|
Print some text to the game window. |
DebugSphere | DebugSphere(center: Vector, radius: number, duration: number, color: Color): void
|
Draw a wire sphere in the world. |
DisconnectOutput | DisconnectOutput(connectionId: number): void
|
Use a connection id to disconnect the output of an entity from a callback. |
EntFireAtName | EntFireAtName(name: string, input: string, value?: EntIOValue, delay?: number): void
|
Fire the input on all targets matching the specified name. |
EntFireAtTarget | EntFireAtTarget(target: Entity, input: string, value?: EntIOValue, delay?: number): void
|
Fire the input on the specified target. |
FindEntitiesByClass | FindEntitiesByClass(className: string): Entity[]
|
Find entities of the specified class name. |
FindEntityByClass | FindEntityByClass(className: string): Entity | undefined
|
Find the first entity of the specified class name. |
FindEntitiesByName | FindEntitiesByName(name: string): Entity[]
|
Find entities matching the specified name. |
FindEntityByName | FindEntityByName(name: string): Entity | undefined
|
Find the first entity matching the specified name. |
GetGameMode | GetGameMode(): number
|
Get the current Game Mode. Todo: Document return values and their meaning.
|
GetGameTime | GetGameTime(): number
|
Get the game time in seconds. |
GetGameType | GetGameType(): number
|
Get the current Game Type. Todo: Document return values and their meaning.
|
GetMapName | GetMapName(): string
|
Get the name of the current map. |
GetPlayerController | GetPlayerController(slot: number): CSPlayerController | undefined
|
Get the player controller in the given slot. |
GetRoundsPlayed | GetRoundsPlayed(): number
|
Get the number of rounds played in the current game. |
GetTraceHit | GetTraceHit(start: Vector, end: Vector, config?: TraceConfig): TraceResult
|
Trace along a line and detect collisions. |
IsWarmupPeriod | IsWarmupPeriod(): boolean
|
Get if the game is currently in a Warmup period. |
Msg | Msg(text: string): void
|
Log a message to the console. |
ServerCommand | ServerCommand(command: string): void
|
Issue a command on the server. |
SetNextThink | SetNextThink(time: number): void
|
Set when the think callback should next be called. |
Hooks
Passing callbacks with fitting signatures into these functions causes them to be called at the appropriate times.
Function | Signature | Description |
---|---|---|
OnActivate | OnActivate(callback: () => void): void
|
Called when the point_script entity is activated. |
OnBeforeReload | OnBeforeReload(callback: () => any): void
|
Called in Tools mode before the script is reloaded due to changes. A returned value will be passed to the OnReload callback.
|
OnGameEvent | OnGameEvent<E extends keyof GameEventDefs>(eventName: E, callback: (args: GameEventDefs[E]) => void): void
|
Called when known game events are fired. See GameEventDefs for list of known game events.
|
OnReload | OnReload(callback: (memory: any) => void): void
|
Called in Tools mode after the script reloaded due to changes. |
OnScriptInput | OnScriptInput(name: string, callback: (context: EntIOContext) => void): void
|
Called input RunScriptInput is triggered on the point_script entity with a value that matches. |
SetThink | SetThink(callback: () => void): void
|
Called per-think. |
Entity
Methods
Function | Signature | Description |
---|---|---|
GetAbsAngles | GetAbsAngles(): QAngle
|
|
GetAbsOrigin | GetAbsOrigin(): Vector
|
|
GetAbsVelocity | GetAbsVelocity(): Vector
|
|
GetClassName | GetClassName(): string
|
|
GetEntityName | GetEntityName(): string
|
|
GetEyeAngles | GetEyeAngles(): QAngle
|
|
GetEyePosition | GetEyePosition(): Vector
|
|
GetHealth | GetHealth(): number
|
|
GetLocalAngles | GetLocalAngles(): QAngle
|
|
GetLocalOrigin | GetLocalOrigin(): Vector
|
|
GetLocalVelocity | GetLocalVelocity(): Vector
|
|
GetMaxHealth | GetMaxHealth(): number
|
|
GetTeamNumber | GetTeamNumber(): number
|
|
IsValid | IsValid(): boolean
|
|
Kill | Kill(): void
|
|
Remove | Remove(): void
|
|
SetEntityName | SetEntityName(name: string): void
|
|
SetMaxHealth | SetMaxHealth(health: number): void
|
|
SetHealth | SetHealth(health: number): void
|
|
Teleport | Teleport(newPosition: Vector | null, newAngles: QAngle | null, newVelocity: Vector | null): void
|
BaseModelEntity
- extends Entity
Methods
Function | Signature | Description |
---|---|---|
Glow | Glow(color?: Color): void
|
|
SetColor | SetColor(color: Color): void
|
|
SetModel | SetModel(modelName: string): void
|
|
SetModelScale | SetModelScale(scale: number): void
|
|
Unglow | Unglow(): void
|
CSPlayerController
- extends Entity
Methods
Function | Signature | Description |
---|---|---|
AddScore | AddScore(points: number): void
|
Add to the player's score. Negative values are allowed but the score will not go below zero. |
GetObserverPawn | GetObserverPawn(): CSObserverPawn | undefined
|
|
GetPlayerPawn | GetPlayerPawn(): CSPlayerPawn | undefined
|
|
GetPlayerSlot | GetPlayerSlot(): number
|
|
GetScore | GetScore(): number
|
|
GetWeaponDataForLoadoutSlot | GetWeaponDataForLoadoutSlot(slot: number, team?: number): CSWeaponData | undefined
|
Leave team as the default to use the player's current team. |
IsBot | IsBot(): boolean
|
|
IsObserving | IsObserving(): boolean
|
|
JoinTeam | JoinTeam(team: number): void
|
CSObserverPawn
- extends BaseModelEntity
Methods
Function | Signature | Description |
---|---|---|
GetObserverMode | GetObserverMode(): number
|
|
GetPlayerController | GetPlayerController(): CSPlayerController | undefined
|
|
SetObserverMode | SetObserverMode(nMode: number): void
|
CSPlayerPawn
- extends BaseModelEntity
Methods
Function | Signature | Description |
---|---|---|
DestroyWeapon | DestroyWeapon(target: CSWeaponBase | undefined): void
|
|
DestroyWeapons | DestroyWeapons(): void
|
|
FindWeapon | FindWeapon(name: string): CSWeaponBase | undefined
|
|
FindWeaponBySlot | FindWeaponBySlot(slot: CSGearSlot): CSWeaponBase | undefined
|
|
GetActiveWeapon | GetActiveWeapon(): CSWeaponBase | undefined
|
|
GetArmor | GetArmor(): number
|
|
GetPlayerController | GetPlayerController(): CSPlayerController | undefined
|
|
GiveNamedItem | GiveNamedItem(name: string, autoDeploy?: boolean): void
|
|
SetArmor | SetArmor(value: number): void
|
|
SwitchToWeapon | SwitchToWeapon(target: CSWeaponBase | undefined): void
|
CSWeaponBase
- extends BaseModelEntity
Methods
Function | Signature | Description |
---|---|---|
GetData | GetData(): CSWeaponData
|
CSWeaponData
Methods
Function | Signature | Description |
---|---|---|
GetName | GetName(): string
|
|
GetPrice | GetPrice(): number
|
|
GetType | GetType(): CSWeaponType
|
PointTemplate
- extends Entity
Methods
Function | Signature | Description |
---|---|---|
ForceSpawn | ForceSpawn(origin?: Vector, angle?: QAngle): Entity[] | undefined
|
Interfaces
GameEventDefs
Property | Type | Description |
---|---|---|
bomb_defused | { userid: number }
|
|
bomb_planted | { userid: number }
|
|
player_activate | { userid: number }
|
|
player_connect | { userid: number, name: string, bot: boolean }
|
|
player_death | { userid: number, attacker: number }
|
|
player_disconnect | { userid: number, reason: number }
|
|
round_end | { winner: number }
|
|
round_start | { round_number: number }
|
TraceConfig
Property | Type | Optional | Description |
---|---|---|---|
ignoreEnt | Entity
|
yes | Set to ignore collisions with an entity, typically the source of a trace. |
interacts | TraceInteracts
|
yes | Defaults to trace against any solid. |
sphereRadius | number
|
yes | Set to trace a sphere with specified radius. |
TraceResult
Property | Type | Optional | Description |
---|---|---|---|
didHit | boolean
|
no | |
end | Vector
|
no | |
fraction | number
|
no | |
hitEnt | Entity | null
|
yes |
Enumerations
CSGearSlot
Name | Value | Description |
---|---|---|
INVALID | -1 | |
RIFLE | 0 | |
PISTOL | 1 | |
KNIFE | 2 | |
GRENADES | 3 | |
C4 | 4 |
CSWeaponType
Name | Value | Description |
---|---|---|
KNIFE | 0 | |
PISTOL | 1 | |
SUBMACHINEGUN | 2 | |
RIFLE | 3 | |
SHOTGUN | 4 | |
SNIPER_RIFLE | 5 | |
MACHINEGUN | 6 | |
C4 | 7 | |
TASER | 8 | |
GRENADE | 9 | |
EQUIPMENT | 10 | |
STACKABLEITEM | 11 | |
UNKNOWN | 12 |
TraceInteracts
Name | Value | Description |
---|---|---|
SOLID | 0 | |
WORLD | 1 |
Type Aliases
cs_script pre-defines a few type aliases.
Color
Signature: type Color = { r: number, g: number, b: number, a?: number }
EntIOContext
Signature: type EntIOContext = { caller?: Entity, activator?: Entity }
EntIOValue
Signature: type EntIOValue = boolean | number | string | Vector | Color | undefined
QAngle
Signature: type QAngle = { pitch: number, yaw: number, roll: number }
Vector
Signature: type Vector = { x: number, y: number, z: number }