Agent selections
The native API returns collections such as all agents, allies and enemies. Selection helpers are useful when a feature needs to apply several conditions and then choose one result: the nearest visible enemy, every living teammate, or agents inside a radius.
Minimal example
Section titled “Minimal example”import { agents } from "@killscript/sdk/client";
const visibleLivingEnemies = agents .select(agents.enemies()) .visible() .alive() .toArray();agents.select() copies the source collection into an ordinary generated Lua
table. Chained filters modify this private selection; they never modify the
game’s native collection.
toArray() returns a shallow copy. Mutating that returned array does not alter
the selection used by first(), count() or later filters.
Call agents.select() without an argument to start from Agents.GetAll().
Direct agent queries
Section titled “Direct agent queries”The same agents namespace exposes the common native collections in both
client and Reflex code:
| Method | Native result |
|---|---|
local() | Local agent or undefined |
localOrSpectated() | Local or currently spectated agent, or undefined |
all() | Agents.GetAll() |
allies() | Agents.GetAllies() |
enemies() | Agents.GetEnemies() |
select(values?) | A chainable private selection; defaults to all agents |
Choose the nearest valid target
Section titled “Choose the nearest valid target”import { agents } from "@killscript/sdk/client";
function nearestVisibleEnemy(maxDistance: number): Agent | undefined { const local = agents.local(); if (local === undefined) return undefined;
const origin = local.Movement.Position; return agents .select(agents.enemies()) .visible() .alive() .within(origin, maxDistance) .nearestTo(origin);}Each condition reads from left to right. A missing result is undefined, so
the caller must handle the case where no agent matches.
Available operations
Section titled “Available operations”| Operation | Result |
|---|---|
where(predicate) | Keeps agents accepted by a custom predicate |
alive() / dead() | Filters by agent.Stats.IsAlive |
visible() | Keeps agents with at least one currently visible hitbox |
within(origin, distance) | Keeps agents no farther than the world-space distance |
exclude(agent) | Removes one agent; undefined is ignored |
team(team) | Keeps one native Team value |
first() | Returns the first current result |
nearestTo(origin) | Returns the closest current result |
count() | Returns the current result count |
toArray() | Returns the filtered ordinary array |
Use where() for a condition that is not already represented:
const richAliveAgents = agents .select() .visible() .alive() .where((agent) => agent.Stats.Money >= 5000) .toArray();For arbitrary non-agent collections, use Game arrays.