API documentation
This page is a list of all functions, interfaces, types, and enums offered by the cs_script API in Counter-Strike 2
Valve has released a TypeScript file defining the current API along side the zoo map, it can be found at
Steam\steamapps\common\Counter-Strike Global Offensive\content\csgo\maps\editor\zoo\scripts\types\point_script.d.ts
Functions
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".
Function | Signature | Description |
---|---|---|
Msg | Msg(text: any): void; | Log a message to the console. |
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. |
DebugLine | DebugLine(config: { start: Vector, end: Vector, duration?: number, color?: Color }): void; | Draw a line in the world. 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. |
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. |
SetThink | SetThink(callback: () => void): void; | Called at a specified time. Control when this is run using SetNextThink. |
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. |
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. |
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 |
DisconnectOutput | DisconnectOutput(connectionId: number): void; | Find entities by name. |
FindEntityByName | FindEntityByName(name: string): Entity | undefined; | Find the first entity matching the specified name. |
FindEntitiesByName | FindEntitiesByName(name: string): Entity[]; | Find entities matching the specified name. |
FindEntityByClass | FindEntityByClass(className: string): Entity | undefined; | Find the first entity of the specified class name. |
FindEntitiesByClass | FindEntitiesByClass(className: string): Entity[]; | Find entities of the specified class name. |
GetPlayerController | GetPlayerController(playerSlot: number): CSPlayerController | undefined; | Get the player controller in the given slot. |
TraceLine | TraceLine(trace: BaseTraceConfig): TraceResult; | Trace a point along a line and detect collisions |
TraceSphere | TraceSphere(trace: { radius: number } & BaseTraceConfig): TraceResult; | Trace a sphere along a line and detect collisions |
TraceBox | TraceBox(trace: { mins: Vector, maxs: Vector } & BaseTraceConfig): 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 |
GetGameTime | GetGameTime(): number; | Get the game time in seconds. |
IsWarmupPeriod | IsWarmupPeriod(): boolean; | Get if the game is currently in a Warmup period. |
IsFreezePeriod | IsFreezePeriod(): boolean; | Get if the game is currently in a Freeze period. |
GetGameType | GetGameType(): number; | Get the current Game Type. |
GetGameMode | GetGameMode(): number; | Get the current Game Mode. |
GetMapName | GetMapName(): string; | Get the name of the current map. |
GetRoundsPlayed | GetRoundsPlayed(): number; | Get the number of rounds played in the current game. |
ClientCommand | ClientCommand(playerSlot: number, command: string): void; | Issue the specified command to the specified client. |
ServerCommand | ServerCommand(command: string): void; | Issue a command. |
Deprecated
These overloads will be removed in a future update
Function | Signature | Description |
---|---|---|
OnBeforeReload | OnBeforeReload(callback: () => any): void; | |
OnReload | OnReload(callback: (memory: any) => void): void; | |
DebugScreenText | DebugScreenText(text: any, x: number, y: number, duration: number, color: Color): void; | |
DebugLine | DebugLine(start: Vector, end: Vector, duration: number, color: Color): void; | |
DebugBox | DebugBox(mins: Vector, maxs: Vector, duration: number, color: Color): void; | |
DebugSphere | DebugSphere(center: Vector, radius: number, duration: number, color: Color): void; | |
GetTraceHit | GetTraceHit(start: Vector, end: Vector, config?: { ignoreEntity?: Entity, ignorePlayers?: boolean }): TraceResult; | |
EntFireAtName | EntFireAtName(name: string, input: string, inputData?: InputValue | { value?: InputValue, caller?: Entity, activator?: Entity }, delay?: number): void; | |
EntFireAtTarget | EntFireAtTarget(target: Entity, input: string, inputData?: InputValue | { value?: InputValue, caller?: Entity, activator?: Entity }, delay?: number): void; |
Events
Function | Signature | Description |
---|---|---|
OnScriptReload<T> | 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. |
OnActivate | OnActivate(callback: () => void): void; | Called when the point_script entity is activated |
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. |
OnPlayerConnect | OnPlayerConnect(callback: (event: { player: CSPlayerController }) => void): void; | Called when a client finishes the initial connection handshake with the server. |
OnPlayerActivate | OnPlayerActivate(callback: (event: { player: CSPlayerController }) => void): void; | Called when a client finishes loading and is ready to spawn. |
OnPlayerDisconnect | OnPlayerDisconnect(callback: (event: { playerSlot: number }) => void): void; | Called when a client disconnects from the server. |
OnPlayerReset | OnPlayerReset(callback: (event: { player: CSPlayerPawn }) => void): void | Called when a player respawns, changes team, or is placed back at spawn due to a round restart |
OnRoundStart | OnRoundStart(callback: () => void): void; | Called when a new round begins |
OnRoundEnd | OnRoundEnd(callback: (event: { winningTeam: number, reason: CSRoundEndReason }) => void): void; | Called when a team wins a round |
OnBombPlant | OnBombPlant(callback: (event: { plantedC4: Entity, planter: CSPlayerPawn }) => void): void; | Called when a player plants the c4 |
OnBombDefuse | OnBombDefuse(callback: (event: { plantedC4: Entity, defuser: CSPlayerPawn }) => void): void; | Called when a player defuses the c4 |
OnBeforePlayerDamage | OnBeforePlayerDamage(callback: (event: BeforePlayerDamageEvent) => BeforePlayerDamageModify | { abort: true } | void): void; | Called when a CSPlayerPawn is about to take damage @param callback Return { damage: N } to modify the amount of damage. Armor and hitgroup modifications will be applied to this new value.Return { abort: true } to cancel the damage event. |
OnPlayerDamage | OnPlayerDamage(callback: (event: PlayerDamageEvent) => void): void; | Called when a player has taken damage. |
OnPlayerKill | OnPlayerKill(callback: (event: { player: CSPlayerPawn, inflictor?: Entity, attacker?: Entity, weapon?: CSWeaponBase }) => void): void; | Called when a player dies. inflictor , attacker and weapon will match the damage event that caused the kill. |
OnPlayerJump | OnPlayerJump(callback: (event: { player: CSPlayerPawn }) => void): void; | Called when a player jumps off the ground. |
OnPlayerLand | OnPlayerLand(callback: (event: { player: CSPlayerPawn }) => void): void; | Called when a player hits the ground while falling. |
OnPlayerChat | OnPlayerChat(callback: (event: { player: CSPlayerController | undefined, text: string, team: number }) => void): void; | Called when a player sends a chat message. team will match they player's team if the message was sent to team chat. |
OnPlayerPing | OnPlayerPing(callback: (event: { player: CSPlayerController, position: Vector }) => void): void; | Called when a player pings a location. |
OnGunReload | OnGunReload(callback: (event: { weapon: CSWeaponBase }) => void): void; | Called when a gun is reloaded. |
OnGunFire | OnGunFire(callback: (event: { weapon: CSWeaponBase }) => void): void; | Called when a gun emits bullets. A shotgun will only trigger this once when emitting multiple bullets at once. |
OnBulletImpact | OnBulletImpact(callback: (event: { weapon: CSWeaponBase, position: Vector }) => void): void; | Called when a bullet hits a surface. This will trigger for each bullet and for each impact. Penetrations can cause a single bullet to trigger multiple impacts. |
OnGrenadeThrow | OnGrenadeThrow(callback: (event: { weapon: CSWeaponBase, projectile: Entity }) => void): void; | Called when a grenade is thrown. projectile is the newly created grenade projectile. |
OnGrenadeBounce | OnGrenadeBounce(callback: (event: { projectile: Entity, bounces: number }) => void): void; | Called when a grenade bounces off a surface. bounces is the number of bounces so far. |
OnKnifeAttack | OnKnifeAttack(callback: (event: { weapon: CSWeaponBase, attackType: CSWeaponAttackType }) => void): void; | Called when a knife attacks, even if it misses. |
Entity
API for all entities.
Function | Signature | Description |
---|---|---|
IsValid | IsValid(): boolean; | Returns false if the entity has been deleted. |
GetAbsOrigin | GetAbsOrigin(): Vector; | The position of the origin of this entity relative to the world. |
GetLocalOrigin | GetLocalOrigin(): Vector; | The position of the origin of this entity relative to its parent. Will be relative to the world if no parent. |
GetAbsAngles | GetAbsAngles(): QAngle; | The angles [pitch, yaw, and roll] of this entity relative to the world. |
GetLocalAngles | GetLocalAngles(): QAngle; | The angles [pitch, yaw, and roll] of this entity relative to its parent. Will be relative to the world if no parent. |
GetAbsVelocity | GetAbsVelocity(): Vector; | The velocity of this entity relative to the world. |
GetLocalVelocity | GetLocalVelocity(): Vector; | The velocity of this entity relative to its parent. Will be relative to the world if no parent. |
GetEyeAngles | GetEyeAngles(): QAngle; | The angles of the eyes of this entity relative to the world. |
GetEyePosition | GetEyePosition(): Vector; | The position of the eyes of this entity relative to the world |
Teleport | Teleport(newValues: { position?: Vector, angles?: QAngle, velocity?: Vector }): void; | Update the physics state of this entity. |
GetClassName | GetClassName(): string; | |
GetEntityName | GetEntityName(): string; | |
SetEntityName | SetEntityName(name: string): void; | |
GetOwner | GetOwner(): Entity | undefined; | |
SetOwner | SetOwner(owner: Entity | undefined): void; | |
GetParent | GetParent(): Entity | undefined; | |
SetParent | SetParent(parent: Entity | undefined): void; | |
GetTeamNumber | GetTeamNumber(): number; | |
GetHealth | GetHealth(): number; | |
SetHealth | SetHealth(health: number): void; | |
GetMaxHealth | GetMaxHealth(): number; | |
SetMaxHealth | SetMaxHealth(health: number): void; | |
IsAlive | IsAlive(): boolean; | |
IsWorld | IsWorld(): boolean; | Get if this is the world entity |
GetGroundEntity | GetGroundEntity(): Entity | undefined; | Get the entity that this entity is resting on. Will be undefined if in the air. |
TakeDamage | TakeDamage(takeDamage: { damage: number, inflictor?: Entity, attacker?: Entity, weapon?: CSWeaponBase }): number; | Apply damage to this entity. Damage value will be modified by armor and hitgroup. |
Kill | Kill(): void; | |
Remove | Remove(): void; | |
Teleport | Teleport(newPosition: Vector | null, newAngles: QAngle | null, newVelocity: Vector | null): void; | Deprecated, this method will be removed in a future update |
GetLocalVelcoity | GetLocalVelocity(): Vector; | Deprecated, this method will be removed in a future update |
BaseModelEntity
extends Entity
API for all entities which have a model.
Function | Signature | Description |
---|---|---|
SetModel | SetModel(modelName: string): void; | |
SetModelScale | SetModelScale(scale: number): void; | |
SetColor | SetColor(color: Color): void; | |
Glow | Glow(color?: Color): void; | |
Unglow | Unglow(): void; |
CSWeaponBase
extends BaseModelEntity
API for all Counter-Strike weapons.
Function | Signature | Description |
---|---|---|
GetData | GetData(): CSWeaponData; | |
GetOwner | GetOwner(): CSPlayerPawn | undefined; |
CSWeaponData
API for Counter-Strike weapon data.
Function | Signature | Description |
---|---|---|
GetName | GetName(): string; | |
GetType | GetType(): CSWeaponType; | |
GetGearSlot | GetGearSlot(): CSGearSlot; | |
GetPrice | GetPrice(): number; | |
GetDamage | GetDamage(): number; // Starting damage as the bullet travels | |
GetRange | GetRange(): number; | |
GetRangeModifier | GetRangeModifier(): number; // Exponential damage drop off from traveling through air. nextDamage = currentDamage * rangeModifier ^ (distance / 500). | |
GetPenetration | GetPenetration(): number; // Power to maintain damage during penetration |
CSPlayerController
extends Entity
API for player controllers.
Function | Signature | Description |
---|---|---|
GetPlayerSlot | GetPlayerSlot(): number; | |
GetPlayerName | GetPlayerName(): string; | |
GetPlayerPawn | GetPlayerPawn(): CSPlayerPawn | undefined; | |
GetObserverPawn | GetObserverPawn(): CSObserverPawn | undefined; | |
GetScore | GetScore(): number; | |
AddScore | AddScore(points: number): void; | Add to the player's score. Negative values are allowed but the score will not go below zero. |
GetWeaponDataForLoadoutSlot | GetWeaponDataForLoadoutSlot(slot: CSLoadoutSlot, team?: number): CSWeaponData | undefined; | Leave team as the default to use the player's current team. |
IsObserving | IsObserving(): boolean; | |
IsBot | IsBot(): boolean; | |
IsConnected | IsConnected(): boolean; | |
JoinTeam | JoinTeam(team: number): void; |
CSObserverPawn
extends BaseModelEntity
API for spectators.
Function | Signature | Description |
---|---|---|
GetPlayerController | GetPlayerController(): CSPlayerController | undefined; | |
GetOriginalPlayerController | GetOriginalPlayerController(): CSPlayerController; | Gets the controller that this player pawn was originally spawned for. |
GetObserverMode | GetObserverMode(): number; | |
SetObserverMode | SetObserverMode(nMode: number): void; |
CSPlayerPawn
extends BaseModelEntity
API for player pawns (the actual player in the world that the controller controls).
Function | Signature | Description |
---|---|---|
GetPlayerController | GetPlayerController(): CSPlayerController | undefined; | Gets the controller currently controlling this player pawn. |
GetOriginalPlayerController | GetOriginalPlayerController(): CSPlayerController; | Gets the controller that this player pawn was originally spawned for. |
FindWeapon | FindWeapon(name: string): CSWeaponBase | undefined; | |
FindWeaponBySlot | FindWeaponBySlot(slot: CSGearSlot): CSWeaponBase | undefined; | |
GetActiveWeapon | GetActiveWeapon(): CSWeaponBase | undefined; | |
DestroyWeapon | DestroyWeapon(target: CSWeaponBase): void; | |
DestroyWeapons | DestroyWeapons(): void; | |
DropWeapon | DropWeapon(target: CSWeaponBase): void; | |
SwitchToWeapon | SwitchToWeapon(target: CSWeaponBase): void; | |
GiveNamedItem | GiveNamedItem(name: string, autoDeploy?: boolean): void; | |
GetArmor | GetArmor(): number; | |
SetArmor | SetArmor(value: number): void; | |
IsCrouching | IsCrouching(): boolean; | |
IsCrouched | IsCrouched(): boolean; | |
IsNoclipping | IsNoclipping(): boolean; |
PointTemplate
extends Entity
API for point_template entities.
Function | Signature | Description |
---|---|---|
ForceSpawn | ForceSpawn(origin?: Vector, angle?: QAngle): Entity[] | undefined; |
Types
Vector
type Vector = { x: number, y: number, z: number };
QAngle
type QAngle = { pitch: number, yaw: number, roll: number };
Color
type Color = { r: number, g: number, b: number, a?: number };
InputValue
type InputValue = boolean | number | string | Vector | Color | undefined;
BeforeDamageResult
type BeforeDamageResult = { damage?: number, abort?: boolean } | void;
Interfaces
BaseTraceConfig
interface BaseTraceConfig {
start: Vector;
end: Vector;
/** Specify entities to not trace against. 0, 1 or 2 entities is equally fast. 3 or more is equally slower */
ignoreEntity?: Entity | Entity[];
ignorePlayers?: boolean;
/** Trace against hitboxes instead of the larger collision shape for entities with hitboxes (eg. players) */
traceHitboxes?: boolean;
}
TraceResult
interface TraceResult {
fraction: number;
end: Vector;
didHit: boolean;
startedInSolid: boolean;
normal: Vector;
hitEntity?: Entity;
hitGroup?: CSHitGroup;
}
BulletTrace
/**
* Configuration object for `Instance.TraceBullet`
* @example {damage:30, rangeModifer:.85, penetration:1} // Glock
* @example {damage:30, rangeModifer:.45, penetration:1} // Mag-7
* @example {damage:36, rangeModifier:.98, penetration:2} // AK47
* @example {damage:115, rangeModifier:.99, penetration:2.5} // AWP
*/
interface BulletTrace {
start: Vector,
end: Vector,
/** The player shooting the bullet. Acts as `ignoreEnt` for traces. */
shooter: CSPlayerPawn,
/** The starting damage value of the bullet. This will reduce as it travels through the air and penetrates solids. @default 100 */
damage?: number,
/** The exponential damage drop off constant from traveling through air. @default .85 */
rangeModifier?: number,
/** The power to maintain damage during penetration. Will default to 1 if left unspecified. @default 1 */
penetration?: number,
}
BulletTraceResult
/**
* Result entry for `Instance.TraceBullet`
*/
interface BulletTraceResult {
/** The entity hit by the bullet. This is not limited to players. */
hitEntity: Entity;
/** Damage value reduced by travel, before damage modification (body armor, headhshots, etc) */
damage: number;
position: Vector;
hitGroup: CSHitGroup;
}
BeforePlayerDamageEvent
interface BeforePlayerDamageEvent {
/** The victim that is taking damage */
player: CSPlayerPawn;
/** The amount of damage being applied, before armor and hitgroup modifications */
damage: number;
/** The type or types of damage. */
damageTypes: CSDamageTypes;
/** The flags configuring how to interpret the damage. */
damageFlags: CSDamageFlags;
/** The entity applying the damage. For bullets this is the owner of the gun. For grenades this is the exploding projectile. */
inflictor?: Entity;
/** The entity credited with causing the damage. For bullets this is the shooter. For grenades this is the thrower. */
attacker?: Entity;
/** The weapon used. For grenades this will not be present because the weapon is often removed before the projectile explodes. */
weapon?: CSWeaponBase;
}
BeforePlayerDamageModify
interface BeforePlayerDamageModify {
/** The amount of damage being applied, before armor and hitgroup modifications */
damage?: number;
/** The type or types of damage. */
damageTypes?: CSDamageTypes;
/** The flags configuring how to interpret the damage. */
damageFlags?: CSDamageFlags;
}
PlayerDamageEvent
interface PlayerDamageEvent {
/** The victim that has taken damage */
player: CSPlayerPawn;
/** The actual health lost after armor and hitgroup modifications */
damage: number;
/** The type or types of damage. */
damageTypes: CSDamageTypes;
/** The flags configuring how to interpret the damage. */
damageFlags: CSDamageFlags;
/** The entity applying the damage. For bullets this is the owner of the gun. For grenades this is the exploding projectile. */
inflictor?: Entity;
/** The entity credited with causing the damage. For bullets this is the shooter. For grenades this is the thrower. */
attacker?: Entity;
/** The weapon used. For grenades this will not be present because the weapon is often removed before the projectile explodes. */
weapon?: CSWeaponBase;
}
EntityDamage
interface EntityDamage {
/** The amount of damage being applied, before armor and hitgroup modifications */
damage: number;
/** The type or types of damage. */
damageTypes?: CSDamageTypes;
/** The flags configuring how to interpret the damage. */
damageFlags?: CSDamageFlags;
/** The entity applying the damage. For bullets this is the owner of the gun. For grenades this is the exploding projectile. */
inflictor?: Entity;
/** The entity credited with causing the damage. For bullets this is the shooter. For grenades this is the thrower. */
attacker?: Entity;
/** The weapon used. For grenades this will not be present because the weapon is often removed before the projectile explodes. */
weapon?: CSWeaponBase;
}
enums
CSRoundEndReason
- UNKNOWN = -1
- IN_PROGRESS
- GAME_COMMENCING
- DRAW
- TARGET_BOMBED
- TARGET_SAVED
- BOMB_DEFUSED
- HOSTAGES_RESCUED
- HOSTAGES_NOT_RESCUED
- CTS_WIN
- TERRORISTS_WIN
- CTS_SURRENDER
- TERRORISTS_SURRENDER
CSWeaponType
- KNIFE
- PISTOL
- SUBMACHINEGUN
- RIFLE
- SHOTGUN
- SNIPER_RIFLE
- MACHINEGUN
- C4
- TASER
- GRENADE
- EQUIPMENT
- STACKABLEITEM // Healthshot
- UNKNOWN
CSWeaponAttackType
- INVALID = -1
- PRIMARY
- SECONDARY
CSGearSlot
- INVALID = -1
- RIFLE
- PISTOL
- KNIFE
- GRENADES
- C4
- BOOSTS
CSLoadoutSlot
- INVALID
- MELEE
- SECONDARY0
- SECONDARY1
- SECONDARY2
- SECONDARY3
- SECONDARY4
- SMG0
- SMG1
- SMG2
- SMG3
- SMG4
- RIFLE0
- RIFLE1
- RIFLE2
- RIFLE3
- RIFLE4
- EQUIPMENT2
CSDamageTypes
- GENERIC = 0
- CRUSH = 1 << 0
- BULLET = 1 << 1
- SLASH = 1 << 2
- BURN = 1 << 3
- VEHICLE = 1 << 4
- FALL = 1 << 5
- BLAST = 1 << 6
- CLUB = 1 << 7
- SHOCK = 1 << 8
- SONIC = 1 << 9
- BUCKSHOT = 1 << 10
- DROWN = 1 << 11
- POISON = 1 << 12
- HEADSHOT = 1 << 13
CSDamageFlags
- NONE = 0
- SUPPRESS_HEALTH_CHANGES = 1 << 0
- SUPPRESS_PHYSICS_FORCE = 1 << 1
- SUPPRESS_EFFECTS = 1 << 2
- PREVENT_DEATH = 1 << 3
- FORCE_DEATH = 1 << 4
- SUPPRESS_DAMAGE_MODIFICATION = 1 << 5
CSHitGroup
- INVALID = -1
- GENERIC
- HEAD
- CHEST
- STOMACH
- LEFTARM
- RIGHTARM
- LEFTLEG
- RIGHTLEG
- NECK