Getting started

Introduction

amxts lets you write AMX Mod X plugins for Counter-Strike 1.6 in TypeScript. A plugin is an ordinary .ts file: familiar types, classes, closures, async/await, events you listen to. It runs on the server next to your Pawn plugins, and the two call each other.

plugin
({
name
: "Welcome",
version
: "1.0.0",
author
: "you" });
server
.
addEventListener
("putInServer", (
event
) => {
print
(
event
.
player
, `Welcome, ${
event
.
player
.
name
}!`);
});
game
.
addEventListener
("takeDamage", (
event
) => {
if (
event
.
attacker
.
team
==
event
.
player
.
team
)
event
.
preventDefault
(); // no team damage
});
server
.
addCommand
("/heal", ({
player
}) => {
if (
player
.
health
< 100)
player
.
health
= 100;
});

What you get

  • TypeScript as you know it: number, string, boolean, arrays, Map, classes and interfaces, optional fields, closures, template strings.
  • Players and entities as objects: player.health = 100, player.team, player.hideHud.push("money"), Entity.findAll({ classname: "grenade" }) (Players and entities).
  • Events as in the browser: server.addEventListener("putInServer", ...) for the server, game.addEventListener("takeDamage", ...) for the game, with event.preventDefault() (Game events).
  • An editor that knows the game: every native, every game event and every entity field comes with its type and a description; a typo is a red line, not an error on the server.
  • Waiting without blocking: await sleep(1000), await useFetch<Stats>(url), cancelled on its own when the player leaves (Async).
  • Save and play: amxts dev rebuilds a plugin on save and reloads it on the running server, without a map change (Getting started).
  • Tests without a game server: your plugin runs against a fake server with npx amxts test (Testing).
  • Pawn plugins keep working: a TypeScript plugin exports natives and forwards for them and calls theirs (Natives, Forwards).

How it runs

The build compiles each plugin ahead of time to machine code, a .aot file. The amxts_amxx module, an AMX Mod X module you install on the server, loads these files and runs them inside AMX Mod X. Every native the server has - of AMX Mod X, ReAPI, the other modules and other plugins - is a typed function a plugin can call.

What the server needs

  • AMX Mod X 1.9 or later.
  • The amxts_amxx module, on a Windows or a Linux server: amxts_amxx.dll or amxts_amxx_i386.so, which the line amxts_amxx in modules.ini finds on either.
  • For every game event of ReGameDLL's own as the game raises it (playerSpawn, roundEnd, …): ReHLDS, ReGameDLL and ReAPI. The entity properties, the player actions (give, respawn, …) and most game events work without them, through AMX Mod X's own modules, some events with less (installing).
ReHLDS is recommended
amxts is built and tested on ReHLDS with ReGameDLL and ReAPI, and on Valve's own HLDS. On plain HLDS a plugin is written the same, and the game events come through Ham Sandwich, the game's log and its messages: most are heard only after the game has acted, so they cannot be stopped or changed, and a few - fallDamage, giveDefaultItems, the player's movement - are not heard at all (a server without ReAPI).

How to put amxts on a server, and where each file goes: Installing on a server.

What amxts cannot do yet, and what to write instead, is on Limitations.

Modules

A module is a package of TypeScript that plugins share (Shared modules). A project lists the modules it uses in amxts.config.ts: a module one of them requires comes along, and a module no plugin uses is not built. The official ones:

  • menu-core — menus from INI, YAML or JSON files or from code (Menus): the module to add for a server's menus. A quick menu built in code alone is the core's Menu (menus);
  • config-core — configs in INI, YAML or JSON, read into typed objects (Configs);
  • resemiclip — who walks through whom, as a rule over two players, over the ReSemiclip module (resemiclip);
  • ftp since v0.2 — FTP, FTPS and SFTP: upload, download and list files on another server, every call a promise (ftp).

useFetch and fetch for web requests come with amxts (HTTP). More modules are in the modules catalog, and you can write your own.

Next

Getting started: a project, your first plugin, and the command that rebuilds it on every save.