Plugin API reference
Generated by tools/gen_plugin_api.py from native/game/src/plugins/api.toml: do not edit. API version 1. The design is in docs/plugins_api.md.
Functions
cs.on(event: string, handler: (...any) -> ...any, options: HookOptions?) -> Hook
Joins a handler to an event. It runs after the game handled it, or before with { before = true }. A name with a colon is another plugin's event ("stats:record", see cs.emit): its handler gets the values emitted and may return false to stop the later ones.
cs.command(name: string, handler: (...any) -> ...any, options: CommandOptions?) -> boolean
A command: from a player's console, the server console (player nil) and, unless chat = false, the chat as /name or !name. The handler gets the player and the words (args[1]..., args.line the whole line after the name). A name with + or - before is a key bind's press and release (bind mouse3 +hook), never in the chat. False when another plugin has that command already: it stays that plugin's (the server console says so) and the rest of this plugin goes on.
cs.reply(player: Player?, text: string)
Answers where a command came from: the player's chat if typed there, else their console; the server console for nil.
cs.cvar(name: string, default: string, options: CvarOptions?) -> Cvar
Registers a setting the plugin owns (it keeps its value after the plugin unloads). Registering it again returns the same setting, with the options given changed.
cs.find_cvar(name: string) -> Cvar?
Any existing setting by name, or nil.
cs.after(seconds: number, handler: (...any) -> ...any, options: TimerOptions?) -> Timer
Runs a function once after some seconds of game time.
cs.every(seconds: number, handler: (...any) -> ...any, options: TimerOptions?) -> Timer
Runs a function every so many seconds of game time (at least one server frame apart).
cs.time() -> number
The game clock in seconds (it restarts with each map).
cs.chat(to: (Player | {Player})?, text: string)
Writes in the chat of one player, a list of them, or everyone (nil). Colour tags: {default} {team} {green} {red} {blue} {grey} {white} {#rrggbb}.
cs.center(to: (Player | {Player})?, text: string)
Text in the middle of the screen of one player, a list, or everyone (nil).
cs.console(to: (Player | {Player})?, text: string)
A line in the console of one player, a list, or everyone (nil).
cs.print(text: string)
A line in the server console, after the plugin's name.
cs.log(text: string)
A line in the server log, after the plugin's name.
cs.map() -> string
The current map's name (empty while plugins load at the server's start, before the first map).
cs.server_command(line: string)
Runs a line in the server console (after the current frame). Needs the server_console permission: that line has the full powers of the server console.
cs.team(name: string) -> Team
A team: t or ct.
cs.hostages() -> {Hostage}
The map's hostages (rescued and dead ones too).
cs.grenades() -> {Grenade}
The grenades in the world (thrown, and smoking), and the planted bomb.
cs.fields(of: any) -> {FieldInfo}
What raw access reaches: nil gives the entity variables; an Entity also the members of its game classes; "rules" the game rules' members. Needs no permission (it reads nothing).
cs.players() -> {Player}
The connected players, by slot.
cs.max_players() -> number
How many players the server takes (its slots).
cs.player(slot: number) -> Player?
The player in a slot, or nil.
cs.entity(index: number) -> Entity?
The entity of an index (0: the world), or nil.
cs.find_entities(options: FindOptions?) -> {Entity}
The entities matching every option given (all of them for none), in index order.
cs.create_entity(class: string, options: CreateOptions?) -> Entity?
Makes an entity of a class (info_player_start, info_target...); nil if the class does not exist.
cs.register_entity(name: string, class: EntityClass)
Defines an entity class: maps may place it (its map keys reach spawn) and cs.create_entity makes it. The name may not be one of the game's classes or another plugin's. Registered in plugin_start its files are precached at every map; registered later, from the next map.
cs.entity_classes() -> {string}
The entity classes the plugins registered.
cs.patch_map(handler: (...any) -> ...any)
Changes each map's entities before they spawn: the handler gets the map's name and its entities as a list of key tables (the first is the world) and edits the list in place (remove, change, add tables; values are strings). The plugin's maps/all.toml and maps/<map>.toml apply first. cs.precache works in it.
cs.register_weapon(name: string, weapon: WeaponDef)
Defines a weapon from one of the game's guns with other numbers, models and sound: cs.register_weapon("weapon_ak47_gold", { base = "ak47", damage = 50, clip = 40, price = 3500 }). Give it by its name (player:give, maps, cs.create_entity); to the game it is then its base gun (Weapon.variant tells it apart), so a player holds one of the two. The clients get its numbers and predict it as the server runs it.
cs.register_mode(name: string, mode: ModeDef)
Defines a game mode: cs.register_mode("deathmatch", { title = "Deathmatch", off = { "rounds" }, respawn = 2, objectives = false }). One mode runs at a time (cs.set_mode); its title shows in the server list.
cs.set_mode(name: string?) -> boolean
Runs a mode (stopping the one running), or none (absent): false when there is no such mode. cs.game.mode names the one running.
cs.register_grenade(name: string, grenade: GrenadeDef)
Defines a grenade from one of the game's with another fuse, flight, blast, models, or a blast of the plugin's own: cs.register_grenade("weapon_firegrenade", { base = "hegrenade", radius = 200, price = 500, detonate = burn }). Give it by its name; to the game it is then its base grenade (Weapon.variant and Grenade.variant tell it apart), and a player's grenades of one base are all the last one bought.
cs.buy_items() -> {BuyItem}
The buy menu's items: the game's and the plugins'.
cs.set_buy_item(id: string, change: BuyChange)
Changes an item of the buy menu: its price, whether it can be bought, its team, its name. The players' buy menus follow.
cs.register_buy_item(id: string, item: BuyItemDef)
Adds an item to the buy menu: players buy it with the menu or by typing its id, under the game's checks (alive, buy zone and time, team, money, player_buy); its buy callback gives it.
cs.trace_line(start: vector, stop: vector, options: TraceOptions?) -> TraceResult
Traces a line from start to end.
cs.trace_hull(start: vector, stop: vector, hull: string, options: TraceOptions?) -> TraceResult
Traces a box from start to end: point, human (standing player), large or head (ducking player).
cs.trace_entity(entity: Entity, start: vector, stop: vector, hull: string) -> TraceResult
Traces a hull from start to end against one entity's model only (as the movement code would meet it): point, human, large or head.
cs.trace_texture(entity: Entity, start: vector, stop: vector) -> string
The name of the texture a line from start to end hits on an entity's model ("": none).
cs.point_contents(point: vector) -> string
What is at a point: empty, solid, water, slime, lava, sky or ladder.
cs.emit_sound(entity: Entity, sample: string, options: SoundOptions?)
Plays a sound from an entity (a path under sound/; it must be precached).
cs.precache(path: string) -> boolean
Gets a file ready for the map, so players have it (downloaded when missing): a model or sprite (models/...mdl, sprites/...spr), a sound (sound/...wav) or any other file. Only in a map_start handler (while the map loads); again each map. The server finds a plugin's own files in its content/ folder (under the game's). Returns false when the server has no such file.
cs.model_index(path: string) -> number
A precached model's or sprite's number this map, as game messages carry it (a TempEntity's sprite, a beam's model); 0 when it is not precached.
cs.dynamic_light(to: (Player | {Player})?, origin: vector, options: LightOptions?)
A light at a point for a moment, for one player, a list, or everyone (nil).
cs.set_light(to: (Player | {Player})?, entity: Entity, options: EntityLightOptions?)
Hangs a steady light on an entity (a flashlight) for one player, a list, or everyone (nil); again to change it. Sent once: the players' games draw it each frame where the entity is shown (a player's own as its view moves), so it does not flicker or trail. One per entity; it goes with the entity or the map. A player who joins later gets the ones for everyone.
cs.clear_light(to: (Player | {Player})?, entity: Entity)
Takes the light cs.set_light hung on an entity off, for one player, a list, or everyone (nil).
cs.mark_line(to: (Player | {Player})?, id: string, from: vector, target: vector, options: MarkOptions?)
Draws a line in the world for one player, a list, or everyone (nil), named id (again with the same id to change it; the other plugins' ids are apart). Sent once and again only when changed: the players' games draw it every frame, sharp, gliding to a new place instead of jumping. Not seen by players who join later.
cs.mark_text(to: (Player | {Player})?, id: string, at: vector, text: string, options: MarkOptions?)
Writes a text in the world (the game's font, sharp at any size), for one player, a list, or everyone (nil), named id as cs.mark_line's. It faces the viewer unless facing turns it (on a floor: facing up, up the way it reads).
cs.unmark(to: (Player | {Player})?, id: string?)
Erases the plugin's mark id (nil: all its marks) for one player, a list, or everyone (nil).
cs.beam(to: (Player | {Player})?, from: any, target: any, options: BeamOptions?)
Draws a beam between two points or entities (a beam to an entity follows it), for one player, a list, or everyone (nil).
cs.create_beam(from: any, target: any, options: BeamOptions?) -> Entity?
Makes a beam that stays (an entity) between two points or entities, until it is removed; seen by everyone who sees that place (hide it from players with Player:hide). Move it with Entity:set_beam. life does not apply.
cs.beam_follow(to: (Player | {Player})?, entity: Entity, options: BeamOptions?)
A trail behind a moving entity, for one player, a list, or everyone (nil).
cs.beam_clear(to: (Player | {Player})?, entity: Entity)
Removes the beams and trails following an entity, for one player, a list, or everyone (nil).
cs.sparks(to: (Player | {Player})?, at: vector)
A burst of sparks at a point, for one player, a list, or everyone (nil).
cs.explosion(to: (Player | {Player})?, at: vector, options: EffectOptions?)
An explosion (sprite, light and sound, no damage: Entity:damage or cs.radius_damage for that), for one player, a list, or everyone (nil).
cs.radius_damage(at: vector, damage: number, radius: number, options: DamageOptions?)
Hurts what is within radius of a point as an HE grenade's blast does (less with distance; the server's grenade settings apply). Players and breakables react as to the game's own blasts.
cs.smoke(to: (Player | {Player})?, at: vector, options: EffectOptions?)
A puff of smoke rising from a point, for one player, a list, or everyone (nil).
cs.sprite(to: (Player | {Player})?, at: vector, sprite: string, options: EffectOptions?)
Shows a sprite (sprites/...spr, precached) at a point for a moment, for one player, a list, or everyone (nil).
cs.tracer(to: (Player | {Player})?, from: vector, target: vector)
A bullet's tracer flying from one point to another, for one player, a list, or everyone (nil).
cs.decal(to: (Player | {Player})?, at: vector, name: string, entity: Entity?)
Puts a decal of the game's ({scorch1, {bigshot1, {blood1... as decals.wad names them) on the surface at a point, on the world or on a brush entity, for one player, a list, or everyone (nil). Players who join later do not see it.
cs.blood(to: (Player | {Player})?, at: vector, options: EffectOptions?)
A spurt of blood at a point, for one player, a list, or everyone (nil).
cs.particles(to: (Player | {Player})?, at: vector, options: EffectOptions?)
A burst of particles of one colour spreading from a point, for one player, a list, or everyone (nil).
cs.add_game_bot(options: GameBotOptions?) -> boolean
Adds a bot of the game's, as bot_add does (after the current frame; the first bot on a map without a bot mesh waits while it is made). False when no profile is free for that team and difficulty, or the profile is unknown or already playing. The bot's own settings (bot_quota, bot_knives_only...) stay the server's cvars.
cs.ban(id: string, minutes: number)
Puts a player ID (CSID:...) or a computer (HWID:...) on the server's ban list (banid), for minutes (0: for good, written to bans.toml). Players on it are refused when they connect; one playing now stays (Player:ban kicks).
cs.unban(id: string)
Takes a player ID or a computer off the server's ban list (and out of bans.toml).
cs.bans() -> {Ban}
The player ID and computer bans in force (cs.ban, Player:ban, banid, bans.toml); address bans are not in it.
cs.http(url: string, options: HttpOptions?, callback: ((...any) -> ...any)?)
Sends an HTTP request (http:// or https://, the certificate checked; a web API) to a host the plugin's manifest lists (hosts). The callback gets a table: status, ok (a 2xx status), body, headers (lower-case names) and, when it failed without an answer, error. It always runs on a later frame, never inside the call; requests of an unloaded plugin are dropped.
cs.add_bot(name: string, options: BotOptions?) -> Player?
Adds a bot this plugin moves itself (a replay): no AI, no collision, no damage, nothing in the world reacts to it; it stays where Player:pose puts it. Spectators can watch it. Nil when the server is full. Player:kick removes it; it goes with its plugin.
cs.map_entities() -> any
The loaded map's entities as the BSP lists them (with the plugins' map patches), before the game spawned them: one table of key and value strings each (classname, model, lip, wait...).
cs.vote(title: string, options: {string}, done: (...any) -> ...any, voters: (Player | {Player})?, seconds: number?) -> boolean
Asks players to choose one of the options (a numbered menu, keys 1 to 9). It ends when every voter chose or after seconds (default 15); done then gets { counts, votes, voters, winner, option }: the votes per option, how many voted, how many could, and the option with the most votes (its number and text; absent on a tie or with no votes). The title and each option that is a key of the plugin's texts (lang/) show in each voter's language. One vote runs at a time: false when another is running. Bots do not vote.
cs.vote_running() -> boolean
A vote is running (any plugin's).
cs.cancel_vote()
Ends this plugin's vote now, without calling its done.
cs.change_map(map: string, delay: number?) -> boolean
Changes the map after delay seconds (default at once): false when the server has no such map.
cs.maps() -> {string}
The maps the server can load, sorted (names without maps/ and .bsp).
cs.menu(player: Player, title: string, items: {string}, handler: (...any) -> ...any, options: MenuOptions?) -> number
Shows a numbered menu (keys 1 to 9 for the items, 0 for the exit). The handler gets the player and the key (0: exit); a menu shown later replaces it. Colour codes in the texts: \y yellow, \w white, \r red, \d grey. Returns the menu's id (see cs.menu_shown).
cs.menu_shown(player: Player) -> number
The id cs.menu returned for the menu the player has open, if it is this plugin's and still open (0: none; a key, another menu, the game's own menus and the timeout close it).
cs.close_menu(player: Player)
Closes the player's menu (if it is a plugin's).
cs.send_message(message: string, values: any, options: SendMessageOptions?)
Sends a game message to clients as the game would write it: a message the client knows (StatusIcon, ScreenShake, BarTime... or TempEntity), its values as pairs { kind, value } with kinds byte, char, short, long, angle, coord, entity and string. A message of a fixed size must fill it. It passes through client_message like the game's. Needs the raw_messages permission (a wrong message misleads the clients' HUD).
cs.hud_message(to: (Player | {Player})?, text: string, options: HudMessageOptions?) -> number
A HUD message as the game shows them (a map's game_text, AMX Mod X's show_hudmessage) on the screen of one player, a list, or everyone (nil). Returns the channel it went on.
cs.dhud_message(to: (Player | {Player})?, text: string, options: DhudMessageOptions?)
A director's HUD message (AMX Mod X's show_dhudmessage): larger letters, up to eight at once apart from the HUD messages, on the screen of one player, a list, or everyone (nil). At most 127 characters.
cs.hud_text(to: (Player | {Player})?, text: string, options: HudTextOptions?) -> string
A text on the HUD of one player, a list, or everyone (nil), drawn as the game's HUD messages are, with any of their effects, at any size, as many as wanted (no channels: each has its id). Returns its id.
cs.hud_text_remove(to: (Player | {Player})?, id: string?)
Takes the plugin's HUD text with this id (nil: all of the plugin's) off the screen of one player, a list, or everyone (nil).
cs.notify(to: (Player | {Player})?, text: string, options: NoticeOptions?)
Shows a notice on the HUD of one player, a list, or everyone (nil): a box with an optional title, icon, colours, progress bar and sound, at any of nine places or any point, stacked with the others there. The text may use the chat's colour tags and several lines.
cs.close_notice(to: (Player | {Player})?, id: string?)
Closes the plugin's notice with this id (nil: all of the plugin's notices) for one player, a list, or everyone (nil).
cs.send_client(to: (Player | {Player})?, channel: string, data: any)
Sends a value to the plugin's client script of one player, a list, or everyone (nil), which gets it in its cl.on_message(channel, fn) handlers. The value is copied: nil, booleans, numbers, strings, vectors and tables of those (at most 16 KB packed).
cs.on_client(channel: string, fn: (...any) -> ...any)
Handles the values the plugin's client scripts send on a channel (cl.send(channel, value)): fn gets the player and the value (at most 2 KB packed; a player sending too fast loses messages). The same channel again replaces the handler.
cs.hud_widget(to: (Player | {Player})?, id: string, widget: any)
Shows or changes a widget on the HUD of one player, a list, or everyone (nil), no client script needed. The widget is a table: kind (text, bar, icon, image, list, timer or radar), x and y (its place as a fraction of the screen, 0 to 1), align (left, center or right), color (#rrggbb or #rrggbbaa) and the kind's fields: text text, size; bar w, h, value, max, back (its background colour), label; icon image (a PNG or JPG of the plugin's content), w, h; image the same, its x/y the picture's anchor point, and the image options of cl.draw.image (fit, slice, frames, count, frame, fps, rotation, filter, alpha: docs/client_scripts.md); list title, items (strings), size; timer seconds (counts down from now; with up: counts up from now), label, size; radar size, range (world units across), dots (a list of {pos = vector, color = ...}). Sizes are in pixels of a 1080-line screen.
cs.loading_screen(screen: any, options: any)
Sets the loading screen's pictures: shown, cross-fading, while players load the map, under its texts and bar. The screen is {images = {...}, seconds = 6, fade = 0.8, fit = "cover" | "contain", order = "loop" | "random"}: 1 to 8 PNG or JPG of the plugin's content, each at most 1920x1080 and 2 MB together; seconds 2 to 60 each, fade 0 to 5. With {map = "name"} the list is that map's (it wins there over the server's). nil takes the plugin's list away. It counts from the next map start (the pictures are precached then); players' games download them before the rest and keep them, so a second visit shows them from the start. Players may turn servers' loading pictures off.
cs.window(to: (Player | {Player})?, id: string, window: any)
Opens (or replaces, the same id) a window of the plugin on the screen of one player, a list, or everyone (nil), drawn by the game in its own style at any resolution. The window is a table: title, size ({w, h} in pixels of a 1080-line screen, made smaller on a screen it does not fit; {0, 0}: as large as what it holds), anchor (center by default, or top_left, top, top_right, left, right, bottom_left, bottom, bottom_right) and offset ({x, y} from it), modal (true by default: the cursor shows and the view stops; one at a time, another closes it; false: a panel that leaves the game playable, up to 4), hud (a readout on the HUD: no cursor, no clicks, nothing to close; up to 8), close (false: no close button, and Escape does not close it), close_on_death, its look (frame false: none; back, border, border_width, radius, back_image, back_slice, padding), fade (seconds it takes to appear), and body: an element. Elements are tables with a kind and optional id (what events and cs.window_set name it by), style (a name of cs.window_style, or a list of them), enabled, visible, color, back, size, max_size, grow, tooltip, border, border_width, radius, back_image, back_slice, hover and pressed ({back, color, border}), font (regular, medium, semibold, bold), fade, blink (its period in seconds), and in a stack place (an anchor) and offset; the kinds: panel, row, column, stack (children over each other; children, gap, padding: a number or {left, top, right, bottom}, align; click: clicked as a whole), grid (columns), list (scrolls: height; horizontal), table (columns: {title, width, grow, align, color}, rows: lists of cells, each a text, a number or an element; height, click_rows, sortable, sorted, descending, selected), text (text, font_size, align, wrap, bold, ellipsis, rich: [b], [i], [color=#hex], [size=n] kept), image (image and the image options of cl.draw.image, or avatar: a player's CSID: ID, its profile picture), button (text, image, key 1 to 9, font_size, flat), slot (an item: image, name, count, price, locked, selected, key), bar (value, max, label, smooth, vertical), slider and number (min, max, step, value, label), check and toggle (text, value), field (value, placeholder, max_length, password, live), textarea (value, placeholder, max_length up to 1024, height, live), color (value, alpha), select (options: {id, text}, value; multiple: many chosen, value a list, height) and choice, line (vertical), tabs (tabs: a list of {title, body}, selected) and space. Buttons, slots, clickable containers, tables and fields may send a list of inputs' ids: their events carry those inputs' values (ev.values). Slots, images and containers with an id may be dragged (drag) and dropped on (drop). A text may be { t = key, args = {...} }: the plugin's text (lang/) in each player's language, sent again when they change it. A wrong window fails with where it is wrong (body.children[3].price: a number from 0 to 1e+09); at most 512 elements, 16 levels and 32 KB as sent. Opened again with the same id, the lists' and tables' scroll, the tab chosen and the field being typed in stay. What the player does comes to cs.on_window. docs/plugin_windows.md.
cs.window_set(to: (Player | {Player})?, id: string, element: string, changes: any)
Changes one element of the plugin's open window (by its id; "": the window's own title) for one player, a list, or everyone (nil), without building it again: the fields every element has (enabled, visible, color, back, size, the looks, fade, blink...) and the kind's own (text, rich, bold, ellipsis, image, frame, name, count, price, locked, selected, value, min, max, step, label, placeholder, options, sorted, descending, a container's gap and padding), style too; children replaces what a container holds and rows a table's rows, checked as cs.window checks them (the scroll and the focus stay). cs.window_update changes several at once.
cs.window_update(to: (Player | {Player})?, id: string, changes: any)
Changes several elements of the plugin's open window at once, as cs.window_set changes one: cs.window_update(p, "shop", { money = { text = "$800" }, buy = { enabled = false } }).
cs.window_style(name: string, fields: any)
Names a style of the plugin's windows: the fields an element with style = "name" (or a list of names, later ones over earlier) has unless it gives them itself, any field but kind, id, send and what it holds: cs.window_style("danger", { back = "#3a1010", border = "#ff5050", radius = 6, hover = { back = "#5a1818" } }). Kept until the plugin stops; nil removes it; at most 128. Windows sent after it use it.
cs.window_values(player: Player, id: string) -> any
The values of the inputs of the plugin's open window for the player, as they left them: { [id] = value } (a field's or textarea's text, a number's or slider's number, a check's or toggle's boolean, a select's or choice's option id, a select of multiple a list of ids, a color's #rrggbb, the tabs' tab); nil when it is not open.
cs.window_close(to: (Player | {Player})?, id: string)
Closes the plugin's window with this id ("": all of the plugin's) for one player, a list, or everyone (nil). Its handler does not hear it.
cs.window_open(player: Player, id: string, plugin: string?) -> boolean
Whether the plugin's window with this id is open for the player; with plugin, another plugin's (by its name: a plugin's tests check its windows so).
cs.on_window(id: string, fn: any)
Handles what players do in the plugin's window with this id: fn gets the player and an event {window, id, kind, value, values}: click (a button, a slot, a container with click; a table's row from 1 as the value), sort (a table's column from 1), change (a slider's or number's number, a check's or toggle's boolean, the tabs' tab from 1, a select's or choice's option id, a select of multiple's list of ids, a color's #rrggbb, a field's or textarea's text as it loses focus or, live, as it is typed), submit (a field's text on Enter), drop (on an element with drop: the id of the one dragged onto it as the value) or close (Escape or its close button, another modal window opening, the player dying with close_on_death or leaving; never cs.window_close). An element with send gives values: { [input id] = value } as the player left them (cs.window_values has them all). fn may be a table instead: { click = { buy = fn, ["*"] = fn }, change = fn, close = fn }, by the event's kind and then the element's id (*: any other). Only what fits the window as sent comes: an element there, enabled and shown, a value within its bounds; nothing from a hud window; at most 30 events a player a second. The same id again replaces the handler.
cs.hud_remove(to: (Player | {Player})?, id: string)
Removes the plugin's widget with this id ("": all of the plugin's widgets) from one player, a list, or everyone (nil).
cs.read_file(path: string) -> string?
The text of a file in the plugin's data folder; nil when there is no such file. At most 16 MB.
cs.write_file(path: string, text: string)
Writes a file in the plugin's data folder (its folders are made), replacing it whole: a crash mid-write leaves the old file, never half of the new one. At most 16 MB.
cs.append_file(path: string, text: string)
Adds text at the end of a file in the plugin's data folder (made when missing): logs. The file may grow to 16 MB.
cs.remove_file(path: string) -> boolean
Removes a file (or an empty folder) from the plugin's data folder. Returns whether there was one.
cs.file_exists(path: string) -> boolean
Whether the plugin's data folder has this file or folder.
cs.list_files(folder: string?) -> {string}
The names in a folder of the plugin's data folder (nil: the data folder itself), sorted; folders end in /. Empty when the folder does not exist.
cs.json_encode(value: any, options: JsonOptions?) -> string
A value as JSON. Tables whose keys are 1 to n are lists, other tables objects with string keys (sorted, so the text is stable); a vector is a list of 3 numbers; an empty table is []. Functions, other key types, NaN, infinities, invalid UTF-8 and tables nested over 128 levels (or in themselves) are errors.
cs.json_decode(text: string) -> any
The value a JSON text holds: objects and lists become tables, null nil. Raises on invalid JSON (with the line and column).
cs.read_json(path: string) -> any
json_decode of a file in the plugin's data folder; nil when there is no such file.
cs.write_json(path: string, value: any, options: JsonOptions?)
json_encode (pretty by default) written with write_file.
cs.websocket(url: string, options: WebSocketOptions?) -> WebSocket
Connects a WebSocket client (ws:// or wss://, the certificate checked) to a host the plugin's manifest lists.
cs.tcp(host: string, port: number, options: SocketOptions?) -> Socket
Connects a TCP socket (needs the raw_sockets permission; the host must be in the manifest).
cs.udp(host: string, port: number) -> Socket
A UDP socket that sends to and receives from one host and port (needs the raw_sockets permission; the host must be in the manifest).
cs.export(name: string, fn: (...any) -> ...any)
Offers a function to the other plugins (cs.import); the same name again replaces it. What it gets and returns is copied between the plugins' VMs: nil, booleans, numbers, strings, vectors, buffers, the API's objects (players, entities...) and tables of those; never functions.
cs.plugins() -> {PluginInfo}
The loaded plugins, in load order (the one calling included).
cs.plugin_info() -> PluginInfo
The calling plugin's own PluginInfo.
cs.exports(plugin: string) -> {string}
The names a loaded plugin exports, sorted (empty when it is not loaded).
cs.import: (plugin: string, name: string) -> (...any) -> ...any
A function that calls another plugin's export (list the plugin in depends so it loads first). Arguments and results are copied (see cs.export); an error inside it raises here. The export is looked up at each call, so it follows a reload of that plugin.
cs.emit: (event: string, ...any) -> boolean
Runs every plugin's handlers of "<this plugin>:<event>" (cs.on("stats:record", fn)), by priority, now, with copies of the values. A handler that returns false stops the rest; returns whether none did.
cs.t(language: string, key: string, args: any) -> string
The plugin's text for key in a language (the server console's, a log's); see Player:t.
cs.languages() -> {string}
The languages the plugin has texts in (its lang/*.toml), sorted.
cs.toml_encode(value: any) -> string
A table as TOML text (strings, numbers, booleans, lists and tables; keys sorted).
cs.toml_decode(text: string) -> any
TOML text as a table (an error for text that is not TOML).
cs.read_toml(path: string) -> any
toml_decode of a file in the plugin's data folder; nil when there is no such file.
cs.write_toml(path: string, value: any)
toml_encode written with write_file.
cs.read_buffer(path: string) -> any
A file in the plugin's data folder as a buffer (read and written with Luau's buffer library: integers, floats, strings at any offset); nil when there is no such file.
cs.write_buffer(path: string, data: any)
Writes a buffer (or a string) as a file in the plugin's data folder, whole.
cs.read_file_async(path: string, options: AsyncFileOptions?, callback: (...any) -> ...any)
Reads a file in the plugin's data folder on an I/O thread (up to 256 MB); the callback gets (content, nil) or (nil, error) on a later frame.
cs.write_file_async(path: string, data: any, options: AsyncFileOptions?, callback: ((...any) -> ...any)?)
Writes a string or a buffer as a file in the plugin's data folder on an I/O thread (replaced whole, or appended); the callback, if any, gets (true, nil) or (nil, error) on a later frame.
cs.open_recording(name: string, callback: (...any) -> ...any)
Reads a demo the server recorded (Player:record; its name, without .csdem) on an I/O thread, after its recording is written; the callback gets (recording, nil) or (nil, error) on a later frame. The commands stay in memory until Recording:close or the plugin unloads.
cs.remove_recording(name: string) -> boolean
Deletes a demo the server recorded (its name, without .csdem), once what is being written to it is done. False when the name is not valid or it is being recorded.
cs.recording_part(name: string, offset: number, length: number, callback: (...any) -> ...any)
Reads bytes of a demo the server recorded (its name, without .csdem) on an I/O thread, after its recording is written: from offset, at most length (1 to 4194304). The callback gets (bytes, size) (a string, possibly shorter at the end; the file's whole size) or (nil, error) on a later frame. For sending it somewhere in pieces (cs.http).
cs.database(name: string) -> Database
Opens (or makes) the SQLite database <name>.db in the plugin's data folder; the same object for the same name. Names: 1 to 64 of a-z, 0-9, _ and -.
cs.store(name: string) -> Store
Opens (or makes) the key-value store <name>.store in the plugin's data folder (read whole at once; expired keys dropped); the same object for the same name.
Classes
Player
A connected player (or bot). The same object for the whole connection; using it after the player left is an error.
| member | type | |
|---|---|---|
slot | number | The player's slot, 1 to the server's maximum. |
name | string | The player's name. |
id | string | The player ID (CSID:...), BOT for bots, LAN only in recordings made before accounts. |
account | boolean | Signed in with a Classic Strike account (its certificate checked): every player on an internet server; false for bots, LAN players without one and the local game's own. |
verified | boolean | Its account's email is verified. |
full_game | boolean | Its account owns the full game (or a trial in force). Online servers only admit such players; on a LAN it tells who has it. |
hwid | string | The player's computer (HWID:...) as its account certificate names it, empty without one (bots, LAN players, older certificates). banid <minutes> <HWID:...> bans the computer: every account on it. |
address | string | The IP address the player connected from, without the port (loopback for the local game, empty for bots). |
bot | boolean | Whether it is a bot. |
connected | boolean | False after the player left (every other member then raises an error). |
in_game | boolean | Whether the player has joined the game (past connecting). |
admin | boolean | Whether the player is in admins.toml. |
immunity | number | The player's immunity in admins.toml (the highest of its entry's and groups'; 0: none). |
language | string | The player's language as the game sent it (es, pt_br...; the plugin's own when the game sent none). |
team | string | t, ct, spectator or none. |
alive | boolean | Whether the player is alive. |
ping | number | The player's ping in milliseconds. |
entity | Entity | The player's entity. |
origin | vector | Where the player is (setting it moves the player as it is, see also :teleport). (settable) |
velocity | vector | The velocity. (settable) |
base_velocity | vector | The velocity of what carries the player (conveyors, pushes). (settable) |
angles | vector | Where the player looks; setting it turns the player's view. (settable) |
punch_angle | vector | The view kick (recoil, falls). (settable) |
view_offset | vector | The eyes' offset from the origin. (settable) |
flags | number | The entity flags (cs.flag). (settable) |
buttons | number | The buttons held (cs.button). |
old_buttons | number | The buttons held in the previous command. |
in_duck | boolean | Whether the player is in the middle of ducking. (settable) |
duck_time | number | The time left of the duck transition. (settable) |
fall_velocity | number | The downward speed of the fall. (settable) |
stamina | number | The jump's stamina penalty (0: none). (settable) |
velocity_modifier | number | The speed factor after being hit (1: none). (settable) |
movetype | string | walk, noclip, fly, none, follow... (settable) |
solid | string | not, trigger, bbox, slidebox or bsp. (settable) |
health | number | The health. (settable) |
armor | number | The armor. (settable) |
takedamage | boolean | Whether the player can be hurt. (settable) |
gravity | number | The gravity factor (1: normal). (settable) |
air_accelerate | number | The player's own air acceleration (as sv_airaccelerate, and predicted on the player's client); 0 goes back to the server's. (settable) |
maxspeed | number | The top speed (see :reset_maxspeed). (settable) |
ground | Entity? | What the player stands on (set it with the on_ground flag to put the player on an entity). (settable) |
water_level | number | 0 dry, 1 feet, 2 waist, 3 under water. |
hide_hud | number | The parts of the HUD hidden (cs.hide_hud). (settable) |
fov | number | The field of view (0 or 90: normal). (settable) |
flash_battery | number | The flashlight's battery, 0 to 100. (settable) |
weapon | string | The class name of the weapon in hand ("": none). |
active_weapon | Weapon? | The weapon in hand. |
money | number | The money. (settable) |
frags | number | The score (the scoreboard shows a change at once). (settable) |
deaths | number | The deaths (the scoreboard shows a change at once). (settable) |
hear_players | boolean | Hears the other players' sounds (steps, weapons, shots; on by default). Off: only the player's own, and a spectator the watched player's. (settable) |
observer_target | Player? | Who a spectator watches. |
puppet | boolean | A bot made with cs.add_bot. |
recording | string? | The demo the server is recording of the player (Player:record, sv_record, sv_autorecord), nil when none. |
recording_time | number? | Where the player's recording is now: seconds since its first command, on the clock cs.open_recording gives its commands (RecordedCommand.time) and a bot plays it on (Player:play shows at each moment what was shown then). Nil when not recording or before the first command. A plugin marks its own moments of a run with it (a pause, a sound) to find them in the recording. |
playing | boolean | A bot made with cs.add_bot is playing a recording (Player:play). |
play_time | number? | Where a bot's playback is, in seconds of the recording (Player:play); nil when it plays none. |
speaking | boolean | The player is talking on the voice chat now (a voice packet in the last 0.3 seconds; player_voice tells the changes). |
observer_mode | number | How a spectator watches: 0 not spectating, 1 chase locked, 2 chase free, 3 roaming, 4 in eye, 5 map free, 6 map chase. |
view_model | string | The first-person weapon model (models/v_knife.mdl; empty: none, the weapon hidden for this player only). (settable) |
weapon_model | string | The weapon model others see in the player's hands. (settable) |
buy_zone | string | Where the player may buy: map (the map's zones and mp_buy_anywhere, the default), anywhere or nowhere. The buy time still applies. Back to map at each map. (settable) |
can_buy | boolean | Whether the player may buy now (alive, in a buy zone, within the buy time). |
model | string | The player model by its name (terror, or a precached models/player/<name>/<name>.mdl as <name>), kept over team and spawn changes; empty: the team's own. (settable) |
-
:respawn(): Spawns the player again (alive, at a spawn point), whatever the round. -
:join_team(team: string) -> boolean: Joinst,ctorspectatoras from the team menu, with a random appearance; the game's rules on team changes apply (but not the one change per death, andspectatorworks at any time: a living player is taken out without dying). Returns whether the player is on that team now. -
:switch_team() -> boolean: Moves a player ontorctto the other team at once, alive and keeping the items, as the game's team swap does (the other team's matching model; a defuse kit is dropped). False for a player on no team or spectating. -
:strip(): Takes every item (weapons, armor, the C4, kits), leaving the suit. -
:give(item: string, options: GiveOptions?) -> Entity?: Gives an item (weapon_usp,item_kevlar...) even when pickups are off; returns it, nil if the player could not take it. -
:take(item: string) -> boolean: Takes one item away (weapon_ak47,weapon_c4,item_thighpack,weapon_shield), switching to the next best weapon when it was in the hand; its spare ammunition stays. False if the player does not carry it. -
:drop(item: string) -> Entity?: Drops an item the player carries (weapon_ak47; empty: the one in the hand) as the drop command does, throughplayer_drop; returns what lies on the ground, nil if nothing was dropped. -
:items() -> {Item}: The items the player carries. -
:weapons() -> {Weapon}: The weapons the player carries (the knife, grenades and the C4 too). -
:info(key: string) -> string: A key of the player's userinfo ("": none): what its game set (cl_lw,_vgui_menus...) or the player withsetinfo. -
:set_info(key: string, value: string): Changes a key of the player's userinfo (""removes it) as if the player had: the next frame the server takes it in (namerenames the player, made unique;model,rate,cl_lw...) and tells the others. Keys are 1 to 63 characters without\or". -
:select(item: string): Takes the item into the hand (if the player has it). -
:reset_maxspeed(): Sets the top speed back to what the weapon in hand allows. -
:movement() -> Movement: The movement settings in effect for the player. -
:set_movement(settings: MoveSettings): Gives the player their own movement settings (the client predicts with them). Gravity and top speed aregravityandmaxspeed. -
:reset_movement(): Back to the server's movement settings (air_acceleratetoo). -
:move_state(name: string, plugin: string?) -> number: One of the numbers the plugin's movement script (or another plugin's) keeps for the player (move.state); 0 when it keeps none of that name. -
:set_move_state(name: string, value: number): Sets one of the numbers the plugin's movement script keeps for the player: the script reads it asm.state.<name>from the next command, on the server and in the player's prediction (a per-player setting of the script). -
:teleport(origin: vector, options: TeleportOptions?): Moves the player there (no interpolation), with zero velocity unless given. -
:mute_voice(speaker: Player, muted: boolean): Stops this player hearing a speaker's voice (or lets them again). -
:pose(options: PoseOptions): Places a bot made withcs.add_botfor this frame: where it is, where it looks, how it moves; the game animates it from that (walking, running, crouching, jumping). -
:record(name: string?) -> string?: Starts a demo the server records of the player, in its folder asserver_demos/<name>.csdem(letters, digits,_,-,.and/for folders; no part starting or ending with., none named as a device such asconornul; at most 200 characters). Without a name:<map>_<player>_<date>. It plays in the game's demo player from the player's eyes and keeps every command (cs.open_recording). Returns the name, nil when it could not start (a bot, already recording, a name being recorded). It starts with the next frame and ends when the player leaves, or withPlayer:stop_recording. -
:stop_recording(options: StopRecordingOptions?) -> string?: Ends the player's recording: kept (undersave_aswhen given) or deleted (discard). Returns the name it was kept under, nil when there was none, it was discarded, orsave_asis not a valid name (the recording goes on then). -
:play(recording: Recording, options: PlayOptions?): A bot made withcs.add_botplays a recording each frame: what the others were shown of the player at that moment, as it was (its place, view, buttons, animation and lean); in a recording made before 0.9.45, posed between its commands as the frame falls (asPlayer:pose). Ends withreplay_end, unless it loops. -
:stop_playing(): The bot stops playing; it stays where it is. -
:send_command(line: string): Runs a command line on the player's game (spk,lastinv...); only commands the game lets servers run.messagemode <command>opens the player's chat line for a prompt: what they type comes back as<command> "text". -
:hide(entity: Entity, hidden: boolean): Hides an entity (a player too) from this player only, or shows it again. Gone with the entity. -
:pass_through(entity: Entity, through: boolean): Lets this player move through an entity (the others still collide with it), or not; the player's client predicts it. Gone with the entity. -
:render(entity: Entity, options: ViewRenderOptions?): How this player only sees an entity (a glow, a colour, transparency); nil: as everyone does. -
:kick(reason: string?): Disconnects the player with a reason. -
:show_motd(body: string): Opens the message of the day window with this text: anhttp://orhttps://address opens that page, HTML is shown as a page, else plain text (at most 1536 bytes). The title bar shows the server's name; players who turned the message of the day off do not see it. -
:allowed(name: string) -> boolean: Whether the player's admins.toml entry (with its groups) allows a name (a command, or any permission a plugin names, likezones_edit) and denies it nowhere. -
:groups() -> {string}: The player's admin groups in admins.toml, inherited ones too (empty: none). -
:can_target(target: Player) -> boolean: Whether the player may act on target (kick, slay...): itself, or a player whose immunity is not above its own. -
:t(key: string, args: any) -> string: The plugin's text for key in the player's language (lang/<language>.toml; else the base language, the plugin's own, English, the key itself), with{1},{2}... from a list or{name}from a table ({{is a brace). -
:play_sound(sample: string, options: PlaySoundOptions?): Plays a sound only this player hears, not placed in the world (a file undersound/, or!NAMEa sentence). -
:fade(options: FadeOptions?): Tints the player's screen: fades to a colour and back, or holds it. -
:shake(options: ShakeOptions?): Shakes the player's view (an earthquake, a blast nearby). -
:play_music(file: string, loop: boolean?): Plays music for the player at their music volume, not placed in the world; it replaces the music playing. -
:stop_music(): Stops the musicPlayer:play_musicstarted (and the server'smp3music). -
:slay(keep_frags: boolean?) -> boolean: Kills the player as thekillcommand does (a suicide in the death notices). False when it is not alive in the game. -
:slap(damage: number?) -> boolean: Throws the player a little in a random direction, jolts its view and takesdamagehealth. False when it is not alive. -
:freeze(frozen: boolean): Stops the player from moving, turning aside its keys (it may still look around and shoot), or lets it move again; its client predicts it. Its next spawn lets it move again. -
:ban(minutes: number, options: BanOptions?): Puts the player on the server's ban list (banid; bans for good are written to bans.toml) and kicks it with the reason. Bots are only kicked. -
:data() -> any: A table this plugin keeps for the player until it leaves or the map changes (each plugin has its own): what a plugin remembers about a player meanwhile. To keep something longer,cs.storebyPlayer.id. -
:light_style(style: number, pattern: string): Changes a light style for this player only (0 is the normal light; patterns are lettersadark tozbright,mnormal). Back to the map's with an empty pattern. -
:set_fog(options: FogOptions?): Fog for this player only, from now (until the map changes or another call). Without options the map's own fog (env_fog), or none. -
:set_weather(kind: string?): Rain (rain), snow (snow) or none (none) for this player only, from now. Without a kind the map's own.
Entity
An entity of the map (the world, brushes, triggers, items, players...). Stays the same object while the entity exists; using it after it was removed is an error (check valid).
| member | type | |
|---|---|---|
valid | boolean | False once the entity was removed (every other member then raises an error). |
index | number | Its index (0: the world; players are 1 to the maximum). |
classname | string | Its class (func_button). |
liquid | boolean | Water, slime or lava: a func_water, a brush marked as a liquid, or one with liquid surfaces. |
targetname | string | Its name, what targets it. (settable) |
target | string | What it targets. (settable) |
model | string | Its model (*12 for a brush entity). |
player | Player? | The player it is, if it is one. |
weapon | Weapon? | It as a weapon, if it is one (carried or on the ground; not a weaponbox). |
grenade | Grenade? | It as a grenade, if it is one (or the planted bomb). |
hostage | Hostage? | It as a hostage, if it is one. |
origin | vector | Where it is (setting it relinks it in the world). (settable) |
angles | vector | Its angles. (settable) |
velocity | vector | Its velocity. (settable) |
avelocity | vector | Its turning velocity. (settable) |
base_velocity | vector | The velocity of what carries it. (settable) |
mins | vector | Its box's lower corner, relative to the origin (see :set_size). |
maxs | vector | Its box's upper corner, relative to the origin. |
absmin | vector | Its box's lower corner in the world. |
absmax | vector | Its box's upper corner in the world. |
movedir | vector | The direction it moves in (doors, buttons). (settable) |
spawnflags | number | The map's flags of it. (settable) |
flags | number | Its flags (cs.flag). (settable) |
effects | number | Its effects (cs.effect). (settable) |
solid | string | not, trigger, bbox, slidebox or bsp. (settable) |
movetype | string | none, walk, step, fly, toss, push, noclip, follow... (settable) |
health | number | Its health. (settable) |
takedamage | boolean | Whether it can be damaged. (settable) |
dmg | number | The damage it does (doors, hurts; negative heals). (settable) |
next_think | number | The game time of its next think (0: none). Setting it schedules one. (settable) |
speed | number | Its speed (doors, trains). (settable) |
gravity | number | Its gravity factor. (settable) |
friction | number | Its friction factor. (settable) |
render_mode | number | How it is drawn (0 normal, 1 colour, 2 texture, 3 glow, 4 solid, 5 additive). (settable) |
render_amount | number | Its opacity in the render mode, 0 to 255. (settable) |
render_color | vector | Its render colour, 0 to 255 per channel. (settable) |
render_fx | number | Its render effect. (settable) |
scale | number | How big its sprite is drawn (0: its own size). (settable) |
frame | number | Its sprite's frame, or its model's animation frame. (settable) |
framerate | number | How fast its animation plays (1: as made). (settable) |
owner | Entity? | Its owner (it does not collide with it). (settable) |
ground | Entity? | What it stands on. |
noise | string | Its sound key noise. (settable) |
noise1 | string | Its sound key noise1 (doors: moving). (settable) |
noise2 | string | Its sound key noise2 (doors: stopping). (settable) |
noise3 | string | Its sound key noise3. (settable) |
message | string | Its message key. (settable) |
iuser1 | number | A free whole number (players: the observer mode). (settable) |
iuser2 | number | A free whole number (players: the observed player). (settable) |
iuser3 | number | A free whole number. (settable) |
iuser4 | number | A free whole number. (settable) |
fuser1 | number | A free number. (settable) |
fuser2 | number | A free number (players: the jump stamina). (settable) |
fuser3 | number | A free number. (settable) |
fuser4 | number | A free number. (settable) |
global_name | string | Its name across the maps of a level change (unused in multiplayer). (settable) |
old_origin | vector | Where it was (some entities keep it: a train's last corner, a player's last safe place). (settable) |
client_base_velocity | vector | A conveyor's push, as the client is told. (settable) |
punch_angle | vector | A player's view kick (recoil, hits). (settable) |
view_angle | vector | A player's view angles. (settable) |
end_pos | vector | Where a client-moved projectile ends. (settable) |
start_pos | vector | Where a client-moved projectile starts. (settable) |
impact_time | number | When a client-moved projectile hits. (settable) |
start_time | number | When a client-moved projectile started. (settable) |
fix_angle | number | 1: the client takes angles as its view; 2: adds avelocity to it (reset each frame). (settable) |
ideal_pitch | number | The pitch it turns to. (settable) |
pitch_speed | number | How fast it turns its pitch. (settable) |
ideal_yaw | number | The yaw it turns to. (settable) |
yaw_speed | number | How fast it turns its yaw. (settable) |
model_index | number | Its model's precache index (0: none: not sent to clients). (settable) |
view_model | string | A player's first-person weapon model. (settable) |
weapon_model | string | A player's weapon model as others see it. (settable) |
size | vector | Its box's size. (settable) |
local_time | number | A pusher's own clock (doors, trains: what their thinks count on). (settable) |
skin | number | Its model's skin (brushes: their contents, as water or a ladder). (settable) |
body | number | Its model's body group. (settable) |
light_level | number | How lit the floor under it is (players). (settable) |
sequence | number | Its model's animation. (settable) |
gait_sequence | number | A player's legs' animation. (settable) |
anim_time | number | When its animation started. (settable) |
frags | number | A player's score. (settable) |
weapon_bits | number | A player's weapons, a bit per weapon id (bit 31: the suit). (settable) |
dead_flag | number | 0 alive, 1 dying, 2 dead, 3 respawnable, 4 discard body. (settable) |
view_offset | vector | Its eyes over the origin. (settable) |
buttons | number | A player's buttons this frame (cs.button). (settable) |
impulse | number | A player's impulse this frame (100: flashlight, 201: spray). (settable) |
chain | Entity? | The next entity of a list some functions build. |
damage_inflictor | Entity? | What hurt it last. (settable) |
enemy | Entity? | What it attacks (monsters, hostages: who scared them). (settable) |
aim_entity | Entity? | What it follows (movetype follow). (settable) |
color_map | number | Its colours (players of the old models: top and bottom). (settable) |
team | number | Its team number (some entities; players use Player.team). (settable) |
max_health | number | Its health at most. (settable) |
teleport_time | number | How long it keeps no control after a teleport (water jumps). (settable) |
armor_type | number | Its armor's kind. (settable) |
armor | number | Its armor. (settable) |
water_level | number | How deep in water: 0 out, 1 feet, 2 waist, 3 eyes. (settable) |
water_type | number | The contents it is in (-3 water, -4 slime, -5 lava). (settable) |
net_name | string | A player's name; other entities: a second name key (netname). (settable) |
damage_take | number | The health it lost this frame. (settable) |
damage_save | number | The damage its armor took this frame. (settable) |
damage_time | number | When it next hurts (hurts and the like). (settable) |
air_finished | number | When a player under water starts to drown. (settable) |
pain_finished | number | When a player next hurts from drowning or a liquid. (settable) |
radsuit_finished | number | When its protection runs out (unused). (settable) |
player_class | number | A free number (players: unused). (settable) |
max_speed | number | A player's top speed. (settable) |
fov | number | A player's field of view (0: the default). (settable) |
weapon_anim | number | A player's first-person weapon animation. (settable) |
push_msec | number | The milliseconds a pusher moved a player this frame. (settable) |
in_duck | number | A player is ducking (going down). (settable) |
step_sound_time | number | Milliseconds to a player's next step sound. (settable) |
swim_time | number | Milliseconds to a player's next swim sound. (settable) |
duck_time | number | Milliseconds left of a player's ducking. (settable) |
step_left | number | Which foot steps next. (settable) |
fall_velocity | number | How fast a player falls. (settable) |
game_state | number | A free number (players: unused). (settable) |
old_buttons | number | A player's buttons the frame before. (settable) |
group_info | number | The group bits traces filter on (cs.trace groups). (settable) |
vuser1 | vector | A free vector. (settable) |
vuser2 | vector | A free vector. (settable) |
vuser3 | vector | A free vector. (settable) |
vuser4 | vector | A free vector. (settable) |
euser1 | Entity? | A free entity. (settable) |
euser2 | Entity? | A free entity. (settable) |
euser3 | Entity? | A free entity. (settable) |
euser4 | Entity? | A free entity. (settable) |
-
:remove(): Removes it at the end of the frame (players cannot be removed). -
:set_size(mins: vector, maxs: vector): Sets its box (relative to the origin) and relinks it. -
:set_model(model: string): Sets its model (it must be precached; brush models*nalways are). -
:use(activator: Entity?, options: UseOptions?): Uses it, as a button press or a trigger would. -
:damage(amount: number, options: DamageOptions?) -> boolean: Hurts it as the game would (armor, hit effects, death), throughentity_damageand, for a player,player_damage. False when it took none (it cannot be hurt, or a handler blocked it). -
:spawn(): Spawns it (an entity made withspawn = false). -
:key_value(key: string, value: string): Gives it a map key, as the map would (before:spawn()). -
:get(field: string, index: number?) -> any: A variable or member by its name: an entity variable (health, or its classic namespev_health,EV_FL_health) or a member of the entity's game class (m_iTeam);index(from 1) for arrays. The names: docs/plugins_fields.md. Needs theraw_propertiespermission. -
:set(field: string, value: any, index: number?): Changes a variable or member by its name, without the checks of the properties (an origin is not relinked, a model is not looked up). Needs theraw_propertiespermission. -
:set_beam(from: any, target: any, options: BeamOptions?): Moves a beam made bycs.create_beam(and changes its look;lifedoes not apply).
Game
The game's rules a plugin may turn off. Each one comes back on when every plugin that turned it off has unloaded.
The one object is cs.game.
| member | type | |
|---|---|---|
rounds | boolean | Rounds end (by a win, the time, or a draw). (settable) |
buying | boolean | Players can buy (menus, commands, the buy zone icon). (settable) |
pickups | boolean | Players pick up weapons and items (Player:give always works). (settable) |
item_drops | boolean | Players drop items (by the drop command or when they die). (settable) |
death_notices | boolean | Kills are shown in the corner. (settable) |
corpses | boolean | The dead leave bodies. (settable) |
gibs | boolean | Bodies can burst into gibs. (settable) |
team_menu | boolean | Joining players get the team and appearance menus (off: they stay unassigned until a plugin uses Player:join_team; the team commands do nothing). (settable) |
pvp_damage | boolean | Players can hurt other players. (settable) |
team_balance | boolean | The game keeps the teams even: mp_limitteams (for players and bots) and mp_autoteambalance (off: a mode that decides the teams, at once rather than at the next round). (settable) |
description | string | The game's name in the server browser (empty: the game's own). (settable) |
round | number | The current round's number since the map (or the last restart) began, from 1. |
freeze_period | boolean | In the freeze time at a round's start. |
round_over | boolean | The round has ended (the time before the next). |
round_time_left | number | Seconds left in the round (0 when it has none or is over). |
bomb_planted | boolean | A bomb is planted. |
score_ct | number | The counter-terrorists' rounds won. (settable) |
score_t | number | The terrorists' rounds won. (settable) |
bomb | Bomb? | The planted bomb. |
semiclip | string | Which players pass through each other: off, team (teammates) or all. Their clients see them as not solid, so the prediction agrees; bullets still hit. Player:pass_through adds single pairs. (settable) |
bullets_pass_through | boolean | A player's bullets go through the players they pass through (semiclip, Player:pass_through) and may not hurt (a teammate without friendly fire), on to what is behind them. Off by default. (settable) |
bomb_carrier | Player? | Who carries the C4. |
mode | string | The mode running (cs.set_mode), or empty. |
version | string | The server's game version (0.9.5). |
compat | number | Its compatibility number: players join only servers with their own. |
update_version | string | The version of a downloaded update waiting for the restart (update_ready), or empty. |
update_required | string | How much that update matters: none, server or critical (empty without one). |
-
:end_round(reason: string, delay: number?) -> boolean: Ends the round now, as the game would for that reason (round_end's reasons:cts_win,terrorists_win,draw,target_bombed...); the next starts afterdelayseconds (absent or 0: the server's). False when the round is already over or the reason is unknown. -
:restart(seconds: number?): Restarts the game (scores, money, rounds) afterseconds(default 1), assv_restart. -
:get(field: string, index: number?) -> any: A member of the game rules by its name (m_iRoundTime; docs/plugins_fields.md);index(from 1) for arrays. Needs theraw_propertiespermission. -
:set(field: string, value: any, index: number?): Changes a member of the game rules (no checks: the game sees what you write). Needs theraw_propertiespermission.
Weapon
A weapon (or the knife, a grenade, the C4) as an item: in a player's hands or on the ground. Stays the same object while its entity exists.
| member | type | |
|---|---|---|
entity | Entity | Its entity. |
name | string | Its class (weapon_ak47). |
id | number | Its weapon number (weapon_ak47: 28). |
variant | string | The plugin weapon it is (weapon_ak47_gold, cs.register_weapon), or empty for the game's own. |
owner | Player? | Who carries it. |
slot | number | Its slot: 1 primary, 2 pistol, 3 knife, 4 grenades, 5 C4. |
clip | number | The rounds in its magazine (-1: none). (settable) |
max_clip | number | Its magazine's size (-1: none). |
ammo | number | Its owner's spare rounds of its ammunition (-1: none, or no owner). (settable) |
max_ammo | number | The spare rounds a player may carry (-1: none). |
next_attack | number | Seconds until it may attack again. (settable) |
next_secondary_attack | number | Seconds until its secondary attack. (settable) |
idle_time | number | Seconds until its next idle animation. (settable) |
reloading | boolean | It is reloading. |
shots_fired | number | Shots in the current burst of fire (what the recoil grows with). (settable) |
accuracy | number | Its accuracy factor (lower is better; what the spread grows with). (settable) |
silenced | boolean | The M4A1's or the USP's silencer is on. |
burst | boolean | The Glock's or the FAMAS's burst mode is on. |
max_speed | number | Its carrier's top speed with it in hand. (settable) |
Grenade
A grenade in flight (or after it went off: a smoke grenade smokes on), or the planted bomb. Stays the same object while its entity exists.
| member | type | |
|---|---|---|
entity | Entity | Its entity. |
kind | string | he, flash, smoke or bomb. |
thrower | Player? | Who threw (or planted) it. |
detonate_time | number | The game time it goes off (a grenade on the ground: smoke grenades wait for it to stop too). (settable) |
damage | number | Its blast's damage (HE: 100; the bomb: 500). (settable) |
detonated | boolean | It has gone off (a smoke grenade still smoking). |
variant | string | The plugin grenade it was thrown from (cs.register_grenade), or empty for the game's own. |
-
:detonate(): Makes it go off now (a smoke grenade, once it lies still).
Bomb
The planted bomb (cs.game.bomb).
| member | type | |
|---|---|---|
entity | Entity | Its entity. |
grenade | Grenade | It as a grenade (its blast). |
planter | Player? | Who planted it. |
site | Entity? | The bomb site it was planted on. |
explode_time | number | The game time it explodes. (settable) |
defuser | Player? | Who is defusing it. |
defuse_time | number | The game time the defuse in progress ends (0: none). (settable) |
Hostage
A hostage (cs.hostages()). Stays the same object while its entity exists.
| member | type | |
|---|---|---|
entity | Entity | Its entity. |
leader | Player? | Whom it follows; set it to make it follow a player, nil to stop it. (settable) |
alive | boolean | It is alive and not rescued. |
rescued | boolean | It has been rescued. |
start | vector | Where it started the round. |
WebSocket
A WebSocket client (cs.websocket). Its handlers run on the tick: open (connected), message (the text or bytes, and whether it was a binary message) and close (the code, the reason and, when it broke, an error). Messages sent before it opened go once it does.
| member | type | |
|---|---|---|
url | string | Its URL. |
open | boolean | Connected (and not closed). |
-
:on(event: string, handler: (...any) -> ...any): Sets the handler ofopen,messageorclose(replacing the last one). -
:send(data: any, binary: boolean?) -> boolean: Sends a message: text, or binary forbinaryor a buffer. False when it is closed or 16 MB wait to be sent. -
:close(code: number?, reason: string?): Closes it (code 1000, or 3000 to 4999); its close handler does not run.
Socket
A raw TCP or UDP socket (cs.tcp, cs.udp; the raw_sockets permission). Handlers: open, data (the bytes: what came on TCP, one datagram on UDP) and close (nil, or the error).
| member | type | |
|---|---|---|
protocol | string | tcp or udp. |
host | string | The host it talks to. |
port | number | Its port. |
open | boolean | Connected (and not closed). |
-
:on(event: string, handler: (...any) -> ...any): Sets the handler ofopen,dataorclose(replacing the last one). -
:send(data: any) -> boolean: Sends bytes (a string or a buffer; on UDP one datagram, at most 65507 bytes). False when it is closed or 16 MB wait to be sent. -
:close(): Closes it; its close handler does not run.
Database
An SQLite database in the plugin's data folder (cs.database). Its queries run on an I/O thread, one at a time, in the order sent; the tick never waits for them (but for query_now). Parameters: ? with a list ({ 1, "a" }) or :name with a table ({ name = 1 }); nil, booleans (as 0 and 1), numbers, strings and buffers (as blobs). A result is a table: ok, rows (one table per row, by column name; blobs as strings), columns (the column names in order), changes, last_id and, when it failed, error.
| member | type | |
|---|---|---|
name | string | Its name (the file is <name>.db). |
-
:query(sql: string, params: any, callback: ((...any) -> ...any)?): Runs SQL on the I/O thread; the callback gets the result on a later frame. Without parameters the text may hold several statements (the last one's rows come back). Without a callback a failure is printed. -
:query_now(sql: string, params: any) -> any: Runs SQL and waits for its result (after the queries sent before it): forplugin_startandmap_start, never every frame. -
:close(): Closes it after its queries (it closes with its plugin too).
Store
A key-value store in the plugin's data folder (cs.store): JSON values by string key, with an optional expiry. Reads answer from memory at once; writes reach the file on an I/O thread.
| member | type | |
|---|---|---|
name | string | Its name (the file is <name>.store). |
-
:get(key: string) -> any: The key's value; nil when there is none (or it expired). -
:set(key: string, value: any, options: StoreOptions?): Sets the key's value (whatjson_encodetakes, at most 1 MB as JSON); nil deletes it. -
:delete(key: string) -> boolean: Deletes the key; whether it had a value. -
:has(key: string) -> boolean: Whether the key has a value. -
:touch(key: string, ttl: number): Sets the key's expiry tottlseconds from now (0: never). -
:expires(key: string) -> number: Seconds until the key expires (0: never, or no such key). -
:keys(prefix: string?) -> {string}: The keys with a value (only those that start withprefix), sorted. -
:clear(): Deletes every key.
Recording
The commands of a demo the server recorded (cs.open_recording), in memory: for a bot to play (Player:play) or to study how the player moved and aimed.
| member | type | |
|---|---|---|
name | string | The demo's name. |
map | string | The map it was recorded on (where it started). |
count | number | Its commands. |
length | number | Seconds from the first command to the last. |
-
:command(index: number) -> RecordedCommand: Command numberindex(1 tocount; an error past them). -
:at(time: number) -> number: The number of the last command at or beforetimeseconds (1 before the first). -
:close(): Frees the commands (a bot playing it keeps them until it stops).
Team
A team of players (cs.team("t"), cs.team("ct")).
| member | type | |
|---|---|---|
name | string | t or ct. |
score | number | Its rounds won (the scoreboard follows). (settable) |
count | number | Its players. |
alive | number | Its players alive. |
title | string | Its name on the players' scoreboard and team menu (empty: the game's). (settable) |
color | string | Its colour there, #rrggbb (empty: the game's). (settable) |
limit | number | Players it takes at most from the team menu and auto-join (0: no limit; Player:join_team is not limited). (settable) |
joinable | boolean | Players can choose it (false: only Player:join_team puts them there). (settable) |
-
:players() -> {Player}: Its players.
Cvar
A server setting.
| member | type | |
|---|---|---|
name | string | Its name. |
value | string | Its value as text; setting it changes the setting. A plugin sets its own settings; the server's and other plugins' ones need the server_console permission, and plugin_dev is set only from the server console. (settable) |
protected | boolean | Whether it is a protected setting (a password: sv_password, rcon_password), whose value the server never shows players. |
-
:number() -> number: Its value as a number (0 if it is not one). -
:int() -> number: Its value as a whole number. -
:bool() -> boolean: Whether its value is a number other than 0.
Timer
A timer from cs.after or cs.every.
| member | type | |
|---|---|---|
active | boolean | Whether it will still run. |
-
:cancel(): Stops it (nothing if it already ended).
Hook
A handler joined to an event with cs.on.
-
:remove(): Takes the handler off the event.
Constants
cs.button
The buttons of a player's command (Player.buttons, player_command's buttons), as bits.
attack, jump, duck, forward, back, use, cancel, left, right, move_left, move_right, attack2, run, reload, alt1, score
cs.flag
An entity's flags, as bits.
fly, swim, conveyor, client, in_water, monster, god_mode, no_target, on_ground, partial_ground, water_jump, frozen, fake_client, ducking, float, on_train, world_brush, spectator, kill_me
cs.damage
Kinds of damage (player_damage's damage_type), as bits.
generic, crush, bullet, slash, burn, freeze, fall, blast, club, shock, sonic, energy_beam, never_gib, always_gib, drown, grenade
cs.hide_hud
Parts of the HUD a player's hide_hud hides, as bits.
weapons, flashlight, all, health, timer, money, crosshair
cs.effect
An entity's effects, as bits.
bright_field, muzzle_flash, bright_light, dim_light, no_interp, light, no_draw
Records
Plain tables the API returns.
BuyItem
An item of the buy menu (cs.buy_items).
| field | type | |
|---|---|---|
id | string | What a player types to buy it (ak47, vesthelm, primammo, a plugin's id). |
name | string | Its name in the menu. |
group | string | pistols, shotguns, smgs, rifles, machineguns, equipment, extra or ammo. |
price | number | Its price now (-1: the ammo's, which depends on the weapon). |
team | string | Who may buy it: any, terrorist or ct. |
enabled | boolean | Whether it can be bought. |
plugin | string | The plugin whose item it is (empty for the game's). |
PluginInfo
A loaded plugin (cs.plugins).
| field | type | |
|---|---|---|
name | string | Its folder's name (what cs.import and depends take). |
version | string | Its plugin.toml version. |
author | string | Its plugin.toml author. |
description | string | Its plugin.toml description. |
paused | boolean | It is paused (too many errors). |
TraceResult
What a trace found.
| field | type | |
|---|---|---|
fraction | number | How far it went, 0 to 1 (1: nothing in the way). |
end_pos | vector | Where it stopped. |
normal | vector | The normal of the surface hit. |
entity | Entity? | What it hit (the world is an entity too). |
start_solid | boolean | It started inside something solid. |
all_solid | boolean | It never left something solid. |
in_open | boolean | It went through open space. |
in_water | boolean | It went through water. |
hit_group | number | The body part hit (0 when no player was hit). |
Movement
A player's movement settings in effect (Player:movement()): their own where set, else the server's.
| field | type | |
|---|---|---|
accelerate | number | Ground acceleration (sv_accelerate). |
air_accelerate | number | Air acceleration (sv_airaccelerate; the same as Player.air_accelerate). |
friction | number | Ground friction (sv_friction). |
stop_speed | number | Below this speed friction stops the player as if at it (sv_stopspeed). |
jump_height | number | How high a jump goes, in units (mp_jump_height, 45). |
bhop_cap | number | Jumping faster than this many times the top speed drops the speed (1.2); 0: no cap (sv_enablebunnyhopping). |
auto_bhop | boolean | Holding jump jumps again on landing (sv_autobunnyhopping). |
stamina | boolean | Landing and jumping slow the player for a while (the original behaviour). |
max_velocity | number | The movement's speed clamp on each axis (sv_maxvelocity). |
ladder_speed | number | Climbing speed on ladders (200). |
duck_speed | number | The speed factor ducked (0.333), on ladders too. |
swim_speed | number | The speed factor swimming (0.8). |
can_jump | boolean | The player may jump. |
can_duck | boolean | The player may duck. |
ramp_fix | boolean | A slide ramp that stops a fast slide dead in the middle (a seam of the map's ramp) lets the player slide on; walls, floors and pixel surf stay as they are (off by default). |
FieldInfo
A variable or member raw access reaches (docs/plugins_fields.md).
| field | type | |
|---|---|---|
name | string | Its name (health, m_iTeam). |
class | string | Whose: entity (every entity's variables), a game class (CBasePlayer), or rules. |
type | string | integer, number, boolean, vector, string or Entity. |
count | number | How many (arrays), else 1. |
writable | boolean | Whether :set may change it. |
classic | {string} | Its classic names (pev_health, EV_FL_health). |
Item
An item a player carries.
| field | type | |
|---|---|---|
name | string | Its class name (weapon_usp). |
clip | number | The rounds in its magazine (-1: none). |
ammo | number | The player's spare rounds of its ammunition (-1: none). |
Ban
A ban in force on the server's list (cs.bans).
| field | type | |
|---|---|---|
id | string | The player ID (CSID:...) or the computer (HWID:...). |
minutes | number | Minutes left; 0 for good. |
RecordedCommand
One command a player ran, as a demo the server recorded keeps it (Recording:command).
| field | type | |
|---|---|---|
time | number | When, in seconds from the first command (0 for the first): on the player's own clock, its msec after the command before, never later than arrived nor more than 0.1 s before it. A bot plays the commands on it. |
arrived | number | When the server ran it, on the same clock. Commands the player's connection held back run late and together: arrived jumps over a gap, then holds for the ones that came with it, while time goes on evenly. |
view_angles | vector | Where the player looked (pitch, yaw, roll). |
forward_move | number | The forward speed asked. |
side_move | number | The sideways speed asked. |
up_move | number | The upward speed asked (swimming, ladders). |
buttons | number | The buttons held (cs.button). |
msec | number | The command's length in milliseconds. |
impulse | number | Its impulse (0: none). |
weapon_select | number | The weapon it switched to (0: none). |
origin | vector | Where the player was after it. |
velocity | vector | The velocity after it. |
on_ground | boolean | On the ground after it. |
ducking | boolean | Ducked after it. |
Option tables
MoveSettings
A player's own movement settings (Player:set_movement): each given one replaces the server's for that player alone; their client predicts with them, so the movement stays exact. The others stay as they were.
| field | type | |
|---|---|---|
accelerate | number? | Ground acceleration (sv_accelerate). |
air_accelerate | number? | Air acceleration (sv_airaccelerate; the same as Player.air_accelerate). |
friction | number? | Ground friction (sv_friction). |
stop_speed | number? | Below this speed friction stops the player as if at it (sv_stopspeed). |
jump_height | number? | How high a jump goes, in units (mp_jump_height, 45). |
bhop_cap | number? | Jumping faster than this many times the top speed drops the speed (1.2); 0: no cap (sv_enablebunnyhopping). |
auto_bhop | boolean? | Holding jump jumps again on landing (sv_autobunnyhopping). |
stamina | boolean? | Landing and jumping slow the player for a while (the original behaviour). |
max_velocity | number? | The movement's speed clamp on each axis (sv_maxvelocity). |
ladder_speed | number? | Climbing speed on ladders (200). |
duck_speed | number? | The speed factor ducked (0.333), on ladders too. |
swim_speed | number? | The speed factor swimming (0.8). |
can_jump | boolean? | The player may jump. |
can_duck | boolean? | The player may duck. |
ramp_fix | boolean? | A slide ramp that stops a fast slide dead in the middle (a seam of the map's ramp) lets the player slide on; walls, floors and pixel surf stay as they are (off by default). |
HookOptions
How a handler joins an event.
| field | type | |
|---|---|---|
before | boolean? | Run before the game handles the event (may change or block it). |
priority | number? | Higher runs first (default 0); equal priorities keep load order. |
class | string? | Only for this class of entity (events with an entity to filter on). |
entity | Entity? | Only for this entity (events with an entity to filter on). |
message | string? | Only for the game messages of this name (client_message). |
CommandOptions
How a command is reached.
| field | type | |
|---|---|---|
help | string? | One line for help and the command list. |
admin | boolean? | Only admins whose admins.toml entry allows the command's name. |
chat | boolean? | Also as /name and !name in the chat (default true). |
show | boolean? | Keep the chat line visible when typed in the chat (default false). |
CvarOptions
A plugin's setting.
| field | type | |
|---|---|---|
help | string? | What it does. |
min | number? | Values below are raised to it. |
max | number? | Values above are lowered to it. |
public | boolean? | Shown to players in the server's rules (default false). |
TimerOptions
Where a timer belongs.
| field | type | |
|---|---|---|
player | Player? | The timer ends when this player leaves. |
TraceOptions
What a trace goes through.
| field | type | |
|---|---|---|
ignore | Entity? | An entity the trace goes through (usually the one tracing). |
monsters | boolean? | Hit players and monsters too (default true). |
glass | boolean? | Hit glass-like transparent brushes (default true). |
FindOptions
Which entities to find; every field given must match.
| field | type | |
|---|---|---|
class | string? | The class name. |
targetname | string? | The targetname. |
target | string? | The target. |
model | string? | The model (*12 for a brush entity). |
near | vector? | Within radius of this point. |
radius | number? | With near (default 64). |
CreateOptions
A new entity.
| field | type | |
|---|---|---|
origin | vector? | Where it is. |
angles | vector? | Its angles. |
spawn | boolean? | Spawn it at once (default true); else call :spawn() later. |
EntityClass
An entity class a plugin defines (cs.register_entity). Each callback gets the entity first.
| field | type | |
|---|---|---|
spawn | ((...any) -> ...any)? | (entity, keys): it spawned; keys holds the map's keys it was given ({ amount = "20" }), or the ones :key_value gave it. |
think | ((...any) -> ...any)? | (entity): its next think came (set entity.next_think). |
touch | ((...any) -> ...any)? | (entity, other): something touched it. |
use | ((...any) -> ...any)? | (entity, activator, caller): it was used (a trigger, or a player's use key when usable). |
blocked | ((...any) -> ...any)? | (entity, other): it moves and something blocks it. |
model | string? | Its model (models/...mdl, sprites/...spr), precached at each map. |
precache | {string}? | More files to precache at each map (models, sprites, sound/...wav). |
mins | vector? | Its box's lower corner (with maxs). |
maxs | vector? | Its box's upper corner. |
solid | string? | not (default), trigger, bbox, slidebox or bsp. |
movetype | string? | none (default), toss, bounce, fly, push... (as Entity.movetype). |
usable | boolean? | Players can use it with their use key. |
WeaponDef
A variant of one of the game's guns (cs.register_weapon): what is not given stays the gun's.
| field | type | |
|---|---|---|
base | string | The gun it is made from (ak47 or weapon_ak47): its class, slot, ammo, animations and behaviour. |
name | string? | Its name (the buy menu's). |
damage | number? | A bullet's damage (the alternate mode's changes in proportion). |
cycle | number? | Seconds between shots (the alternate and zoomed modes' change in proportion). |
clip | number? | Rounds in a clip (1 to 250). |
spread | number? | Times the gun's spread (0.5: twice as accurate). |
recoil | number? | Times the gun's recoil. |
max_speed | number? | How fast its carrier runs (the zoomed speed changes in proportion). |
penetration | number? | How many surfaces a bullet goes through. |
range_mod | number? | The damage kept per 500 units (0.98: 2% lost). |
view_model | string? | Its first-person model (models/v_...mdl). |
player_model | string? | The model on its carrier (models/p_...mdl). |
world_model | string? | Its model on the ground (models/w_...mdl). |
fire_sound | string? | Its shot's sound (weapons/....wav), played by the clients instead of the gun's. |
price | number? | Adds it to the buy menu, beside its base, at this price (bought by its name without weapon_). |
ModeDef
A game mode (cs.register_mode): what it changes while it runs.
| field | type | |
|---|---|---|
title | string? | Its name in the server list's Mode column (default: its name). |
off | {string}? | The cs.game rules it turns off (rounds, buying, team_menu...); they come back when it stops. |
respawn | number? | Seconds after a death until the player spawns again (0: at once); absent: the game's rounds decide. |
objectives | boolean? | False: the maps' bomb sites, hostages and rescue, VIP and escape zones are taken out (and the bomb), at once and at each map while it runs. |
start | ((...any) -> ...any)? | (): it starts (cs.set_mode). |
stop | ((...any) -> ...any)? | (): it stops (another mode starts, or cs.set_mode()); the teams' titles, colours and limits are reset after. |
GrenadeDef
A variant of one of the game's grenades (cs.register_grenade): what is not given stays the grenade's.
| field | type | |
|---|---|---|
base | string | The grenade it is made from: hegrenade, flashbang or smokegrenade (or with weapon_): its slot, ammo, animations and blast. |
name | string? | Its name (the buy menu's). |
fuse | number? | Seconds from the throw until it goes off (the game's: 1.5; a smoke grenade then waits to lie still). |
damage | number? | An HE blast's damage (the game's: 100). |
radius | number? | An HE blast's radius (the game's: 3.5 times the damage). |
gravity | number? | Times the world's gravity in flight (the game's: 0.55 HE, 0.5 the others). |
friction | number? | Its bounce friction (the game's: 0.7 HE, 0.8 the others). |
view_model | string? | Its first-person model (models/v_...mdl). |
player_model | string? | The model on its carrier (models/p_...mdl). |
world_model | string? | Its model on the ground and in flight (models/w_...mdl). |
price | number? | Adds it to the buy menu, beside its base, at this price (bought by its name without weapon_). |
detonate | ((...any) -> ...any)? | (grenade, thrower): it goes off (after grenade_detonate handlers); return true when the plugin made the blast, and the game's is skipped (the grenade is removed). |
BuyChange
Changes to an item of the buy menu (cs.set_buy_item).
| field | type | |
|---|---|---|
price | number? | Its price (-1: its own again). For primammo/secammo, every clip's. |
enabled | boolean? | False: nobody can buy it (it leaves the menu). |
team | string? | Who may buy it: any, terrorist or ct. |
name | string? | Its name in the menu. |
reset | boolean? | Back to the game's price and enabled, before the other fields apply. |
BuyItemDef
A plugin's item for the buy menu (cs.register_buy_item).
| field | type | |
|---|---|---|
name | string | Its name in the menu. |
price | number | Its price. |
group | string? | Its menu: pistols, shotguns, smgs, rifles, machineguns, equipment or extra (the default, a menu of its own). |
team | string? | Who may buy it: any (default), terrorist or ct. |
icon | string? | Its picture in the menu: m:<view model> (m:v_ak47) or empty. |
buy | ((...any) -> ...any)? | (player) -> boolean?: give it; returning false means not bought (nothing is paid). |
DamageOptions
Where damage comes from.
| field | type | |
|---|---|---|
attacker | Entity? | Who is to blame (default the world). |
inflictor | Entity? | What hurts (default the attacker). |
type | number? | The kinds of damage (cs.damage; default generic). |
UseOptions
How an entity is used.
| field | type | |
|---|---|---|
caller | Entity? | What passes the use on (default the activator). |
type | string? | toggle (default), on, off or set. |
value | number? | The value of set. |
SoundOptions
How a sound plays.
| field | type | |
|---|---|---|
channel | string? | auto (default), weapon, voice, item, body, stream or static. |
volume | number? | 0 to 1 (default 1). |
attenuation | number? | How fast it fades with distance: 0 everywhere, 0.8 normal (default), 2 close only. |
pitch | number? | 100 normal (default). |
stop | boolean? | Stop this sound on that channel instead. |
TeleportOptions
How a player is moved.
| field | type | |
|---|---|---|
angles | vector? | Where the player looks afterwards (default unchanged). |
velocity | vector? | The velocity afterwards (default zero). |
GiveOptions
An item given to a player.
| field | type | |
|---|---|---|
clip | number? | The rounds in its magazine (default full). |
ammo | number? | The player's spare rounds of its ammunition (default unchanged). |
LightOptions
A dynamic light.
| field | type | |
|---|---|---|
radius | number? | In units (default 200). |
color | string? | #rrggbb (default white). |
life | number? | Seconds (default 0.1). |
decay | number? | Radius lost per second (default 0). |
MarkOptions
How a mark looks.
| field | type | |
|---|---|---|
color | string? | #rrggbb (default white). |
alpha | number? | 0 (clear) to 1 (default). |
size | number? | A line's width, a text's height, in units (default 1 and 8), or in screen pixels with pixels. |
pixels | boolean? | size is in screen pixels (of a 1080-line screen), not units: a line as thin (a text as big) near or far. |
on_top | boolean? | Seen through the world (default false: walls hide it). |
ease | boolean? | A change glides there (default true). |
life | number? | Seconds, then it goes (default: until erased). |
facing | vector? | A text: the way its front looks (default: at the viewer). |
up | vector? | A text: the way its letters stand (default: up). |
EntityLightOptions
A light that stays on an entity.
| field | type | |
|---|---|---|
radius | number? | In units (default 150). |
color | string? | #rrggbb (default white). |
at | string? | aim (default: where the entity aims, a player where it looks) or body (at the entity). |
ViewRenderOptions
How one player sees an entity.
| field | type | |
|---|---|---|
mode | string? | normal, color, texture, glow, solid or additive. |
amount | number? | 0 (invisible) to 255 (opaque). |
color | string? | #rrggbb. |
fx | number? | A render effect (19: glow shell). |
FadeOptions
A screen tint.
| field | type | |
|---|---|---|
color | string? | #rrggbb (default black). |
alpha | number? | 0 to 255 (default 255). |
duration | number? | Seconds the fade takes (default 0.5). |
hold | number? | Seconds at full colour (default 0). |
direction | string? | in (from the colour to clear, default), out (from clear to the colour) or stay (holds it until another fade). |
BeamOptions
A beam (a line drawn between two points or entities).
| field | type | |
|---|---|---|
color | string? | #rrggbb (default white). |
alpha | number? | 0 to 255 (default 255). |
width | number? | In tenths of a unit (default 10). |
life | number? | Seconds (default 1; at most 25). |
noise | number? | How much it wavers (0 to 255, default 0). |
speed | number? | How fast its texture scrolls (default 0). |
sprite | string? | Its sprite (sprites/...spr, precached; default the game's beam). |
EffectOptions
How a world effect looks (each effect reads the fields it has a use for).
| field | type | |
|---|---|---|
sprite | string? | Its sprite (sprites/...spr, precached; default the game's own for that effect). |
scale | number? | Its size, 1 the sprite's own (default: explosion 3, smoke 2.5, sprite 1, blood 1). |
framerate | number? | Frames per second (default: explosion 15, smoke 10). |
alpha | number? | A sprite's brightness, 0 to 255 (default 200). |
sound | boolean? | An explosion's sound (default true). |
light | boolean? | An explosion's light (default true). |
palette | number? | A colour of the game's palette: blood (default 247 red; 195 yellow) and particles (default 247). |
radius | number? | Particles: how far they go (default 50). |
duration | number? | Particles: seconds they last (default 1). |
ShakeOptions
A view shake.
| field | type | |
|---|---|---|
amplitude | number? | How far the view moves, 0 to 16 units (default 4). |
duration | number? | Seconds (default 1). |
frequency | number? | How fast it shakes, 0.1 to 255 (default 10). |
BanOptions
A ban.
| field | type | |
|---|---|---|
reason | string? | What the player is told when kicked (default "Banned"). |
computer | boolean? | Bans the player's computer (its hwid: every account on it) instead of its ID; the ID when it has no hwid. |
GameBotOptions
A bot of the game's (one that plays by itself).
| field | type | |
|---|---|---|
team | string? | t or ct (default: as bot_join_team says). |
difficulty | string? | easy, normal, hard or expert (default: bot_difficulty's). |
profile | string? | A bot profile's name (the bots' BotProfile.db): that bot. |
HttpOptions
An HTTP request.
| field | type | |
|---|---|---|
method | string? | GET (default; POST with a body), POST, PUT, PATCH, DELETE or HEAD. |
body | string? | What to send (sent as application/json unless a Content-Type header says otherwise). |
headers | any | A table of header names and values. |
timeout | number? | Seconds before it fails (default 10). |
PlaySoundOptions
A sound for one player.
| field | type | |
|---|---|---|
pitch | number? | 100 is normal (default). |
BotOptions
A bot of cs.add_bot.
| field | type | |
|---|---|---|
team | string? | ct (default) or t. |
model | number? | Its look, 1 to 4 (default 1). |
PoseOptions
A bot's place for one frame.
| field | type | |
|---|---|---|
origin | vector? | Where it is. |
angles | vector? | Where it looks (pitch, yaw, roll). |
velocity | vector? | How it moves (the animation follows it; nothing moves it). |
buttons | number? | The buttons it holds (cs.button): spectators' key readouts; the jump key going down on the ground and the duck key animate it as a player's. |
ducking | boolean? | Crouched. |
on_ground | boolean? | Standing on something (else in the air: the jump animation). |
teleport | boolean? | A jump to the new place, not a move (clients do not slide it there). |
StopRecordingOptions
How a demo the server records ends (Player:stop_recording).
| field | type | |
|---|---|---|
discard | boolean? | Deleted, not kept (a run that was not a record). |
save_as | string? | Kept under this name instead (replacing a demo of that name): the same rules as a name for Player:record. |
PlayOptions
How a bot plays a recording (Player:play).
| field | type | |
|---|---|---|
from | number? | Where it starts, in seconds of the recording (default 0). |
to | number? | Where it ends, in seconds of the recording (default its end). |
speed | number? | How fast it plays (default 1; 0.1 to 10). |
loop | boolean? | From the start again at the end, until Player:stop_playing (default: it stops, replay_end). |
HudMessageOptions
A HUD message as the game's own (cs.hud_message, a map's game_text): four channels, a new one on a channel showing on every text of that channel.
| field | type | |
|---|---|---|
x | number? | Its place across, a part of the screen: 0 left to 1 right; -1 centred; below 0 from the right edge (-0.1: a tenth from it). |
y | number? | Its place down, the same way: 0 top to 1 bottom; -1 centred; below 0 from the bottom. |
color | string? | #rrggbb (default #c86400). |
color2 | string? | The second colour, of flicker and typewriter (default #ffffff). |
effect | string? | fade (in and out, default), flicker (the second colour flashes over it) or typewriter (typed out a letter each fade_in, each turning from the second colour in fx_time). |
fx_time | number? | Seconds a typed letter takes to turn from the second colour (default 6). |
fade_in | number? | Seconds it fades in; typed out: seconds a letter (default 0.1). |
hold | number? | Seconds it stays (default 12). |
fade_out | number? | Seconds it fades out (default 0.2). |
channel | number? | 1 to 4 (default: the next of the four, in turn). |
DhudMessageOptions
A director's HUD message (cs.dhud_message, a "DHUD"): larger letters, eight of its own apart from the four channels.
| field | type | |
|---|---|---|
x | number? | Its place across, a part of the screen: 0 left to 1 right; -1 centred; below 0 from the right edge (-0.1: a tenth from it). |
y | number? | Its place down, the same way: 0 top to 1 bottom; -1 centred; below 0 from the bottom. |
color | string? | #rrggbb (default #00a000). |
effect | string? | fade (in and out, default), flicker (the second colour flashes over it) or typewriter (typed out a letter each fade_in, each turning from the second colour in fx_time). |
fx_time | number? | Seconds a typed letter takes to turn from the second colour (default 6). |
fade_in | number? | Seconds it fades in; typed out: seconds a letter (default 0.1). |
hold | number? | Seconds it stays (default 3). |
fade_out | number? | Seconds it fades out (default 1.5). |
HudTextOptions
A HUD text of the game's own (cs.hud_text): everything a HUD message and a director's do, any size, as many as wanted, by id.
| field | type | |
|---|---|---|
id | string? | Its id (1 to 32 characters): a text with the same id takes its place, cs.hud_text_remove takes it off. Default: a new one. |
x | number? | Its place across, a part of the screen: 0 left to 1 right; -1 centred; below 0 from the right edge (-0.1: a tenth from it). |
y | number? | Its place down, the same way: 0 top to 1 bottom; -1 centred; below 0 from the bottom. |
color | string? | #rrggbb (default #ffffff). |
color2 | string? | The second colour, of flicker and typewriter (default #ffffff). |
effect | string? | fade (in and out, default), flicker (the second colour flashes over it) or typewriter (typed out a letter each fade_in, each turning from the second colour in fx_time). |
fx_time | number? | Seconds a typed letter takes to turn from the second colour (default 0.25). |
fade_in | number? | Seconds it fades in; typed out: seconds a letter (default 0.1). |
hold | number? | Seconds it stays; -1: until taken off (cs.hud_text_remove, the same id) or the map changes (default 5). |
fade_out | number? | Seconds it fades out (default 0.5). |
size | number? | Its letters' size, in points at 1080 lines (8 to 120; default 22, a HUD message's; a director's is 44.5). |
align | string? | left (x is each line's left edge), center (its middle) or right (its right edge), with x from 0 to 1. Default: as a HUD message (x -1 centres each line, below 0 counts from the right edge). |
font | string? | normal (default) or mono (fixed width: columns line up). |
FogOptions
Fog for one player (Player:set_fog).
| field | type | |
|---|---|---|
color | string? | #rrggbb (default grey #808080). |
density | number? | How thick: 0 is none, 0.001 light, 0.005 thick (0 to 0.1; default 0.002). |
MenuOptions
A numbered menu.
| field | type | |
|---|---|---|
exit | string? | The text of key 0 (default Exit; "" for none). |
timeout | number? | Seconds it stays open (default until a key). |
text | string? | The whole menu as written, its own key labels included (title, items and exit are then not used; at most 1000 bytes). |
keys | number? | With text: the keys that answer, a bit per key (bit 0 is key 1, bit 9 key 0; default all). |
NoticeOptions
How a notice looks and behaves.
| field | type | |
|---|---|---|
title | string? | A heading above the text. |
kind | string? | info (default), success, warning, error or plain: the colours, icon and sound. hud: bare outlined text, no box, sound or animation (a HUD readout updated often: a timer, keys, a list). |
icon | string? | An icon name (info, check, warning, error, timer, flag, star, bolt, pin) or none. |
color | string? | The accent colour, #rrggbb. |
background | string? | The background, #rrggbb or #rrggbbaa. |
text_color | string? | The text colour, #rrggbb. |
position | string? | top (default), top_left, top_right, left, center, right, bottom_left, bottom or bottom_right. |
x | number? | With y, instead of position, as cs.hud_text takes it: its place across, a part of the screen: 0 left to 1 right; -1 centred; below 0 from the right edge (-0.1: a tenth from it). |
y | number? | Its top, the same way: 0 top to 1 bottom; -1 centred; below 0 from the bottom. Notices at the same place stack down from it. |
duration | number? | Seconds on screen (default 4; 0: until closed). |
sound | string? | default (the kind's), none, or info, success, warning, error. |
id | string? | A notice with the same id is replaced in place (no new animation). |
progress | number? | A bar under the text, 0 to 1. |
size | string? | small, normal (default) or large. |
align | string? | With x/y, as cs.hud_text's: left (x is the left edge), center (its middle) or right (its right edge), with x from 0 to 1. A hud notice's lines line up the same way (default: centred). |
font | string? | normal (default) or mono (fixed width: columns line up). |
JsonOptions
How JSON is written.
| field | type | |
|---|---|---|
pretty | boolean? | Indented, one value per line (default: compact). |
WebSocketOptions
How a WebSocket connects.
| field | type | |
|---|---|---|
headers | any | A table of header names and values for the upgrade request. |
timeout | number? | Seconds to connect before it fails (default 10). |
SocketOptions
How a TCP socket connects.
| field | type | |
|---|---|---|
tls | boolean? | TLS over it, the host's certificate checked (default: plain). |
timeout | number? | Seconds to connect before it fails (default 10). |
SendMessageOptions
Where a message goes.
| field | type | |
|---|---|---|
dest | string? | one, one_unreliable, all (default without player), broadcast (unreliable), pvs, pas, pvs_reliable or pas_reliable (one with player). |
player | Player? | The receiver (one, one_unreliable). |
origin | vector? | Where it is heard (pvs, pas). |
StoreOptions
How a store keeps a value.
| field | type | |
|---|---|---|
ttl | number? | Seconds until it expires (default: never). |
AsyncFileOptions
How a file is read or written on an I/O thread.
| field | type | |
|---|---|---|
binary | boolean? | read_file_async: the bytes as a buffer (default: a string). |
append | boolean? | write_file_async: added at the file's end (default: the file replaced). |
Events
Every event object also has blocked and :stop() (no later handler runs); blockable events have :block() in before handlers.
plugin_start
Every plugin has loaded (at the server's start), or this one has (when loaded later).
plugin_end
The plugin is about to unload (unload, reload, server shutdown).
map_start
A map has started (its entities exist).
| field | type | |
|---|---|---|
map | string | The map's name. |
map_end
The map is ending.
| field | type | |
|---|---|---|
map | string | The map's name. |
update_ready
A game update is downloaded and waits for the server to restart (servers started by the launcher, ClassicStrike --server): with nobody on it restarts at once, otherwise when the map ends, and ten minutes later at the latest for server and critical updates. A moment to save what the plugin keeps and to tell the players its own way. cs.game.update_version says it too.
| field | type | |
|---|---|---|
version | string | The update's version. |
required | string | none (optional), server (servers and players must move to it) or critical. |
frame
Every server frame, before the game moves the world. Keep it light.
| field | type | |
|---|---|---|
time | number | The game clock. |
player_connect (before handlers)
A player connects. Before handlers may refuse it with ev:reject(reason).
| field | type | |
|---|---|---|
player | Player | Who connects. |
-
:reject(reason: string): Refuses the connection with this reason.
player_join
A player has joined the game (past connecting). A client's handlers run on the next server frame, once it can take messages (a welcome reaches it); a bot's at once.
| field | type | |
|---|---|---|
player | Player | Who joined. |
player_leave
A player leaves. The player object stays valid until the handlers ran. A map change makes everyone leave and connect again.
| field | type | |
|---|---|---|
player | Player | Who leaves. |
map_change | boolean | Whether it is the map changing (the player comes back with the new map). |
chat (before handlers, blockable)
A player says something. Before handlers may block it (nobody sees it).
| field | type | |
|---|---|---|
player | Player | Who speaks. |
text | string | What they said. |
team | boolean | Whether only their team hears it. |
cvar_change
A setting changed value.
| field | type | |
|---|---|---|
name | string | The setting's name. |
old | string | Its value before. |
value | string | Its value now. |
entity_spawn (filters on entity)
An entity has spawned (the map's at its start, and every one made later).
| field | type | |
|---|---|---|
entity | Entity | The entity. |
use (before handlers, blockable, filters on entity)
An entity is used (a button pressed, a trigger firing its target). Before handlers may block it: the entity does nothing.
| field | type | |
|---|---|---|
entity | Entity | What is used. |
activator | Entity? | Who started it (usually a player). |
caller | Entity? | What passes it on (the activator, or a relay). |
use_type | string | off, on, set or toggle. |
value | number | The value of set. |
touch (before handlers, blockable, filters on entity)
Two entities touch (told once for the entity, with the other). Before handlers may block it: the entity does not react.
| field | type | |
|---|---|---|
entity | Entity | What is touched. |
other | Entity | What touches it. |
replay_end
A bot reached the end of the recording it played (Player:play without loop): it stays there, no longer playing.
| field | type | |
|---|---|---|
player | Player | The bot. |
player_spawn
A player has spawned (alive, at a spawn point).
| field | type | |
|---|---|---|
player | Player | Who spawned. |
player_damage (before handlers, blockable)
A player is about to be hurt. Before handlers may change the damage or block it.
| field | type | |
|---|---|---|
player | Player | Who is hurt. |
inflictor | Entity? | What hurts (a weapon's owner, a grenade, a door...). |
attacker | Entity? | Who is to blame. |
damage | number | How much. (settable in before handlers) |
damage_type | number | The kinds of damage (cs.damage). |
player_trace_attack (before handlers, blockable)
A bullet or a blade hits a player (before the damage: blood, armor, hit group). Before handlers may block it.
| field | type | |
|---|---|---|
player | Player | Who is hit. |
attacker | Entity? | Who attacks. |
damage | number | How much. (settable in before handlers) |
damage_type | number | The kinds of damage (cs.damage). |
hit_group | number | The body part (1 head, 2 chest, 3 stomach, 4-5 arms, 6-7 legs). |
player_killed (before handlers, blockable)
A player dies. Before handlers may block it (the player stays alive: set the health back).
| field | type | |
|---|---|---|
player | Player | Who dies. |
attacker | Entity? | Who killed (the world for falls). |
player_command (before handlers)
A player's movement command arrives (every frame of the player's game). Before handlers may change the buttons and the impulse.
| field | type | |
|---|---|---|
player | Player | Whose command. |
buttons | number | The buttons held (cs.button). (settable in before handlers) |
impulse | number | The impulse (100 flashlight, 201 spray). (settable in before handlers) |
forward_move | number | The forward speed asked. (settable in before handlers) |
side_move | number | The sideways speed asked. (settable in before handlers) |
up_move | number | The upward speed asked. (settable in before handlers) |
view_angles | vector | Where the player looks. |
msec | number | The command's length in milliseconds. |
player_move
A player moved through one command (several a frame at high frame rates): the state before and after that move, from the movement itself. Only told to plugins that listen; read the fields, not the player's properties (they change after the event).
| field | type | |
|---|---|---|
player | Player | Who moved. |
msec | number | The command's length in milliseconds. |
buttons | number | The buttons held (cs.button). |
old_buttons | number | The buttons of the command before. |
forward_move | number | The forward speed asked. |
side_move | number | The sideways speed asked. |
view_angles | vector | Where the player looked. |
start_origin | vector | Where the move started. |
start_velocity | vector | The velocity it started with. |
start_on_ground | boolean | On the ground when it started. |
start_ducking | boolean | Ducked (the small hull) when it started. |
origin | vector | Where it ended. |
velocity | vector | The velocity it ended with. |
base_velocity | vector | What pushed the player (conveyors, trigger_push). |
on_ground | boolean | On the ground at the end. |
ducking | boolean | Ducked (the small hull) at the end. |
in_duck | boolean | In the middle of ducking. |
jumped | boolean | The move made a jump (off the ground). |
jump_origin | vector | With jumped: where the player left the ground. |
jump_velocity | vector | With jumped: the velocity right after the jump (the takeoff), before the rest of the move. |
on_ladder | boolean | On a ladder. |
water_level | number | 0 dry, 1 feet, 2 waist, 3 under water. |
ground | Entity? | What the player stands on at the end. |
max_speed | number | The speed cap of the move. |
air_accelerate | number | The air acceleration the move used. |
entity_visible (before handlers, blockable, filters on entity)
An entity goes into what one player is sent this frame (once per viewer and entity: keep it light; filter with { class = } or { entity = }). Before handlers may change how that player alone sees it, or block it (that player does not see it). For fixed choices Player:hide and Player:render cost less.
| field | type | |
|---|---|---|
viewer | Player | Who is sent it. |
entity | Entity | What. |
origin | vector | Where the viewer sees it. (settable in before handlers) |
model | string | Its model (a precached one). (settable in before handlers) |
skin | number | Its skin. (settable in before handlers) |
body | number | Its body group. (settable in before handlers) |
effects | number | Its effects (light, no draw...). (settable in before handlers) |
render_mode | number | Its render mode (0 normal, 1 color, 2 texture, 3 glow, 4 solid, 5 additive). (settable in before handlers) |
render_amount | number | Its render amount (0 to 255). (settable in before handlers) |
render_fx | number | Its render effect (19: glow shell). (settable in before handlers) |
render_color | vector | Its render color (0 to 255 each). (settable in before handlers) |
player_jump
A player jumped off the ground (from the movement: every jump, at any frame rate). To change jumping for a player use Player:set_movement (jump height, auto bunny hop, can_jump): it is predicted.
| field | type | |
|---|---|---|
player | Player | Who jumped. |
origin | vector | Where the player left the ground. |
velocity | vector | The takeoff velocity. |
ducking | boolean | Ducked when jumping. |
player_land
A player landed on the ground after being in the air.
| field | type | |
|---|---|---|
player | Player | Who landed. |
origin | vector | Where. |
fall_speed | number | The falling speed when landing (what fall damage grows with). |
velocity | vector | The velocity after landing. |
player_ladder
A player got on or off a ladder.
| field | type | |
|---|---|---|
player | Player | Who. |
on | boolean | On the ladder now. |
player_water
A player's water level changed (0 dry, 1 feet, 2 waist, 3 under water).
| field | type | |
|---|---|---|
player | Player | Who. |
level | number | The level now. |
old_level | number | The level before. |
player_duck
A player finished ducking (the small hull) or stood up.
| field | type | |
|---|---|---|
player | Player | Who. |
ducking | boolean | Ducked now. |
player_pre_think
Before a player moves, every frame. Keep it light.
| field | type | |
|---|---|---|
player | Player | Who. |
player_post_think
After a player moved, every frame. Keep it light.
| field | type | |
|---|---|---|
player | Player | Who. |
think (before handlers, blockable, filters on entity)
An entity thinks (its next scheduled update). Before handlers may block it: it does not think this time (and does not think again unless something sets its next think). Costly when not filtered: pass a class or an entity.
| field | type | |
|---|---|---|
entity | Entity | What thinks. |
blocked (before handlers, blockable, filters on entity)
A moving entity (a door, a platform, a train) is blocked by another. Before handlers may block it: the mover does not react (no damage, no reversal).
| field | type | |
|---|---|---|
entity | Entity | What moves. |
other | Entity | What is in the way. |
entity_damage (before handlers, blockable, filters on entity)
Any entity (players too, breakables, hostages, buttons...) is about to take damage. Before handlers may change the damage and its kinds, or block it. For players player_damage comes as well, from inside the player's own damage.
| field | type | |
|---|---|---|
entity | Entity | What is hurt. |
inflictor | Entity? | What hurts (a weapon's owner, a grenade, a door...). |
attacker | Entity? | Who is to blame. |
damage | number | How much. (settable in before handlers) |
damage_type | number | The kinds of damage (cs.damage). (settable in before handlers) |
entity_killed (filters on entity)
Damage has destroyed an entity other than a player (a breakable broken, a hostage killed): its health went from above 0 to 0 or less. To keep something alive, lower the damage in entity_damage. Players have player_killed.
| field | type | |
|---|---|---|
entity | Entity | What is destroyed. |
attacker | Entity? | Who destroyed it. |
round_start
A new round begins: players are back at their spawns and the freeze time starts.
| field | type | |
|---|---|---|
round | number | The round's number since the map (or the last restart) began, from 1. |
freeze_time | number | The freeze time's length in seconds. |
freeze_end
The freeze time is over: players may move and the round clock runs.
| field | type | |
|---|---|---|
round | number | The round's number. |
round_end (before handlers, blockable)
The round is about to end. Before handlers may change the reason (and so the winner and the message), the delay before the next round, or block it: the round goes on (the game asks again when the condition still holds).
| field | type | |
|---|---|---|
reason | string | Why: target_bombed, vip_escaped, vip_assassinated, terrorists_escaped, cts_prevent_escape, escaping_terrorists_neutralized, bomb_defused, cts_win, terrorists_win, draw, all_hostages_rescued, target_saved, hostages_not_rescued, terrorists_not_escaped, vip_not_escaped, game_commence, game_restart or game_over. (settable in before handlers) |
winner | string | Who wins for the reason: ct, t or draw (after handlers: the final one). |
delay | number | Seconds before the next round starts. (settable in before handlers) |
game_restart
The game restarts (sv_restart, the game commencing, Game:restart): scores, money and rounds go back to their start.
client_command (before handlers, blockable)
A player's game sends a console command (every one: buy, drop, jointeam, radio1... and those plugins registered, which come after). Before handlers may block it: the game and the plugins' commands ignore it.
| field | type | |
|---|---|---|
player | Player | Whose command. |
command | string | The command's name, in lower case. |
args | string | The rest of the line (its arguments as typed). |
player_choose_team (before handlers, blockable)
A player picks a team (the team menu, jointeam, the automatic pick). Before handlers may change the pick or block it (the player stays where they are); a pick a handler changed passes the game's team balance (mp_limitteams, humans_join_team), not a full team.
| field | type | |
|---|---|---|
player | Player | Who picks. |
team | string | t, ct, auto or spectator. (settable in before handlers) |
player_team
A player's team has changed (by any means: the menu, the automatic balance, a plugin).
| field | type | |
|---|---|---|
player | Player | Who. |
team | string | The team now: t, ct, spectator or none. |
old_team | string | The team before. |
player_name (before handlers, blockable)
A player changes their name. Before handlers may change the new name or block it (the old one stays).
| field | type | |
|---|---|---|
player | Player | Who. |
name | string | The new name. (settable in before handlers) |
old_name | string | The name before. |
player_money (before handlers, blockable)
A player's money changes (a kill, a round's reward, buying, a reset...). Before handlers may change the amount or block it.
| field | type | |
|---|---|---|
player | Player | Whose money. |
amount | number | What is added (negative: taken). (settable in before handlers) |
reason | string | round_win, round_loss, kill, teammate_kill, hostage, bomb, bought, reset, join or other. |
player_buy (before handlers, blockable)
A player is about to buy something (from the menu or a command; the checks of zone, time and team come first, the money after). Before handlers may change the price of this purchase or block it.
| field | type | |
|---|---|---|
player | Player | Who buys. |
item | string | What: a weapon's class (weapon_ak47), item_kevlar, item_assaultsuit, item_nightvision, item_thighpack (the defuse kit), weapon_shield, primary_ammo, secondary_ammo, or a plugin's item by its id. |
cost | number | Its price (a handler may change it for this purchase). (settable in before handlers) |
buy_menu (before handlers, blockable)
A player is about to see a buy menu (the buy key or buy, the equipment key or buyequip), the buy zone, time and team checked. Before handlers may block it and open the plugin's own window instead (cs.window); after handlers hear it opened. Items of the game's menu are added and changed with cs.register_buy_item and cs.set_buy_item.
| field | type | |
|---|---|---|
player | Player | Who opens it. |
menu | string | buy (the buy menu) or equipment (the equipment menu). |
player_pickup (before handlers, blockable)
A player is about to get an item (picked up, bought or given; a duplicate only adds its ammo). Before handlers may block it: the item stays where it is (on the ground, or removed if it was being given).
| field | type | |
|---|---|---|
player | Player | Who gets it. |
item | Entity | The weapon or item. |
player_drop (before handlers, blockable)
A player is about to drop a weapon (the drop command, buying another for the slot, the C4 when dying or leaving; the weapons a dead player leaves come in one box without this event). Before handlers may block it. After handlers get the weapon box it fell into.
| field | type | |
|---|---|---|
player | Player | Who drops it. |
item | Entity | The weapon. |
box | Entity? | After: the box on the ground holding it. |
player_flashed (before handlers, blockable)
A flashbang blinds a player. Before handlers may change how much or block it.
| field | type | |
|---|---|---|
player | Player | Who is blinded. |
attacker | Entity? | Who threw it. |
fade | number | Seconds of the fade back. (settable in before handlers) |
hold | number | Seconds fully blinded first. (settable in before handlers) |
alpha | number | The strength, 0 to 255 (255: looking at it). (settable in before handlers) |
color | vector | The colour (white: 255, 255, 255). (settable in before handlers) |
player_spawn_point (before handlers)
The game picks where a player spawns. Before handlers may give another spot (an entity whose origin and angles are used: a spawn point, an info_target...).
| field | type | |
|---|---|---|
player | Player | Who spawns. |
spot | Entity? | The spot (after: the one used). (settable in before handlers) |
player_equip (before handlers, blockable)
A spawning player is given the round's starting weapons (knife, pistol, and the map's equipment). Before handlers may block it: the player keeps only what they carry (give your own with Player:give).
| field | type | |
|---|---|---|
player | Player | Who. |
player_radio (before handlers, blockable)
A player (or a bot) sends a radio message to their team. Before handlers may block it.
| field | type | |
|---|---|---|
player | Player | Who speaks. |
message | string | The radio sound (%!MRAD_GO...). |
text | string | What the chat shows (#Go_go_go...), or empty. |
player_hint (before handlers, blockable)
The game queues a hint for a player (the tutorial-like messages: #Hint_...). Before handlers may block it.
| field | type | |
|---|---|---|
player | Player | Who. |
message | string | The hint (a #Hint_ key or text). |
weapon_deploy (before handlers, blockable)
A player takes out a weapon. Before handlers may block it: it stays put away (the shooter's own game may show it a moment: its prediction). After handlers run with the weapon out: its view and weapon models set.
| field | type | |
|---|---|---|
player | Player | Whose weapon. |
weapon | Entity | The weapon (weapon_ak47...). |
weapon_holster
A player puts a weapon away (switching, dropping, dying).
| field | type | |
|---|---|---|
player | Player | Whose weapon. |
weapon | Entity | The weapon. |
weapon_attack (before handlers, blockable)
A player's weapon attacks (a shot, a slash, a throw; the secondary: zoom, silencer, burst, the knife's stab). Before handlers may block it (the shooter's own game still shows it: its prediction).
| field | type | |
|---|---|---|
player | Player | Who attacks. |
weapon | Entity | The weapon. |
secondary | boolean | The secondary attack. |
weapon_reload (before handlers, blockable)
A player's weapon starts reloading. Before handlers may block it.
| field | type | |
|---|---|---|
player | Player | Who reloads. |
weapon | Entity | The weapon. |
fire_bullets (before handlers, blockable)
A player fires bullets (once per shot; the shotguns once per pellet). Before handlers may change the damage, the spread, the reach and the penetration, or block it (no bullet: the shooter's own game still shows the shot).
| field | type | |
|---|---|---|
player | Player | Who fires. |
source | vector | Where the bullet starts. |
direction | vector | Where the player aims (before the spread). |
spread | number | The spread (how far off the aim it may go). (settable in before handlers) |
distance | number | How far it reaches. (settable in before handlers) |
penetration | number | How many surfaces it may go through. (settable in before handlers) |
damage | number | The damage at the muzzle. (settable in before handlers) |
grenade_thrown
A player has thrown a grenade.
| field | type | |
|---|---|---|
player | Player | Who threw it. |
grenade | Entity | The grenade in flight. |
kind | string | he, flash or smoke. |
grenade_detonate (before handlers, blockable, filters on grenade)
A grenade or the planted bomb is about to go off. Before handlers may block it: it disappears without effect (a blocked bomb does not win the round). Change its dmg property to change the blast.
| field | type | |
|---|---|---|
grenade | Entity | The grenade, or the bomb. |
kind | string | he, flash, smoke or bomb. |
thrower | Entity? | Who threw or planted it. |
bomb_planted
The bomb has been planted.
| field | type | |
|---|---|---|
player | Player | Who planted it. |
bomb | Entity | The planted bomb. |
bomb_defuse (before handlers, blockable)
A counter-terrorist starts defusing the bomb. Before handlers may change how long it takes or block it.
| field | type | |
|---|---|---|
player | Player | Who defuses. |
bomb | Entity | The bomb. |
kit | boolean | With a defuse kit. |
time | number | Seconds it takes (5 with a kit, 10 without). (settable in before handlers) |
bomb_defuse_end
A defuse ends: done, or stopped (let go, left the ground, died).
| field | type | |
|---|---|---|
player | Player | Who was defusing. |
bomb | Entity | The bomb. |
defused | boolean | Whether it was defused. |
hostage_rescued
A hostage has reached a rescue zone.
| field | type | |
|---|---|---|
hostage | Entity | The hostage. |
rescuer | Player? | Who led it. |
team_win_check (before handlers, blockable)
The game checks whether a team has won the round (players dead, bomb, hostages, VIP, time). Before handlers may block the check: a mode with its own victories ends rounds with Game:end_round.
player_spectate
A spectator's camera changes mode or follows another player.
| field | type | |
|---|---|---|
player | Player | The spectator. |
mode | string | chase_locked, chase_free, roaming, in_eye, map_free or map_chase. |
target | Player? | Whom it follows (nil: no one). |
player_userinfo
A player's userinfo changed (its name, model, rates, keys from setinfo): Player:info(key) reads it.
| field | type | |
|---|---|---|
player | Player | Whose. |
player_voice
A player starts or stops talking on the voice chat (stops: no voice for 0.3 seconds). Player:mute_voice silences a speaker for a listener.
| field | type | |
|---|---|---|
player | Player | Who. |
speaking | boolean | Started (true) or stopped (false). |
player_spray (before handlers, blockable)
A player sprays its picture on a wall (the spray key, every decalfrequency seconds). Before handlers may block it: nothing is drawn, the wait until the next one still counts.
| field | type | |
|---|---|---|
player | Player | Who. |
origin | vector | Where on the wall it goes. |
player_footstep (before handlers, blockable)
A player's movement makes a sound: steps, ladders, wading, swimming. Before handlers may change its volume or block it; the player's own game still plays its own (its prediction), the others hear what is left.
| field | type | |
|---|---|---|
player | Player | Whose. |
sample | string | The sound (player/pl_step1.wav...). |
volume | number | From 0 to 1. (settable in before handlers) |
weapon_idle (before handlers, blockable)
A weapon in hand has nothing to do: it may play an idle animation (or reload when empty, for some). Before handlers may block it.
| field | type | |
|---|---|---|
player | Player | Whose. |
weapon | Entity | The weapon. |
client_message (before handlers, blockable)
The game sends a message to clients: the HUD's texts (TextMsg, SayText, HudTextPro), money, icons, fades, radar, effects (TempEntity)... Before handlers may change its values or block it. Hook it with { message = "TextMsg" } for one message. Messages a handler sends itself do not come here.
| field | type | |
|---|---|---|
message | string | Its name. |
dest | string | Who gets it: one, one_unreliable, all, broadcast (unreliable), init (the signon), pvs, pas, pvs_reliable, pas_reliable. |
player | Player? | Its one receiver (one, one_unreliable). |
origin | vector | Where it is heard (pvs, pas). |
-
:count(): number: How many values it has. -
:arg(index: number): any: Valueindex(from 1): a number, or a string. -
:arg_type(index: number): string: The kind of valueindex:byte,char,short,long,angle,coord,entityorstring. -
:set_arg(index: number, value: any): Changes valueindex(before handlers; a number for numbers, a string for strings; a message of fixed size keeps its strings' lengths).
sound (before handlers, blockable, filters on entity)
An entity starts a sound. Before handlers may block it.
| field | type | |
|---|---|---|
entity | Entity | What makes it. |
sample | string | The sound (a path under sound/, or !sentence). |
channel | number | The channel (0 auto, 1 weapon, 2 voice, 3 item, 4 body, 5 stream, 6 static). |
volume | number | 0 to 1. |
attenuation | number | How fast it fades. |
pitch | number | 100 normal. |