Logic Bots
Chapters

PHP reference

Use this reference to look up the Pilot methods, PHP functions, and constants the script engine accepts. The signatures are generated from the same reference used by autocomplete in Bot Builder.

A signature describes inputs and return types. For when to call a method and how to interpret its result, see the Pilot API, PHP syntax, and worked examples.

Simulation 1.38.0.

Pilot methods

Pilot::scan(): array
Returns the tick snapshot. Keys include self, allies, enemies, pickups, and threats. Contacts carry match-local IDs, X/Z coordinates, bearings in radians, and observed velocity. Pickup entries include amount and secondsRemaining. Hidden opponents are omitted.
Pilot::selfState(): array
Returns this bot’s identity, resources, position, heading, movement, mitigation, and mountSlots. Positions are in arena units, headings in radians, velocities in arena units per second, and timers in seconds.
Pilot::mountState(int $slot): ?array
Reads the specified zero-based mount or returns null. Fields include component, mode, targeting, ready, blockedReason, pendingAim, cooldownRemaining, costs, and applicable effects or upkeep. For aimed weapons, effectiveRange includes the shooter’s targeting bonus. Durations are in seconds.
Pilot::battleState(): array
Returns tick, elapsed, tickDuration, mode, phase, deadlines, attrition, pickup rules, friendly fire, and arena and movement bounds. Positions use X/Z, durations use seconds, and tick fields use simulation ticks.
Pilot::teamState(): array
Returns teamId, participantId, seat, tick, and the own-team roster. The roster includes eliminated seats. Living entries have heading, movement and stun status, cloak, weapon readiness, and coarse resource bands.
Pilot::sendTeamMessage(string $topic, array $payload, ?int $recipientId = null, int $ttlTicks = 20): ?string
Queues a private direct message to an eligible teammate or broadcasts with a null recipient. Returns a match-local message ID or null. Delivery occurs next tick and previous delivery results appear in actionResults().
Pilot::teamMessages(?string $topic = null, ?int $senderId = null): array
Returns messages and truncated for this recipient. Filter by topic or sender ID. Envelopes include id, topic, payload, senderId, recipientId, sentTick, deliveredTick, and expiresTick. Repeated reads are nonconsuming.
Pilot::claimTeamObjective(string $kind, int $objectiveId, int $ttlTicks = 40): bool
Queues an advisory claim for a currently visible pickup. Use kind pickup and its match-local ID. The lifetime uses ticks. Previous outcomes appear in actionResults().
Pilot::releaseTeamObjective(string $kind, int $objectiveId): bool
Queues release of this bot’s advisory pickup claim. Enter kind pickup and the visible pickup ID. The engine checks ownership at resolution.
Pilot::teamClaims(?string $kind = null): array
Lists current own-team claims, optionally filtered by kind. Each includes the objective ID, claimant ID, and creation and expiry ticks.
Pilot::publishTeamData(string $key, array $value, int $ttlTicks): bool
Queues a bounded value under an owner-scoped team key. The value is visible to teammates next tick. The lifetime uses ticks.
Pilot::clearTeamData(string $key): bool
Queues removal of this bot’s value for the team key. The key can retain values published by other teammates.
Pilot::teamData(string $key): ?array
Returns null for a missing team key or an object with entries. Entries include ownerId, value, updatedTick, and expiresTick.
Pilot::actionResults(): array
Reads previous-tick command outcomes, including movement and mount results, rejection reasons, team delivery receipts, and team claim or data outcomes.
Pilot::memory(): array
Reads the key/value state this bot has saved during the current battle. Use recall() when you need a single key.
Pilot::recall(string $key): mixed
Reads one value from this bot’s match-local memory. Returns null for a missing key.
Pilot::remember(string $key, array|string|int|float|bool|null $value): bool
Stores a value in this bot’s private match-local memory and reports success. Passing null removes the key. Each bot has 4 KiB of memory.
Pilot::randomInt(int $min, int $max): int
Returns a repeatable random integer in the inclusive range requested. The range is within −1,000,000,000 to 1,000,000,000. Each bot has its own stream.
Pilot::workRemaining(): int
Reports this script’s remaining work for the current tick.
Pilot::debug(string $label, mixed $value): bool
Adds a bounded label and data value to the authorized practice trace and reports success. Ordinary matches have no script debug trace.
Pilot::recentEvents(): array
Lists observable events since this bot last acted, such as damage, resource pickups, effect changes, contacts, and private shot feedback.
Pilot::signals(): array
Reads the location signals teammates sent on the previous tick. Entries include kind, X/Z, sender, and tick.
Pilot::signal(string $kind, float $x, float $z): bool
Queues one enemy, help, or pickup location signal to teammates. Coordinates are in arena units.
Pilot::moveTo(float $x, float $z, bool $reverse = false): bool
Queues one tick of movement toward the arena point. Set reverse to back toward it. Coordinates are in arena units. Check actionResults() for blockedByBot when the chassis meets another bot.
Pilot::estimateMove(float $x, float $z, bool $reverse = false): ?array
Returns the reachable X/Z point, turnSeconds, driveSeconds, and totalSeconds from the current pose, assuming a clear route. Returns null if the point or movement is unavailable.
Pilot::estimateThreats(): array
Lists visible projectiles and pulses projected to reach this bot if it stays put. Each has kind, type, mode, X/Z, and impactSeconds.
Pilot::estimateThreatsAt(float $x, float $z): ?array
Forecasts the same visible threats at a candidate X/Z point, in impact-time order. Returns null for points outside the arena.
Pilot::estimateFriendlyFire(int $slot, ?float $x = null, ?float $z = null): ?array
Returns friendlyFireEnabled and atRisk. Risk entries contain allied IDs, effect types, and estimated impact time from launch. Centered effects use only a slot. Invalid arguments return null.
Pilot::estimateIntercept(int $slot, float $x, float $z, float $vx, float $vz): ?array
Estimates a ground X/Z aim point and aimSeconds, travelSeconds, and totalSeconds from a scanned position and velocity in arena units per second. Returns null when no estimate is available.
Pilot::estimateReadiness(int $slot): ?array
Returns readyTick, seconds, and the current blockedReason. The timing fields are null when readiness cannot be forecast under current recovery conditions. Unsupported mounts return null.
Pilot::turnTo(float $heading): bool
Queues one tick of chassis rotation in place toward an absolute heading in radians. The last valid movement request wins.
Pilot::destination(): ?array
Returns the movement queued this tick as x, z, and reverse, or null when there is none.
Pilot::queuedActions(): array
Reads this tick’s queued move, turn, aim, fire, cancel, toggle, and signal actions. This is separate from previous outcomes.
Pilot::holdPosition(): bool
Clears voluntary movement and turning queued this tick. Existing knockback still applies.
Pilot::weaponRange(int $slot): ?float
Returns a firing mount’s range or pulse radius in arena units. An unfitted or non-firing mount returns null.
Pilot::estimateShot(int $slot, float $x, float $z): ?array
Returns inRange, aimSeconds, and travelSeconds from this pose to an arena point. Returns null for invalid points and centered effects.
Pilot::toggle(int $slot, bool $on): bool
Queues an equipment state change on a zero-based mount. Read the resolved outcome in actionResults().
Pilot::fire(int $slot, ?float $x = null, ?float $z = null): bool
Queues a shot from a zero-based mount. Point weapons take X/Z coordinates. Missiles launch without waiting for turret alignment. Centered effects take only the mount slot.
Pilot::aim(int $slot, float $x, float $z): bool
Queues turret rotation toward an arena point. Check actionResults() for alignment. A valid missile aim completes immediately because its launcher is fixed.
Pilot::cancelAim(int $slot): bool
Queues cancellation of pending aim or fire on an aimed mount. The turret keeps its current angle.

