AMX Mod X · Counter-Strike 1.6
CS 1.6 plugins in TypeScript.
Write a plugin the way you write any TypeScript: familiar types, classes,
import { Player, plugin, print, server } from "~/facade";
plugin({
name: "Say HP",
version: "1.0.0",
author: "Author",
description: "An example",
});
server.addCommand("/hp", sayHp);
server.addEventListener("putinserver", (event) => {
print(0, `${event.player.name} joined`);
});
function sayHp(player: Player) {
print(player, `${player.name}, your HP: ${player.health}`);
if (player.health < 50) player.health = 100;
}
import { expect, test } from "vitest"; // or "bun:test"
import { loadPlugin } from "../src/testing";
test("/hp heals a hurt player", async () => {
const server = await loadPlugin("as/say-hp.ts");
const player = server.join("Alice", { health: 40 });
player.say("/hp");
expect(player.chat).toContain("Alice, your HP: 40");
expect(player.health).toBe(100);
}, 60_000);
TypeScript, not a new language
A plugin is ordinary TypeScript. Everything AssemblyScript and Pawn need — cells, float bit patterns, string buffers — is kept under the hood, in the facade and the generated natives.
Under the hood
Compiled ahead of time, inside AMX Mod X
amxts does not translate anything into Pawn. The plugin is compiled to WebAssembly by AssemblyScript, then to i386 machine code by WAMR's
Machine code, not an interpreter
Plugins are compiled to machine code before the server loads them.
Any native, typed
The generator reads the
CS 1.6 server
AMX Mod X
amxts_amxx
runs your .aot plugins with WAMR
say-hp.aot loadedamxts_host.amxx
generated, holds no logic
natives by name
Modules and Pawn plugins
reapi, hamsandwich, cstrike, your .amxx
Pawn keeps working
Pawn plugins can call TypeScript
Every
/** A value from a config file, or false when the key is not there. */
export function cfg_get_value(file: string, section: string, key: string) {
return lookup(file, section, key); // string | null
}
/** A value from a config file, or false when the key is not there. */
native bool:cfg_get_value(const file[], const section[], const key[], out[], len);