Scripting API

From Valve Developer Community
< Counter-Strike 2 Workshop Tools
Revision as of 15:55, 2 October 2025 by TheCreator (talk | contribs) (Fix OnPlayerChat signature)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
English (en)Translate (Translate)

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(playerSlot: number, command: string): void Issue the specified command to the specified client.
ConnectOutput ConnectOutput(target: Entity, output: string, callback: (inputData: { value?: InputValue, caller?: Entity, activator?: Entity }) => 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
DebugBox DebugBox(config: { mins: Vector, maxs: Vector, duration?: number, color?: Color }): void Draw an axis aligned box in the world. Only works in dev environments.
DebugLine DebugLine(config: { start: Vector, end: Vector, duration?: number, color?: Color }): void Draw a line in the world. Only works in dev environments.
DebugScreenText DebugScreenText(config: { text: any, x: number, y: number, duration?: number, color?: Color }): void Print some text to the game window. Only works in dev environments.
DebugSphere DebugSphere(config: { center: Vector, radius: number, duration?: number, color?: Color }): void Draw a wire sphere in the world. Only works in dev environments.
DisconnectOutput DisconnectOutput(connectionId: number): void Use a connection id to disconnect the output of an entity from a callback.
EntFireAtName EntFireAtName(config: { name: string, input: string, value?: InputValue, caller?: Entity, activator?: Entity, delay?: number }): void Fire the input on all targets matching the specified names.
EntFireAtTarget EntFireAtTarget(config: { target: Entity, input: string, value?: InputValue, caller?: Entity, activator?: Entity, 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.
IsFreezePeriod IsFreezePeriod(): boolean Get if the game is currently in a Freeze period.
IsWarmupPeriod IsWarmupPeriod(): boolean Get if the game is currently in a Warmup period.
Msg Msg(text: any): 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 OnThink callback should next be run. The exact time will be on the tick nearest to the specified time, which may be earlier or later.
SetThink SetThink(callback: () => void): void Called per-think. Control when this is run using SetNextThink.
TraceBox TraceBox(trace: { start: Vector, end: Vector, mins: Vector, maxs: Vector, ignoreEntity?: Entity, ignorePlayers?: boolean }): TraceResult Trace an axis aligned bounding box along a line and detect collisions
TraceBullet TraceBullet(trace: BulletTrace): BulletTraceResult[] Trace as a bullet and detect hits and damage
TraceLine TraceLine(trace: { start: Vector, end: Vector, ignoreEntity?: Entity, ignorePlayers?: boolean }): TraceResult Trace a point along a line and detect collisions
TraceSphere TraceSphere(trace: { start: Vector, end: Vector, radius: number, ignoreEntity?: Entity, ignorePlayers?: boolean }): TraceResult Trace a sphere along a line and detect collisions

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.
OnBeforePlayerDamage OnBeforePlayerDamage(callback: (event: { player: CSPlayerPawn, damage: number, inflictor?: Entity, attacker?: Entity, weapon?: CSWeaponBase }) => BeforeDamageResult): void
OnBombDefuse OnBombDefuse(callback: (event: { plantedC4: Entity, defuser: CSPlayerPawn }) => void): void
OnBombPlant OnBombPlant(callback: (event: { plantedC4: Entity, planter: CSPlayerPawn }) => void): void
OnBulletImpact OnBulletImpact(callback: (event: { weapon: CSWeaponBase, position: Vector }) => void): void
OnGrenadeBounce OnGrenadeBounce(callback: (event: { projectile: Entity, bounces: number }) => void): void
OnGrenadeThrow OnGrenadeThrow(callback: (event: { weapon: CSWeaponBase, projectile: Entity }) => void): void
OnGunFire OnGunFire(callback: (event: { weapon: CSWeaponBase }) => void): void
OnGunReload OnGunReload(callback: (event: { weapon: CSWeaponBase }) => void): void
OnKnifeAttack OnKnifeAttack(callback: (event: { weapon: CSWeaponBase }) => void): void
OnPlayerActivate OnPlayerActivate(callback: (event: { player: CSPlayerController }) => void): void
OnPlayerChat OnPlayerChat(callback: (event: { player: CSPlayerController | undefined, text: string, team: number }) => void): void
OnPlayerConnect OnPlayerConnect(callback: (event: { player: CSPlayerController }) => void): void
OnPlayerDamage OnPlayerDamage(callback: (event: { player: CSPlayerPawn, damage: number, inflictor?: Entity, attacker?: Entity, weapon?: CSWeaponBase }) => void): void
OnPlayerDisconnect OnPlayerDisconnect(callback: (event: { playerSlot: number }) => void): void
OnPlayerJump OnPlayerJump(callback: (event: { player: CSPlayerPawn }) => void): void
OnPlayerKill OnPlayerKill(callback: (event: { player: CSPlayerPawn, inflictor?: Entity, attacker?: Entity, weapon?: CSWeaponBase }) => void): void
OnPlayerLand OnPlayerLand(callback: (event: { player: CSPlayerPawn }) => void): void
OnPlayerPing OnPlayerPing(callback: (event: { player: CSPlayerController, position: Vector }) => void): void
OnPlayerReset OnPlayerReset(callback: (event: { player: CSPlayerPawn }) => void): void
OnRoundEnd OnRoundEnd(callback: (event: { winningTeam: number }) => void): void
OnRoundStart OnRoundStart(callback: () => void): void
OnScriptInput OnScriptInput(name: string, callback: (inputData: { caller?: Entity, activator?: Entity }) => void): void Called when input RunScriptInput is triggered on the point_script entity with a parameter value that matches name.
OnScriptReload OnScriptReload<T>(config: { before?: () => T, after?: (memory: T) => void }): void Called in Tools mode when the script is reloaded due to changes. The before callback will be invoked before pre-load teardown. The after callback will be invoked after the new script is evaluated and will be passed the return value of the before callback.

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
GetGroundEntity GetGroundEntity(): Entity | undefined
GetHealth GetHealth(): number
GetLocalAngles GetLocalAngles(): QAngle
GetLocalOrigin GetLocalOrigin(): Vector
GetLocalVelocity GetLocalVelocity(): Vector
GetMaxHealth GetMaxHealth(): number
GetOwner GetOwner(): Entity | undefined
GetParent GetParent(): Entity | undefined
GetTeamNumber GetTeamNumber(): number
IsAlive IsAlive(): boolean
IsValid IsValid(): boolean
IsWorld IsWorld(): boolean
Kill Kill(): void
Remove Remove(): void
SetEntityName SetEntityName(name: string): void
SetMaxHealth SetMaxHealth(health: number): void
SetHealth SetHealth(health: number): void
SetOwner SetOwner(owner: Entity | undefined): void
SetParent SetParent(parent: Entity | undefined): void
TakeDamage TakeDamage(takeDamage: { damage: number, inflictor?: Entity, attacker?: Entity, weapon?: CSWeaponBase }): number
Teleport Teleport(newValues: { position?: Vector, angles?: QAngle, velocity?: Vector }): 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
GetPlayerName GetPlayerName(): string
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
IsConnected IsConnected(): boolean
IsObserving IsObserving(): boolean
JoinTeam JoinTeam(team: number): void

CSObserverPawn

extends BaseModelEntity

Methods

Function Signature Description
GetObserverMode GetObserverMode(): number
GetOriginalPlayerController GetOriginalPlayerController(): CSPlayerController Gets the controller that this player pawn was originally spawned for.
GetPlayerController GetPlayerController(): CSPlayerController | undefined Gets the controller currently controlling this player pawn.
SetObserverMode SetObserverMode(nMode: number): void

CSPlayerPawn

extends BaseModelEntity

Methods

Function Signature Description
DestroyWeapon DestroyWeapon(target: CSWeaponBase): void
DestroyWeapons DestroyWeapons(): void
DropWeapon DropWeapon(target: CSWeaponBase): void
FindWeapon FindWeapon(name: string): CSWeaponBase | undefined
FindWeaponBySlot FindWeaponBySlot(slot: CSGearSlot): CSWeaponBase | undefined
GetActiveWeapon GetActiveWeapon(): CSWeaponBase | undefined
GetArmor GetArmor(): number
GetOriginalPlayerController GetOriginalPlayerController(): CSPlayerController Gets the controller that this player pawn was originally spawned for.
GetPlayerController GetPlayerController(): CSPlayerController | undefined Gets the controller currently controlling this player pawn.
GiveNamedItem GiveNamedItem(name: string, autoDeploy?: boolean): void
IsCrouched IsCrouched(): boolean
IsCrouching IsCrouching(): boolean
IsNoclipping IsNoclipping(): boolean
SetArmor SetArmor(value: number): void
SwitchToWeapon SwitchToWeapon(target: CSWeaponBase): void

CSWeaponBase

extends BaseModelEntity

Methods

Function Signature Description
GetData GetData(): CSWeaponData
GetOwner GetOwner(): CSPlayerPawn | undefined

CSWeaponData

Methods

Function Signature Description
GetDamage GetDamage(): number Starting damage as the bullet travels
GetName GetName(): string
GetPenetration GetPenetration(): number Power to maintain damage during penetration
GetPrice GetPrice(): number
GetRange GetRange(): number
GetRangeModifier GetRangeModifier(): number Exponential damage drop off from traveling through air. nextDamage = currentDamage * rangeModifier ^ (distance / 500).
GetType GetType(): CSWeaponType

PointTemplate

extends Entity

Methods

Function Signature Description
ForceSpawn ForceSpawn(origin?: Vector, angle?: QAngle): Entity[] | undefined

Interfaces

BulletTrace

Examples:

  • {damage:30, rangeModifer:.85, penetration:1} // Glock
  • {damage:30, rangeModifer:.45, penetration:1} // Mag-7
  • {damage:36, rangeModifier:.98, penetration:2} // AK47
  • {damage:115, rangeModifier:.99, penetration:2.5} // AWP
Property Type Optional Description
damage number yes Default = 100
end Vector no
penetration number yes Default = 1
rangeModifier number yes Default = .85
shooter CSPlayerPawn no
start Vector no

BulletTraceResult

Property Type Optional Description
damage number no Damage value reduced by travel, before damage modification (body armor, headhshots, etc)
hitEntity Entity no
position Vector no

TraceResult

Property Type Optional Description
didHit boolean no
end Vector no
fraction number no
hitEntity Entity yes
normal Vector no
startedInSolid boolean no


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


Type Aliases

cs_script pre-defines a few type aliases.

BeforeDamageResult

Signature: type BeforeDamageResult = { damage?: number, abort?: boolean } | void

Color

Signature: type Color = { r: number, g: number, b: number, a?: number }

Values will be clamped to a maximum of 255.

InputValue

Signature: type InputValue = 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 }