PHP functions and constants

abs(int|float $num): int|float
Returns a number’s magnitude.
acos(float $num): float
Returns the inverse cosine in radians.
asin(float $num): float
Returns the inverse sine in radians.
atan2(float $y, float $x): float
Returns the angle in radians for the supplied vector components.
ceil(int|float $num): float
Rounds toward positive infinity.
cos(float $num): float
Returns the cosine of an angle in radians.
deg2rad(float $num): float
Converts degrees to radians.
floor(int|float $num): float
Rounds toward negative infinity.
hypot(float $x, float $y): float
Returns the length of a two-dimensional vector.
intdiv(int $num1, int $num2): int
Divides two integers and truncates the quotient toward zero.
max(mixed $value, mixed ...$values): mixed
Returns the greatest supplied value.
min(mixed $value, mixed ...$values): mixed
Returns the least supplied value.
rad2deg(float $num): float
Converts radians to degrees.
round(int|float $num, int $precision = 0, RoundingMode|int $mode = RoundingMode::HalfAwayFromZero): float
Rounds a number to the specified decimal precision. Omit the optional rounding mode to use the default.
sin(float $num): float
Returns the sine of an angle in radians.
sqrt(float $num): float
Returns the square root of a nonnegative number.
tan(float $num): float
Returns the tangent of an angle in radians.
array_column(array $array, string|int|null $column_key, string|int|null $index_key = null): array
Collects one field from each row, with an optional field to use as the result key.
array_key_exists($key, array $array): bool
Checks whether a key is present, including a key whose value is null.
array_keys(array $array, mixed $filter_value, bool $strict = false): array
Returns array keys, optionally filtered by value.
array_slice(array $array, int $offset, ?int $length = null, bool $preserve_keys = false): array
Returns part of an array, with optional length and key preservation.
array_sum(array $array): int|float
Returns the sum of an array’s values.
array_values(array $array): array
Returns values indexed by consecutive numbers starting at zero.
count(Countable|array $value, int $mode = 0): int
Returns the number of elements in an array.
in_array(mixed $needle, array $haystack, bool $strict = false): bool
Checks whether a value appears in an array. Use strict to compare types as well.
is_array(mixed $value): bool
Checks whether a value is an array.
is_bool(mixed $value): bool
Checks whether a value is boolean.
is_finite(float $num): bool
Checks whether a number is finite.
is_float(mixed $value): bool
Checks whether a value is a floating-point number.
is_int(mixed $value): bool
Checks whether a value is an integer.
is_null(mixed $value): bool
Checks whether a value is null.
is_numeric(mixed $value): bool
Checks whether a value is a number or numeric string.
is_string(mixed $value): bool
Checks whether a value is a string.
strlen(string $string): int
Returns the length of a string in bytes.
strtolower(string $string): string
Converts ASCII letters to lowercase.
strtoupper(string $string): string
Converts ASCII letters to uppercase.
substr(string $string, int $offset, ?int $length = null): string
Returns a segment of a string using byte offsets.
Constants
true, false, null, M_PI, M_PI_2, M_PI_4

Examples

Choose a nearby contact

<?php
function nearest(array $contacts): ?array {
    return $contacts[0] ?? null;
}

$contact = nearest($pilot->scan()['enemies']);
if ($contact !== null && ($pilot->mountState(0)['ready'] ?? false)) {
    $pilot->aim(0, $contact['x'], $contact['z']);
}

Acknowledge a team request

<?php
function acknowledge(array $messages, int $tick): void {
    foreach ($messages as $message) {
        if ($message['deliveredTick'] === $tick) {
            $pilot->sendTeamMessage('ack', ['replyTo' => $message['id']], $message['senderId']);
        }
    }
}

acknowledge($pilot->teamMessages('help.request')['messages'], $pilot->battleState()['tick']);