Flags
Some game data is a set of on/off flags: which buttons a player holds, which parts of the HUD are hidden, whether an entity is on the ground. In a plugin such a set is an array of names:
function hideMoney(player: Player) {
player.hideHud = ["money", "timer"]; // set exactly these
player.hideHud.push("flashlight"); // add one
const hidden = player.hideHud.includes("money"); // check one
player.hideHud = player.hideHud.filter((f) => f != "money"); // remove one
player.hideHud = []; // clear all
const jumping = player.buttons.includes("jump");
const onGround = player.flags.includes("onGround");
console.log(`${hidden} ${jumping} ${onGround}`);
}
The names are a closed list: the editor suggests them and rejects a typo with
Type '"mony"' is not assignable to type 'HideHud'. Did you mean '"money"'?
- Reading gives an array of the flags that are on, in a fixed order - not the order they were added in.
- Assigning an array sets exactly those flags.
pushturns one more flag on in the game at once.- To turn a flag off, assign a filtered array.
pop,spliceand the other array methods change only the array you hold, not the game.
Flag properties
| Property | On | Names |
|---|---|---|
flags | Entity | EntityFlag: "onGround", "client", "inWater", "fly", "ducking", "fakeClient", "frozen", "godMode", … |
effects | Entity | Effect: "noDraw", "dimLight", "brightLight", "muzzleFlash", … |
buttons, oldButtons | Entity | Button: "attack", "attack2", "jump", "duck", "forward", "back", "use", "reload", "score", … |
weapons | Entity | WeaponKind: "knife", "usp", "ak47", … - the weapons a player carries, as weapon.kind names them |
buttonLast, buttonPressed, buttonReleased | Player | Button: what was held the frame before, what was pressed and what was let go this frame |
hideHud, hideHudSent | Player | HideHud: "weapons", "flashlight", "all", "health", "timer", "money", "crosshair", "observerCrosshair" |
damageType | Player | Damage: "fall", "burn", "freeze", "bullet", "blast", … |
physicsFlags | Player | PhysicsFlag: "onLadder", "onTrain", "onBarnacle", "ducking", "using", "observer" |
weaponState | Weapon | WeaponState: "uspSilenced", "glock18Burst", "m4a1Silenced", "eliteLeft", "famasBurst", "shieldDrawn" |
The types are exported from @amxts/core, for a parameter of your own:
function press(player: Player, button: Button). Admin rights are an array of
names too: player.access, of the type Access (commands).
Assigning weapons changes only the list, not what the player carries: to
give a weapon, player.give("weapon_ak47")
(Players).
hideHud is what the game sends to the player's client on its next frame. To
hide parts of the HUD at once, use player.screen.hideHud(["money"])
(Players).
Effects
A temporary effect is something the game draws for a moment and forgets: a beam, a shockwave, an explosion, sparks, a light, blood. Each effect is a function of effects, its options are the effect's arguments, and the second argument says who sees it.
Cvars
A cvar is a server setting with a name: mp_freezetime, sv_gravity, or one of your plugin's own. A Cvar object reads and writes one: