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_addons\cs_script_demo\maps\scripts\point_script.d.ts
Functions
Domain
The top level API provided to scripts attached to a point_script entity.
Access these functions by importing Instance from "cs_script/point_script".
Functions
| Name | 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?: ColorArg }): void | Print some text to the game window. Only works in dev environments. |
| DebugLine | DebugLine(config: { start: Vector, end: Vector, duration?: number, color?: ColorArg }): void | Draw a line in the world. Only works in dev environments. |
| DebugSphere | DebugSphere(config: { center: Vector, radius: number, duration?: number, color?: ColorArg }): void | Draw a wire sphere in the world. Only works in dev environments. |
| DebugBox | DebugBox(config: { mins: Vector, maxs: Vector, duration?: number, color?: ColorArg }): void | Draw an axis aligned box in the world. Only works in dev environments. |
| SetSaveData | SetSaveData(data: string): void | Writes save data associated with this workshop addon. Will synchronously write to disk every time this is called. |
| GetSaveData | GetSaveData(): string | Retrieves the save data associated with this workshop addon. Will synchronously read from disk the first time this is called. |
| 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. |
| Delay | Delay(delay: number): Promise<void> | Returns a promise that resolves after delay number of seconds. The exact time will be on the tick nearest to the specified delay, 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. |
| 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. |
| GetAllPlayerControllers | GetAllPlayerControllers(): CSPlayerController[] | Get all the player controllers. Includes disconnected players. |
| 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 |
| TracePlayer | TracePlayer(trace: PlayerTrace): PlayerTraceResult | Trace as a player would collide |
| TraceBullet | TraceBullet(trace: BulletTrace): BulletTraceResult[] | Trace as a bullet and detect hits and damage |
| IsDedicatedServer | IsDedicatedServer(): boolean | Get if the server is a dedicated server. |
| 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. |
| GetRoundRemainingTime | GetRoundRemainingTime(): number | Get the time remaining in the current round in seconds. |
| SetRoundRemainingTime | SetRoundRemainingTime(time: number): void | Set the time remaining in the current round in seconds. |
| SpawnGrenadeProjectile | SpawnGrenadeProjectile(config: SpawnGrenadeProjectileConfig): CSGrenadeProjectileBase | Spawns a live grenade projectile. |
| ClientCommand | ClientCommand(playerSlot: number, command: string): void | Issue the specified command to the specified client. |
| ServerCommand | ServerCommand(command: string): void | Issue a command. |
| DebugScreenText | DebugScreenText(text: any, x: number, y: number, duration: number, color: ColorArg): void | @deprecated This overload will be removed in a future update |
| DebugLine | DebugLine(start: Vector, end: Vector, duration: number, color: ColorArg): void | @deprecated This overload will be removed in a future update |
| DebugBox | DebugBox(mins: Vector, maxs: Vector, duration: number, color: ColorArg): void | @deprecated This overload will be removed in a future update |
| DebugSphere | DebugSphere(center: Vector, radius: number, duration: number, color: ColorArg): void | @deprecated This overload will be removed in a future update |
| GetTraceHit | GetTraceHit(start: Vector, end: Vector, config?: { ignoreEntity?: Entity, ignorePlayers?: boolean }): TraceResult | @deprecated This method will be removed in a future update |
| EntFireAtName | EntFireAtName(name: string, input: string, inputData?: InputValue | { value?: InputValue, caller?: Entity, activator?: Entity }, delay?: number): void | @deprecated This overload will be removed in a future update |
| EntFireAtTarget | EntFireAtTarget(target: Entity, input: string, inputData?: InputValue | { value?: InputValue, caller?: Entity, activator?: Entity }, delay?: number): void | @deprecated This overload will be removed in a future update |
Events
| Name | Signature | Description |
|---|---|---|
| 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. |
| SetThink | SetThink(callback: () => void): void | Called at a specified time. Control when this is run using SetNextThink. |
| QueueAfterThinks | QueueAfterThinks( callback: () => void ): void | Queue up a callback to be invoked once, after all entities have executed their think functions this tick (eg. player input has been handled, projectiles have moved). This can be useful for delaying until a clean moment when an entity isn't mid-computation and might ignore or misinterpret. This can be useful for delaying until the world is in a consistent state. Callbacks queued up during a post entity think callback will be invoked in the same tick. @experimental This method is experimental and may experience breaking changes. Please send feedback to CSGOTeamFeedback@valvesoftware.com with "cs_script Feedback" in the subject line. |
| 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 |
| OnBeginRoundRestart | OnBeginRoundRestart(callback: () => void): void | Called at the start of cleanup for a round restart @experimental This method is experimental and may experience breaking changes. Please send feedback to CSGOTeamFeedback@valvesoftware.com with "cs_script Feedback" in the subject line. |
| OnBombPlantStart | OnBombPlantStart(callback: (event: { planter: CSPlayerPawn }) => void): void | Called when a player starts planting their c4 |
| OnBombPlantAbort | OnBombPlantAbort(callback: (event: { planter: CSPlayerPawn }) => void): void | Called when a player aborts planting their c4 |
| OnBombPlant | OnBombPlant(callback: (event: BombPlantEvent) => void): void | Called when a player plants their c4 |
| OnBombDefuseStart | OnBombDefuseStart(callback: (event: { plantedC4: CSPlantedC4 }) => void): void | Called when a player starts defusing a c4 |
| OnBombDefuseAbort | OnBombDefuseAbort(callback: (event: { plantedC4: CSPlantedC4 }) => void): void | Called when a player aborts defusing a c4 |
| OnBombDefuse | OnBombDefuse(callback: (event: BombDefuseEvent) => void): void | Called when a player defuses a c4 |
| OnBombExplode | OnBombExplode(callback: (event: { plantedC4: CSPlantedC4 }) => void): void | Called when a c4 explodes |
| OnModifyPlayerDamage | OnModifyPlayerDamage(callback: (event: ModifyPlayerDamageEvent) => ModfiyPlayerDamageResult | void): void | Called immediately before a CSPlayerPawn takes damage to armor and health. Called after hitgroup modifications are applied such as headshot multiplier. This won't be called if the player would take no damage. Such as if they're frozen or invulnerable or if friendly fire would disable the damage. Return { damage: N } to modify the amount of damage.Return { damageFlags: event.damageFlags | [CSDamageFlags](#csdamageflags).IGNORE_ARMOR } to have the damage pierce armor.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, 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, hitEntity?: Entity }) => void): void | Called when a bullet hits a surface. Penetrations can cause a single bullet to trigger multiple impacts. This will be called for all impacts of a bullet before any player damage events are called. |
| OnWeaponDrop | OnWeaponDrop(callback: (event: { weapon: CSWeaponBase, dropper: CSPlayerPawn }) => void): void | Called when a weapon is dropped. |
| OnWeaponPickup | OnWeaponPickup(callback: (event: { weapon: CSWeaponBase }) => void): void | Called when a weapon is picked up. |
| OnGrenadeThrow | OnGrenadeThrow(callback: (event: { weapon: CSWeaponBase, projectile: CSGrenadeProjectileBase }) => void): void | Called when a grenade is thrown. projectile is the newly created grenade projectile. |
| OnGrenadeBounce | OnGrenadeBounce(callback: (event: GrenadeBounceEvent) => void): void | Called when a grenade bounces. |
| OnKnifeAttack | OnKnifeAttack(callback: (event: { weapon: CSWeaponBase, attackType: CSWeaponAttackType }) => void): void | Called when a knife attacks, even if it misses. |
| OnCustomHudClicked | OnCustomHudClicked( callback: (event: {player: CSPlayerController, layout: CustomHudLayout, buttonId: string}) => void ): void | Called when a button in a CustomHudLayout is clicked. |
| 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 |
| RegisterCheatCommand | RegisterCheatCommand(name: string, callback: (args: string) => void): void | Creates a console command that will run the specified callback. The command will only work when sv_cheats is true. |
| OnBeforePlayerDamage | OnBeforePlayerDamage(callback: () => any): void | @deprecated This method will be removed in a future update |
| OnBeforeReload | OnBeforeReload(callback: () => any): void | @deprecated This method will be removed in a future update |
| OnReload | OnReload(callback: (memory: any) => void): void | @deprecated This method will be removed in a future update |
Entity
The base class for all entities
Functions
| Name | 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. |
| GetAbsAngularVelocity | GetAbsAngularVelocity(): RotationVector | The angular velocity of this entity relative to the world. |
| GetLocalAngularVelocity | GetLocalAngularVelocity(): RotationVector | The angular 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, angularVelocity?: RotationVector }): void | Update the physics state of this entity. |
| Move | Move(newValues: { position?: Vector, angles?: QAngle, velocity?: Vector, angularVelocity?: RotationVector }): void | Move this entity without resetting the client's interpolation history. |
| GetMoveType | GetMoveType(): CSMoveType | |
| SetMoveType | SetMoveType(moveType: CSMoveType): void | |
| 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: EntityDamage): 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 overload will be removed in a future update |
| GetLocalVelcoity | GetLocalVelcoity(): Vector | @deprecated This method will be removed in a future update |
BaseModelEntity
Functions
| Name | Signature | Description |
|---|---|---|
| SetModel | SetModel(modelName: string): void | |
| GetModelName | GetModelName(): string | |
| SetModelScale | SetModelScale(scale: number): void | |
| GetModelScale | GetModelScale(): number | |
| SetColor | SetColor(color: ColorArg): void | |
| GetColor | GetColor(): Color | |
| Glow | Glow(color?: ColorArg): void | |
| Unglow | Unglow(): void | |
| IsGlowing | IsGlowing(): boolean |
CSWeaponBase
Functions
| Name | Signature | Description |
|---|---|---|
| GetData | GetData(): CSWeaponData | |
| GetOwner | GetOwner(): CSPlayerPawn | undefined | |
| GetOriginalOwner | GetOriginalOwner(): CSPlayerPawn | undefined | |
| GetClipAmmo | GetClipAmmo(): number | |
| SetClipAmmo | SetClipAmmo(ammo: number): void | |
| GetReserveAmmo | GetReserveAmmo(): number | |
| SetReserveAmmo | SetReserveAmmo(ammo: number): void | |
| IsSilencerOn | IsSilencerOn(): boolean |
C4
Functions
| Name | Signature | Description |
|---|---|---|
| GetPlantStartTime | GetPlantStartTime(): number | undefined | |
| GetPlantFinishTime | GetPlantFinishTime(): number | undefined | |
| AbortPlant | AbortPlant(): void |
CSWeaponData
Functions
| Name | Signature | Description |
|---|---|---|
| GetName | GetName(): string | |
| GetType | GetType(): CSWeaponType | |
| GetGearSlot | GetGearSlot(): CSGearSlot | |
| GetPrice | GetPrice(): number | |
| GetDamage | GetDamage(): number | |
| GetMaxClipAmmo | GetMaxClipAmmo(): number | |
| GetMaxReserveAmmo | GetMaxReserveAmmo(): number | |
| GetRange | GetRange(): number | Maximum distance bullets will travel. |
| 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 |
CSGrenadeProjectileBase
Functions
| Name | Signature | Description |
|---|---|---|
| GetThrower | GetThrower(): CSPlayerPawn | |
| GetGrenadeType | GetGrenadeType(): CSGrenadeType | |
| Detonate | Detonate(): void |
CSPlantedC4
Functions
| Name | Signature | Description |
|---|---|---|
| IsBombsiteA | IsBombsiteA(): boolean | |
| IsBombsiteB | IsBombsiteB(): boolean | |
| GetPlanter | GetPlanter(): CSPlayerPawn | undefined | |
| GetDefuser | GetDefuser(): CSPlayerPawn | undefined | |
| IsActive | IsActive(): boolean | |
| IsExploded | IsExploded(): boolean | |
| IsDefused | IsDefused(): boolean | |
| GetPlantTime | GetPlantTime(): number | |
| GetExplodeTime | GetExplodeTime(): number | undefined | |
| GetDefuseStartTime | GetDefuseStartTime(): number | undefined | |
| GetDefuseFinishTime | GetDefuseFinishTime(): number | undefined |
CSPlayerController
Functions
| Name | 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 | |
| AddMoneySpendableNow | AddMoneySpendableNow(amount: number): void | |
| GetMoneySpendableNow | GetMoneySpendableNow(): number | |
| AddMoneyEarnedForNextRound | AddMoneyEarnedForNextRound(amount: number): void | |
| GetMoneyEarnedForNextRound | GetMoneyEarnedForNextRound(): number |
CSObserverPawn
Functions
| Name | 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. |
| GetObserverMode | GetObserverMode(): number | |
| SetObserverMode | SetObserverMode(nMode: number): void |
CSPlayerPawn
Functions
| Name | 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. |
| IsInputPressed | IsInputPressed(inputs: CSInputs): boolean | @returns true if specified inputs are pressed at the end of the current tick. |
| WasInputJustPressed | WasInputJustPressed(inputs: CSInputs): boolean | @returns true if specified inputs went from released to pressed at some point during the current tick. |
| WasInputJustReleased | WasInputJustReleased(inputs: CSInputs): boolean | @returns true if specified inputs went from pressed to released at some point during the current tick. |
| FindWeapon | FindWeapon(name: string): CSWeaponBase | undefined | |
| FindWeaponBySlot | FindWeaponBySlot(slot: CSGearSlot): CSWeaponBase | undefined | |
| GetActiveWeapon | GetActiveWeapon(): CSWeaponBase | undefined | |
| GetC4 | GetC4(): C4 | 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 | |
| HasHelmet | HasHelmet(): boolean | |
| SetHasHelmet | SetHasHelmet(hasHelmet: boolean): void | |
| HasDefuser | HasDefuser(): boolean | |
| SetHasDefuser | SetHasDefuser(hasDefuser: boolean): void | |
| GetDefuseTarget | GetDefuseTarget(): CSPlantedC4 | undefined | |
| IsDucking | IsDucking(): boolean | |
| IsDucked | IsDucked(): boolean | |
| IsScoped | IsScoped(): boolean | |
| IsNoclipping | IsNoclipping(): boolean | |
| IsBuyMenuOpen | IsBuyMenuOpen(): boolean | |
| GetCustomCamera | GetCustomCamera(): CustomPlayerCamera | |
| GetCamera | GetCamera(): CSPlayerCamera | @deprecated This method will be removed in a future update |
| IsCrouching | IsCrouching(): boolean | @deprecated This method will be removed in a future update |
| IsCrouched | IsCrouched(): boolean | @deprecated This method will be removed in a future update |
CustomHudLayout
CustomHudLayouts (custom_hud_layout) are the entry point for scripted maps to provide custom UI.
-
Supported panel types and attributes are:
-
<Panel> with attributes id, class and hittest
-
<Label> with attributes id, class, hittest, and text
-
<Image> with attributes id, class, hittest, and src
-
<Button> with attributes id and class
-
Styling with css is supported.
-
The following css classes will be set on an ancestor panel when appropriate:
-
HUD_BUYMENU_VISIBLE -
HUD_SCOREBOARD_VISIBLE -
Events and client side scripting are not supported.
To use
-
Add a panorama layout .xml file under "panorama/layout/custom_game" in your addon
-
Add a custom_hud_layout point entity to your map and point its
layoutproperty at your .vxml asset. -
See example addon cs_script_demo
-
There is a custom_hud_layout entity in the cs_script_demo.vmap named "welcome_layout" that displays "panorama/layouts/custom_game/welcome.vxml".
-
It also references css file
panorama/styles/custom_game/welcome.css. (vcss is the asset extension) -
The layout begins with a "Dismissed" class on the Panel with id "dialog" which is then removed in cs_script file "maps/scripts/setup.js".
@experimental This feature is experimental and may experience breaking changes.
Please send feedback to CSGOTeamFeedback@valvesoftware.com with "cs_script Feedback" in the subject line.
Functions
| Name | Signature | Description |
|---|---|---|
| SetHasClass | SetHasClass(panelId: string, className: string, hasClass?: boolean): void | Set if a panel has a class. Applies to all players. Omit hasClass to revert to the original value. |
| SetHasClassForPlayer | SetHasClassForPlayer(playerSlot: number, panelId: string, className: string, hasClass?: boolean): void | Set if a panel has a class for a single player. Will override the all player value. Omit hasClass to defer to the all player value. |
| SetDialogVariableString | SetDialogVariableString(panelId: string, variableName: string, value: string): void | Set the value of a dialog variable. Applies to all players. |
| SetDialogVariableStringForPlayer | SetDialogVariableStringForPlayer(playerSlot: number, panelId: string, variableName: string, value?: string): void | Set the value of a dialog variable for a single player. Will override the all player value. Omit value to defer to the all player value. If no all player value has been set, the value will be an empty string. |
| SetInputCaptureEnabled | SetInputCaptureEnabled(playerSlot: number, enabled: boolean): void | Set to true to force a player into cursor mode and enable click detection on the panels of this layout. Set a callback with Instance.OnCustomHudClicked to listen for clicks. Multiple CustomHudLayouts can have input captured at a time. Players will get movement control back once all CustomHudLayouts have disabled input capture. |
| IsInputCaptureEnabled | IsInputCaptureEnabled(playerSlot: number): boolean | Get if this CustomHudLayout is capturing input for a player |
PointTemplate
Functions
| Name | Signature | Description |
|---|---|---|
| ForceSpawn | ForceSpawn(origin?: Vector, angle?: QAngle): Entity[] | undefined |
CustomPlayerCamera
Configuration of a player's view position and angles.
There is at most one of these per CSPlayerPawn, created on demand when CSPlayerPawn.GetCustomCamera is called.
@experimental This feature is experimental and may experience breaking changes.
Please send feedback to CSGOTeamFeedback@valvesoftware.com with "cs_script Feedback" in the subject line.
Functions
| Name | Signature | Description |
|---|---|---|
| GetPlayer | GetPlayer(): CSPlayerPawn | |
| GetMode | GetMode(): CustomCameraMode | |
| SetMode | SetMode(mode: CustomCameraMode): void | |
| SetFollowConfig | SetFollowConfig(followConfig: CameraFollowConfig): void |
CSPlayerCamera
@deprecated This class will be removed soon
Functions
| Name | Signature | Description |
|---|---|---|
| IsEnabled | IsEnabled(): boolean | @deprecated This method will be removed soon |
| SetEnabled | SetEnabled(enabled: boolean): void | @deprecated This method will be removed soon |
| SetIsControllingAngles | SetIsControllingAngles(controlling: boolean): void | @deprecated This method will be removed soon |
Types
Vector
type Vector = { x: number, y: number, z: number };
RotationVector
type RotationVector = { x: number, y: number, z: number };
QAngle
type QAngle = { pitch: number, yaw: number, roll: number };
ColorArg
type ColorArg = { r: number, g: number, b: number, a?: number };
Color
type Color = { r: number, g: number, b: number, a: number };
InputValue
type InputValue = boolean | number | string | Vector | Color | undefined;
SpawnGrenadeProjectileConfig
type SpawnGrenadeProjectileConfig = SpawnGrenadeProjectileConfigWithOwner | SpawnGrenadeProjectileConfigWithoutOwner;
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
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;
}
PlayerTrace
Configuration object for Instance.TracePlayer
interface PlayerTrace {
start: Vector;
/** Leave undefined to just test if `start` is a valid position for the player. */
end?: Vector;
/** The player moving. Effects hull size and player collision. */
player: CSPlayerPawn;
/** Configure tracing as a ducked player, effecting the size of the traced Box. Defaults to the player's IsDucked() value. */
isDucked?: boolean;
}
PlayerTraceResult
Result entry for Instance.TracePlayer
interface PlayerTraceResult {
fraction: number;
end: Vector;
didHit: boolean;
startedInSolid: boolean;
normal: Vector;
hitEntity?: Entity;
}
BombPlantEvent
interface BombPlantEvent {
plantedC4: CSPlantedC4;
/** @deprecated this field will be removed in a future update */
planter?: CSPlayerPawn
}
BombDefuseEvent
interface BombDefuseEvent {
plantedC4: CSPlantedC4;
/** @deprecated this field will be removed in a future update */
defuser: CSPlayerPawn
}
ModifyPlayerDamageEvent
interface ModifyPlayerDamageEvent {
/** The victim that is taking damage */
player: CSPlayerPawn;
/** The amount of damage being applied, after hitgroup modifications and before armor modifications */
damage: number;
/** The types of damage. */
damageTypes: CSDamageTypes;
/** The flags configuring how to interpret the damage. */
damageFlags: CSDamageFlags;
/** The hit group where the damage occured. */
hitGroup: CSHitGroup;
/** 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;
}
ModfiyPlayerDamageResult
interface ModfiyPlayerDamageResult {
/** If true, stop processing this damage */
abort?: boolean;
/** 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 hitgroup and armor modifications */
damage: number;
/** The type or types of damage. */
damageTypes: CSDamageTypes;
/** The flags configuring how to interpret the damage. */
damageFlags: CSDamageFlags;
/** The hit group where the damage occured. */
hitGroup: CSHitGroup;
/** 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;
}
GrenadeBounceEvent
interface GrenadeBounceEvent {
projectile: CSGrenadeProjectileBase;
hitEntity: Entity;
normal: Vector;
/** @deprecated this field will be removed in a future update */
bounces: number
}
SpawnGrenadeProjectileConfigWithOwner
interface SpawnGrenadeProjectileConfigWithOwner {
type: CSGrenadeType;
thrower: CSPlayerPawn;
/* defaults to 1, full strength. */
throwStrength?: number;
/* defaults to thrower's throw position */
position?: Vector;
/* defaults to {0,0,0} */
angles?: QAngle;
/* defaults to thrower's throw velocity */
velocity?: Vector;
/* defaults to a {600,rand(-1200,1200),0} */
angularVelocity?: RotationVector;
}
SpawnGrenadeProjectileConfigWithoutOwner
interface SpawnGrenadeProjectileConfigWithoutOwner {
type: CSGrenadeType;
/* position is required if no thrower is specified */
position: Vector;
/* defaults to {0,0,0} */
angles?: QAngle;
/* defaults to {0,0,0} */
velocity?: Vector;
/* defaults to {0,0,0} */
angularVelocity?: RotationVector;
}
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;
}
CameraFollowConfig
interface CameraFollowConfig {
/** The entity to follow */
followEntity: Entity;
/** Should followOffset be an offset from the eyes instead of the origin */
followEyes?: boolean;
/** An offset from the origin (or eyes) of followEntity to follow */
followOffset?: Vector;
/** An offset from the followed position rotated by player's eye angles. x is forward, y is left, z is up. */
cameraOffset?: Vector;
/** Should cameraOffset be pulled in to not clip into solids. */
clipCameraOffset?: boolean;
/** Strength of returning the camera to cameraOffset after being pushed in by clipping. Defaults to 1; instant. */
cameraOffsetReturnStrength?: number;
}
Enums
CSMoveType
- INVALID = -1
- NONE
- WALK
- FLYGRAVITY
- VPHYSICS
- NOCLIP
- OBSERVER
- LADDER
- CUSTOM
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
CSGrenadeType
- HE
- FLASHBANG
- MOLOTOV
- INCENDIARY
- DECOY
- SMOKE
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
- IGNORE_ARMOR = 1 << 6
CSHitGroup
- INVALID = -1
- GENERIC
- HEAD
- CHEST
- STOMACH
- LEFTARM
- RIGHTARM
- LEFTLEG
- RIGHTLEG
- NECK
CSInputs
- NONE = 0
- FORWARD = 1 << 0
- BACK = 1 << 1
- LEFT = 1 << 2
- RIGHT = 1 << 3
- WALK = 1 << 4
- DUCK = 1 << 5
- JUMP = 1 << 6
- USE = 1 << 7
- ATTACK = 1 << 8
- ATTACK2 = 1 << 9
- RELOAD = 1 << 10
- SHOW_SCORES = 1 << 11
- LOOK_AT_WEAPON = 1 << 12
CustomCameraMode
- DISABLED = 0 — Position and angles come from the eye position and angles of the player.
- CONTROLLED = 1 — Position and angles come from the origin and angles of the camera entity.
- CONTROLLED_POSITION = 2 — Position comes from the origin of camera entity. Angles are player controlled.
- FOLLOW_POSITION = 3 — Position comes from an offset around a followed position. Angles are player controlled.
CSDamageType
@deprecated This enum will be removed in a future update