CS2API 1.0.3
See the version list below for details.
dotnet add package CS2API --version 1.0.3
NuGet\Install-Package CS2API -Version 1.0.3
<PackageReference Include="CS2API" Version="1.0.3" />
<PackageVersion Include="CS2API" Version="1.0.3" />
<PackageReference Include="CS2API" />
paket add CS2API --version 1.0.3
#r "nuget: CS2API, 1.0.3"
#:package CS2API@1.0.3
#addin nuget:?package=CS2API&version=1.0.3
#tool nuget:?package=CS2API&version=1.0.3
CS2API
A C# wrapper and transpiler for Counter-Strike 2's Workshop JavaScript API. Write your point_script scripts in C# with full type safety and IntelliSense, then automatically transpile them to clean JS.
Why?
CS2 Workshop scripts are written in JavaScript using the point_script entity API. CS2API lets you write those scripts in C# instead, giving you:
- Type safety -- catch errors at compile time, not in-game
- IntelliSense -- full autocomplete for every API method, event, and type
- Clean output -- transpiles to dependency-free JS that runs directly in CS2's V8 environment
Installation
dotnet add package CS2API
The package includes both the API stubs (for writing scripts) and the compiler (for transpiling to JS). After building your project, the transpiler runs automatically and outputs .js files to a Scripts/ directory.
Quick Start
Create a new console or class library project and add the CS2API package. Then write a script:
using CS2API;
namespace MyWorkshopMap;
public class Script
{
public static void Main()
{
Instance.Msg("Hello from C#!");
Instance.OnRoundStart(() =>
{
Instance.Msg("Round started!");
});
Instance.OnPlayerChat((e) =>
{
Instance.Msg($"Player said: {e.text}");
});
}
}
This transpiles to:
import { Instance } from "cs_script/point_script";
Instance.Msg("Hello from C#!");
Instance.OnRoundStart(() => {
Instance.Msg("Round started!");
});
Instance.OnPlayerChat((e) => {
Instance.Msg(`Player said: ${e.text}`);
});
Configuration
By default, the transpiler runs after every build and outputs to Scripts/. You can customize this in your .csproj:
<PropertyGroup>
<CS2APIOutputDir>$(MSBuildProjectDirectory)\MyScripts</CS2APIOutputDir>
<CS2APICompilerEnabled>false</CS2APICompilerEnabled>
</PropertyGroup>
Type Mappings
| C# | JS |
|---|---|
Instance.Msg(text) |
Instance.Msg(text) |
new Vector(1, 2, 3) |
{ x: 1, y: 2, z: 3 } |
new Color(255, 0, 0) |
{ r: 255, g: 0, b: 0 } |
$"Hello {name}" |
`Hello ${name}` |
player?.GetPawn() |
player?.GetPawn() |
(int)expr |
expr |
Math.Floor(x) |
Math.floor(x) |
Project Structure
Your C# scripts should follow this pattern:
- Namespace -- used for organization, stripped in output
Scriptclass -- the wrapper class, unwrapped in outputMain()method -- the entry point, its body becomes top-level statements- Other methods -- transpiled to JS
functiondeclarations
License
See LICENSE.md for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.