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.
const shock = server.precache("sprites/shockwave.spr");
const trail = server.precache("sprites/laserbeam.spr");
function blast(here: number[]) {
effects.beamCylinder({ at: here, radius: 385, sprite: shock, life: 0.4, width: 60, color: "#0096ff", alpha: 200 }, { near: here });
effects.sparks({ at: here });
}
function thrown(grenade: Entity, thrower: Player) {
effects.beamFollow({ entity: grenade, sprite: trail, life: 1, width: 5, color: "#0096ff" }, { to: thrower });
}
Sprites and models
An effect draws a sprite or a model the game has precached. server.precache
returns it as a Resource, and that is what an effect's sprite or model
takes:
const shock = server.precache("sprites/shockwave.spr"); // at the top level of the file
server.addEventListener("precache", () => {
const gibs = server.precache("models/glassgibs.mdl"); // or in the "precache" event
});
A file asked for at the top level of the plugin is precached when the map
loads; in the "precache" event it is precached at once. A plugin reloaded in
the middle of a map runs its top level again: the file is not precached a
second time, and the Resource finds the index the map gave it.
resource.path is the path it was given, resource.index the index a native
takes (0 while it is not precached).
The game precaches a file only while the map loads. Asked for later - in a command, in
"init" - a file no plugin precached is said in the console, and
an effect that draws it is not sent, with a line of its own.Who sees it
| Second argument | Who sees the effect |
|---|---|
| left out | everyone |
{ near: point } | the players who can see that point |
{ to: player } | that player alone |
An effect is sent the way the game sends its own: a player whose connection drops it simply misses it.
Units
- Times -
life- are in seconds:life: 0.4. - A colour is CSS hex,
"#0096ff"or"#09f";alphais the brightness,0to255. - Points, sizes and velocities are the world's units, as
entity.originis. - A few sizes are the effect's own numbers,
0to255, which each option's description explains: a beam'swidth(10is one unit), itsnoise(100is one unit), a sprite'sscale(10is its own size). paletteis a colour of the game's palette,0to255: blood red is247.
The effects
Required options first; the rest have defaults.
| Function | What it draws | Options |
|---|---|---|
beamPoints | a beam between two points | start, end, sprite, life, width; color, alpha, noise, frame, frameRate, speed |
beamEntityPoint | a beam from an entity to a point | start (an entity), end, and the beam's options |
beamEntities | a beam between two entities | start, end (entities), and the beam's options |
beamRing | a ring of beam, two entities its diameter | as beamEntities |
beamCylinder | a cylinder growing to radius - a shockwave | at, radius, and the beam's options |
beamDisk | a disk growing to radius | as beamCylinder |
beamTorus | a ring facing the viewer, growing to radius | as beamCylinder |
beamFollow | a trail behind a moving entity | entity, sprite, life, width; color, alpha |
beamSprite | a beam with a sprite at its end | start, end, sprite, endSprite |
lightning | a bolt between two points | start, end, sprite, life, width; noise |
killBeams | takes away an entity's beams | entity |
explosion | an explosion: sprite, light, particles, sound | at, sprite; scale, frameRate, additive, lights, sound, particles |
tarExplosion | a burst of dark particles | at |
particleExplosion | a burst of particles in palette colours | at; palette, colors |
smoke | a puff of smoke | at, sprite; scale, frameRate |
implosion | tracers flying into a point | at, radius, count, life |
gunshot | a bullet's hit | at |
sparks | sparks falling from a point | at |
armorRicochet | a bullet off armour | at; scale |
lavaSplash, teleport | a splash of particles | at |
tracer | a tracer from one point to another | start, end |
showLine | a line of particles for 30 seconds | start, end |
streakSplash | a shower of tracers in a direction | at, direction, count, speed; randomness, palette |
sprite | a glowing sprite that plays once | at, sprite; scale, alpha |
glowSprite | a glowing sprite that stays | at, sprite, life; scale, alpha |
spriteTrail | glowing sprites flying off a line | start, end, sprite, count, life; scale, speed, randomness |
spriteSpray | a spray of sprites | at, velocity, sprite, count, speed; noise |
largeFunnel | a funnel of sprites | at, sprite; reverse |
fizz | bubbles inside a brush entity | entity, sprite, density |
bubbles, bubbleTrail | bubbles rising from a box, from a line | start, end, height, sprite, count, speed |
dynamicLight | a light on the world around a point | at, radius, life; color, decay |
entityLight | a light on an entity, lighting entities only | entity, at, radius, life; color, decay |
line | a coloured line | start, end, life; color |
box | a box's edges | mins, maxs, life; color |
blood, bloodStream | a spray, a stream of blood | at, direction, speed; palette |
bloodSprite | blood as the game draws a hit | at, spray, drop; scale, palette |
model | a model thrown that bounces - a shell | at, velocity, model, life; yaw, sound |
explodeModel | pieces of a model in every direction | at, speed, model, count, life |
breakModel | pieces out of a box - something broken | at, size, velocity, model, count, life; randomness, material, smoke, transparent |
projectile | a model flying like a nail | at, velocity, model, life; owner |
spray | a shower of models or sprites | at, direction, model, count, speed; noise, renderMode |
playerSprites | sprites out of a player's body | player, sprite, count; variance |
particleBurst | a burst of particles in one colour | at, radius, life; palette |
fireField | a square of fire sprites | at, radius, sprite, count, life; rise, blend, loop, flat |
playerAttachment | a model above a player, going where he goes | player, model, life; offset |
killPlayerAttachments | takes away a player's attached models | player |
The beam's options are sprite, life and width, then color (white),
alpha (255), noise (0, straight), frame and frameRate (the
sprite's animation) and speed (how fast the sprite scrolls along it). Each
option's own description - in the editor - gives its range and default.
A text on the screen is player.showHud. A decal - a bullet hole, a spray on
a wall - is not an effect yet: send it with the natives, message_begin and
write_* (limitations).
Players: actions
A Player is a player on the server. The event or the command that is about him gives him to you (event.player, player in a command's handler), and server.players lists everyone. His game data - gravity, origin, hideHud and the rest - are properties, described on Players and entities. This page is about what you do with a player: find him, move him to a team, give him weapons, show him text, and share his state with other plugins.
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: