gdmp.players
| Call | What it does |
|---|---|
count() |
players in the session |
get(id) → player | null |
{id, name, isLocal, connected, joined, inLevel, levelId, alive, dead, position: {x, y}, rotation, facing, form, icon, hasLook, primaryColor, secondaryColor, ...} (position only while in a level) |
list() → player[] |
every player |
onJoin(cb) onLeave(cb) onSpawn(cb) onDeath(cb) onRespawn(cb) |
cb(player); the same edges on every host |
server: respawn(id) → bool |
GD’s own restart for that player |
server: teleport(id, x, y) / teleport(id, {x, y}) → bool |
move a player |
server: freeze(id, on = true) → bool |
hold a player in place |
server: setMovement(id, mode, {speed}) → bool |
(level 92) "free": that player walks in all four directions (see gdmp.player.setMovement); "platformer": GD’s movement again. A gdmp.control message, like freeze |
server: setVisible(id, visible[, viewerId]) → bool |
stop / start drawing a player, for everyone or for one viewer |
server: setOutline(id, color) → bool |
(level 91) a ring in color ("#RRGGBB" / 0xRRGGBB) around that player’s icon, for everyone; null = none. Same grant as gdmp.nametags; true = sent to at least one player |
true = sent to that player’s game; false = not here (or dropped by the rate limit).
Touch: players meeting each other
Section titled “Touch: players meeting each other”Since API level 89.
GDMP draws the other players without physics: nobody blocks, pushes or lands on anybody. A game that needs contact
(tag, infection, “catch the runner”) asks for it here. Two players touch while both are in the same level with a
position and are within d of each other on both axes: |dx| <= d and |dy| <= d, i.e. two squares of side d
centred on them overlap. d is 30 (one block) unless the script sets it. Like the zones, it is evaluated on every tick
(the server: ~30 / s) from the positions the host has, so a client sees the others slightly in the past and the
server’s touch is the one to trust. Nothing is evaluated until a script uses one of these calls.
| Call | What it does |
|---|---|
onTouch(cb) |
cb({a, b, playerA, playerB}) when two players start touching; a < b are their ids. It fires once per meeting: they must part before it fires again |
onTouchEnd(cb) |
the same shape when they part, leave the level or change level; playerA / playerB is null for a player who left |
touching(id) → id[] |
who touches that player now (after the last tick), ascending; [] for an unknown id |
setTouchDistance(units) → the previous distance |
units in (0, 3000]; applies from the next tick |
// a SERVER script -- tag: "it" passes on by touching someone (no tag-backs for 2 s)let it = null, safeUntil = 0;gdmp.players.onTouch(e => { if ((e.a !== it && e.b !== it) || gdmp.time.now() < safeUntil) return; it = e.a === it ? e.b : e.a; safeUntil = gdmp.time.now() + 2000; gdmp.state.set("it", it);});TypeScript
Section titled “TypeScript”The declarations from the GDMP types (namespace GDMP), comments included:
/** A player, as a frozen copy. The optional groups are absent (not zero) when the host does not have them. */interface Player { readonly id: PlayerId; readonly name: string; readonly connected: boolean; readonly joined: boolean; readonly inLevel: boolean; readonly alive: boolean; readonly dead: boolean; readonly levelId?: number; readonly isLocal?: boolean; readonly experience?: { readonly id: string; readonly version: number; readonly instance: string } | null; /** Only while the player is in a level. */ readonly position?: Vec2; readonly rotation?: number; readonly facing?: 'left' | 'right'; readonly form?: string; readonly icon?: number; readonly hasLook?: boolean; readonly primaryColor?: Rgb; readonly secondaryColor?: Rgb; readonly animation?: { readonly id: number; readonly frame: number };}
interface PlayersCommon { count(): number; get(id: PlayerId): Player | null; list(): Player[]; onJoin(cb: Callback<[player: Player]>): void; onLeave(cb: Callback<[player: Player]>): void; onSpawn(cb: Callback<[player: Player]>): void; onDeath(cb: Callback<[player: Player]>): void; onRespawn(cb: Callback<[player: Player]>): void; /** Level 89. Fires once per meeting: they must part before it fires again. */ onTouch(cb: Callback<[event: TouchEvent]>): void; onTouchEnd(cb: Callback<[event: TouchEvent]>): void; /** Who touches that player now (after the last tick), ascending. */ touching(id: PlayerId): PlayerId[]; /** `units` in (0, 3000]; returns the previous distance. */ setTouchDistance(units: number): number;}
interface PlayersServer extends PlayersCommon { /** GD's own restart for that player. `true` = sent to that player's game. */ respawn(id: PlayerId): boolean; teleport(id: PlayerId, x: number, y: number): boolean; teleport(id: PlayerId, position: { x: number; y: number }): boolean; freeze(id: PlayerId, on?: boolean): boolean; /** Level 92. */ setMovement(id: PlayerId, mode: MovementMode, options?: { speed?: number }): boolean; setVisible(id: PlayerId, visible: boolean, viewerId?: PlayerId): boolean; /** Level 91. `null` = none. */ setOutline(id: PlayerId, color: Color | null): boolean;}
/** Two players started (or stopped) touching. `a < b`. `playerA` / `playerB` is null for a player who left. */interface TouchEvent { readonly a: PlayerId; readonly b: PlayerId; readonly playerA: Player | null; readonly playerB: Player | null;}