Messages
The server tells each client what to draw and play through messages: a chat line, a HUD icon, the round clock, a death notice. A plugin hears a message before it leaves, reads it, changes it or stops it:
server.addMessageListener("death", (event) => {
if (event.headshot) print(0, `${event.killer?.name} - headshot - ${event.victim?.name}`);
});
server.addMessageListener("text", (event) => {
if (event.text == "#Round_Draw") event.preventDefault(); // the client does not get it
});
server.addMessageListener("team", (event) => {
if (event.team == "SPECTATOR") console.log(`${event.target?.name} watches`);
});
server.addMessageListener("roundTime", (event) => {
event.seconds = 90; // the clock shows 90
});
server.removeMessageListener("death", listener) stops it: pass the same name
and the same function that were added. Only the messages listened for reach
the plugin.
A message's name is written out as a string, and the editor lists the names,
each with what the game uses the message for and the game's own name of it:
death is the game's DeathMsg, chat its SayText. The table at the end
of the page has them all.
A few of the game's messages are one thing to a plugin, and one name hears
them all: progressBar is BarTime and BarTime2, which only adds where
the bar starts. The event has the fields of every one of them, and
event.name says which one came; a field the message that came does not
carry reads as 0, null or empty, and assigning it changes nothing -
startPercent is 0 on a BarTime.
server.addMessageListener("progressBar", (event) => {
console.log(`${event.name}: ${event.seconds} s from ${event.startPercent}%`);
});
The event
event.player is the player the message goes to, null for one sent to
everyone, so a player the message is about is a field of its own: target,
or its role - killer, victim, sender. preventDefault() stops the
message. event.name is the game's name of the message, "DeathMsg" for
death.
The game writes each message in a layout of its own, and a message whose
layout is known - almost every one Counter-Strike sends - has a field for
each of its arguments, named and typed: a player is a Player (null for
none), a flag a boolean, a team a Team, a weapon a WeaponKind, a mask
an array of names, a time in seconds. The editor lists them. Assigning a
field changes what the client gets: event.team = "CT".
server.addMessageListener("hideWeapon", (event) => {
event.flags = event.flags.concat(["money"]); // the money is hidden too
});
A message whose layout is not known - a bot's progress, the tutor's texts -
is read by the place of its arguments, through event.args, which every
message has for what its fields leave out:
server.addMessageListener("botProgress", (event) => {
console.log(`${event.args.length} ${event.args.number(0)}`);
});
event.args.number(i) and event.args.text(i) read the argument at i,
0 for the first; isText(i) tells which it is; setNumber(i, value) and
setText(i, value) change it.
An argument the message did not write - statusIcon's colour when it hides
the icon, the params of a text that takes none - reads as 0 or empty, and
assigning it changes nothing. A name the game has no message for is a build
error.
message_begin does not reach the listeners:
AMX Mod X hears only what goes through the engine. One sent with
emessage_begin does, and so do the ones player.screen sends and the one
player.money sends when it is written.Every message
| Name | The game's name | What it is | Fields |
|---|---|---|---|
adStop | ADStop | A player's HUD stops showing the round's advertisement. | - |
allowSpectate | AllowSpec | Whether a player may pick Spectate in the team menu. | allowed |
ammo | AmmoX | A player's reserve ammo of one kind on his HUD changes. | ammo, amount |
ammoPickup | AmmoPickup | A player picks up ammo: the notice at the side of his screen. | ammo, amount |
armor | Battery | A player's armour on his HUD changes. | armor |
armorType | ArmorType | The armour icon on a player's HUD: a vest, or a vest and a helmet. | helmet |
bombDrop | BombDrop | The bomb on the terrorists' radar: dropped or planted. | origin, planted |
bombPickup | BombPickup | The bomb is picked up: it leaves the terrorists' radar. | - |
botProgress | BotProgress | The progress bar a player's client shows while the bots learn a new map. | args |
botVoice | BotVoice | The voice icon over a bot who talks on the radio. | talking, target |
chat | SayText | A chat line. | sender, text, params |
closeBuyMenu | BuyClose | A player's buy menu is closed. | - |
corpse | ClCorpse | A dead player's body is left on the ground for the clients to draw. | model, team, target |
crosshair | Crosshair | Counter-Strike's own crosshair on a player's screen is shown or hidden. | shown |
currentWeapon | CurWeapon | The weapon in a player's hands and its clip on his HUD. | active, weapon, clip |
czCareer | CZCareer | A step of Condition Zero's career, its single-player campaign. | args |
czCareerHud | CZCareerHUD | Condition Zero's career on a player's HUD. | args |
damage | Damage | A player is shown the damage he took: the red marks at the side of his screen. | armor, damage, damageType, origin |
death | DeathMsg | A kill in the top right corner of every screen. | killer, victim, headshot, weapon |
flashlight | Flashlight | The flashlight icon on a player's HUD: on or off, and its battery. | on, battery |
flashlightBattery | FlashBat | The flashlight's battery on a player's HUD changes. | battery |
fog | Fog | The fog on a player's screen: its colour and density. | args |
forceCamera | ForceCam | The views a dead player may watch the game in, as mp_forcecamera and mp_forcechasecam allow. | args |
fov | SetFOV | A player's field of view is set. | fov |
gameMode | GameMode | Whether the game is played in teams, for a player's client. | args |
gameTitle | GameTitle | The game's title on a player's screen when he enters the game. | args |
geiger | Geiger | The Geiger counter's clicks a player hears near radiation. | range |
health | Health | A player's health on his HUD changes. | health |
hideWeapon | HideWeapon | The parts of a player's HUD that are hidden change. | flags |
hint | HudText, HudTextArgs, HudTextPro | A hint in the middle of a player's screen. | text, params |
hltv | HLTV | A note to the HLTV proxies, such as a new round's start. | args |
hostageKilled | HostageK | A hostage is killed: it leaves the counter-terrorists' radar. | hostage |
hostagePosition | HostagePos | A hostage on the counter-terrorists' radar. | hostage, origin |
initHud | InitHUD | A player's HUD is set up, when he enters the game. | - |
itemPickup | ItemPickup | A player picks up an item: the notice at the side of his screen. | item |
itemStatus | ItemStatus | The night vision and the defuse kit a player has, for his HUD. | nightVision, defuseKit |
location | Location | The place on the map a player is in, as the radio names it. | target, place |
menu | ShowMenu | A text menu on a player's screen - the team menu without VGUI, the radio, a plugin's menu. | more, text |
money | Money | A player's money on his HUD changes. | amount, flash |
moneyBlink | BlinkAcct | A player's money on his HUD blinks: he cannot afford what he tried to buy. | blinks |
motd | MOTD | A part of the message of the day, the window a joining player sees. | last, text |
nightVision | NVGToggle | A player's night vision is turned on or off. | on |
progressBar | BarTime, BarTime2 | The progress bar in the middle of a player's screen is shown or hidden, from empty or part of the way full. | seconds, startPercent |
radar | Radar | A teammate on a player's radar. | target, origin |
reloadSound | ReloadSound | The sound of a weapon reloaded nearby, for a player's client. | args |
requestState | ReqState | The game asks a player's client for its state, for the voice. | - |
resetHud | ResetHUD | A player's HUD is reset, at his spawn. | - |
roundTime | RoundTime | The round clock at the top of a player's HUD is set. | seconds |
scenarioIcon | Scenario | The scenario icon on a player's HUD, such as the bomb's or a hostage's. | active, sprite, alpha |
score | ScoreInfo | A player's row on the scoreboard. | target, frags, deaths, team |
scoreAttribute | ScoreAttrib | The marks the scoreboard shows beside a player: dead, the bomb, the VIP. | target, flags |
screenFade | ScreenFade | A player's screen is coloured, fading in or out - a flashbang, a fade to black. | duration, hold, direction, modulate, stay, color |
screenShake | ScreenShake | A player's view shakes - an explosion nearby. | amplitude, duration, frequency |
serverName | ServerName | The server's name a player's client shows. | serverName |
shadow | ShadowIdx | The sprite a player's client draws the players' shadows with. | args |
shellCasing | Brass | A spent shell a weapon throws out, for the clients to draw. | args |
showTimer | ShowTimer | The round clock appears on a player's HUD. | - |
sound | SendAudio | A sound played to a player, such as a radio line. | sender, sound, pitch |
spectatedHealth | SpecHealth, SpecHealth2 | The health of the player a spectator watches. | health, target |
spectator | Spectator | A player becomes a spectator, or stops being one, on the scoreboard. | target, spectator |
statusIcon | StatusIcon | A status icon on a player's HUD - the buy zone, the bomb - is shown, flashed or hidden. | state, sprite, color |
statusText | StatusText | The status line at the bottom of a player's screen, such as the name of the player he aims at. | line, text |
statusValue | StatusValue | A value the status line shows, such as the player a player aims at. | slot, value |
taskTime | TaskTime | The countdown of a task on a player's HUD, such as rescuing the hostages in a career. | seconds, active, fade |
team | TeamInfo | A player's team on the scoreboard. | target, team |
teamScore | TeamScore | A team's score on the scoreboard. | team, score |
text | TextMsg | A text from the game - an announcement, a hint - in chat, the console or the middle of the screen. | destination, text, params |
train | Train | The speed of the train a player drives, on his HUD. | speed |
tutorClose | TutorClose | A tutor's message on a player's screen closes. | - |
tutorLine | TutorLine | A tutor's pointer on a player's screen, at a thing in the world. | args |
tutorState | TutorState | The tutor's state on a player's client. | args |
tutorText | TutorText | A tutor's message on a player's screen. | args |
vguiMenu | VGUIMenu | A VGUI menu of the game opens on a player's screen: the team menu, the class menu, the buy menu. | menu |
viewMode | ViewMode | A player's view goes back to first person. | - |
voiceMask | VoiceMask | The players a player hears on the voice chat, and the ones he has muted. | args |
weaponList | WeaponList | A weapon's description for a player's client: its ammo, its slot, its place in the slot. | classname, ammo, maxAmmo, ammo2, maxAmmo2, slot, position, weapon |
weaponPickup | WeapPickup | A player picks up a weapon: the notice at the side of his screen. | weapon |
weather | ReceiveW | The weather on the map, rain or snow, for a player's client. | args |
Cvars
A cvar is a server setting with a name: mp_freezetime, sv_gravity, or one of your plugin's own. A Cvar object reads and writes one:
Storage
Storage keeps text by key, like a Map<string, string>, but on disk: what a plugin stores survives a map change and a server restart. It is the place for a player's saved points, his last visit, a preference.