Co-op

Usage guide of coop.session: drop-in, drop-out co-op for 1 to 4 players in one world, room codes, personal or shared loot, downed state and revive, difficulty by player count, settings and defaults, service, events, hooks and variables.

Source: module-kits:kits/coop_session/usage/en.mdView Markdown source

Also read offline — CLI: grip-forge docs coop-sessionMCP tool: gripforge_docs { "topic": "coop-session" }

Drop-in co-op (coop.session) #

What it is for #

coop.session puts one to four players in the same world, for survival, RPG, horror, platformer or any PvE game. The host (a player's browser or a dedicated process) owns the world; friends join by a room code at any time, receive the whole world on arrival and leave without ending it. Each player has their own character: inventory, needs, levels and wallet follow them and come back when they rejoin. A downed player can be revived by a teammate before they bleed out; loot is personal or shared; enemies scale with the number of players. Roles are solo, host (the authority) and client (a replica corrected by every snapshot). A lobby, a team HUD (health and status of everyone) and a revive prompt are drawn by the web display module.

Turn it on #

Install the kit in a project and set its settings with the tools below; gripforge kit api coop.session lists every setting, and gripforge docs coop-session prints this guide offline.

gripforge_gamekit_install   { project_id: "gkp_…", id: "coop.session" }
gripforge_gamekit_configure { project_id: "gkp_…", id: "coop.session",
                              config: { "maxPlayers": 4, "loot": "shared", "downedSeconds": 45 } }

First example #

<!-- test: kits/game_engine/host/tests/net_kits.rs::a_coop_room_travels_through_the_relay_of_the_core --> A host opens a room over net.transport: the room code is the one configured, a client joining with the handshake gets a seat and a welcome packet then the whole world, players() lists it, and its departure emits coop.left and keeps its character. Joining without a room code does nothing.

coop.session.hostRoom()                  // true
coop.session.code()                      // "LAN1" (the room configured on net.transport)
coop.session.players()                   // [ host, { seat: 1, name: "Bob", … } ] once Bob joined
                                         // when Bob leaves: coop.left, his character is kept
coop.session.joinRoom("  ", "Zed")       // false: no room code

Settings and defaults #

SettingDefaultMeaning
maxPlayers4{{s_maxPlayers}}
playerNamePlayer{{s_playerName}}
snapshotHz, inputHz10, 20world deltas sent to the clients per second (snapshotHz, 1 to 60) and inputs a client sends per second (inputHz, 1 to 60)
keyframeSeconds, positionStep, angleStep0, 0.001, 0.001keyframeSeconds 0: the whole world only goes to each newcomer and to a client that asks for it; above 0 it is also resent to everyone that often. positionStep and angleStep quantize positions (m) and yaw (rad) in deltas; 0 on both sends them exactly
moveSpeed, sprint, snapTolerance4.5, 1.6, 2how the host judges a client: moveSpeed (walk speed in m/s of a remote player moved by its inputs), sprint (multiplier) and snapTolerance (a client keeps its own predicted position while the host agrees within this distance in m)
playerHealth100{{s_playerHealth}}
downedSeconds30{{s_downedSeconds}}
reviveSeconds, reviveRadius, reviveHealth3, 2, 0.3reviveSeconds (holding revive next to a downed teammate this long brings them back, 0.1 to 60), reviveRadius (reach in m) and reviveHealth (share of health they get back, 0.01 to 1)
respawnSeconds10{{s_respawnSeconds}}
interactRadius2.5{{s_interactRadius}}
dropSeconds, rejoinSeconds4, 60dropSeconds: a client that hears nothing from the host this long counts its transport as dropped (1 to 120); rejoinSeconds: a room client whose transport drops joins the same code again with its rejoin token, seat and character back, retrying this long (0: never, up to 600)
loot, lootEventspersonalpersonal: what a player picks up is theirs; shared: every player present gets the same. lootEvents lists the events with { item, count } that count as loot for shared (default inventory.picked, resource.gathered)
difficulty{ count: 0.5, health: 0.35, damage: 0 }multipliers by player count, 1 + share x (players - 1): count (extra enemies per extra player, 0.5), health (extra enemy health, 0.35), damage (extra enemy damage, 0). encounters.waves and enemy.ai read the variables below
localKits, localVarslistsprefixes of kit ids (localKits) and of variables (localVars) whose state a client keeps from its own machine when a keyframe arrives: its view, camera, controls, inventory and needs (long default lists; extend them for your own kits)
autoHostfalse{{s_autoHost}}
clickRevivetrue{{s_clickRevive}}
actions[]{{s_actions}}
localTags["cinematic.cast"]{{s_localTags}}

Fighting together (1.8) #

<!-- test: kits/game_engine/host/tests/coop_combat.rs::a_client_press_strikes_on_the_host_for_its_own_character_and_the_client_sees_it --> A client sends the host the game's actions it presses (a sabre cut, a guard, a shot) as well as its movement: at join it gives the table of those actions (actions, or every button action of a kit that is not in localKits), then each input message carries what it holds, its press and release edges and where its view aims. The host gives them to input.actions 1.11 as the input of that client's character, so the host's weapon, guard and moveset kits act for the right player (pressedBy), and every machine names its own character there. The result reaches the client with the next delta. A game that registers no such action sends nothing more: the messages stay those of protocol 2.

Pauses and cinematics (1.9) #

<!-- test: kits/game_engine/host/tests/coop_combat.rs::a_client_follows_the_hosts_cinematic_through_the_pause_and_only_the_host_skips --> The session goes on while the game is held (a cinematic, a pause menu): the host keeps taking its clients' messages and sending its deltas and phase, the clients keep sending their input, and nobody is moved, revived or bled out meanwhile. A cinematic the host plays therefore reaches every client, which shows it with its own cast (game.cinematic 1.9): the entities tagged with one of localTags stay on the machine that made them, never replicated nor removed by replication. The host skips for everyone.

Services #

  • coop.session (service): role(), code(), menu(open?), players() (a list of { seat, name, entity, status, host, ping, you } with status of online, away, downed or out), me(), token(), host(link, { code?, name?, seatLocal? }), join(link, name, token?), leave(), hostRoom(code?, name?) and joinRoom(code, name, token?) over net.transport, setInput(partial | null), holdRevive(on), ping(), difficulty() ({ players, count, health, damage }), downed(entity?), reviveTarget(entity?), revive(target, by?), characters(), stats() and memoryHub() for in-process sessions.
  • Variables: coop.role, coop.menu, coop.code, coop.players, coop.ping, coop.downed, coop.bleedout, coop.revive_target, coop.reconnecting, coop.revive_progress, difficulty.enemy_count, difficulty.enemy_health, difficulty.enemy_damage. Inputs: revive (hold, key KeyT) and coop_menu (key KeyO).

Events #

  • coop.hosting (this machine became the host, with the code), coop.joined (a player arrived: player, seat, name, rejoined when they came back with their character), coop.left (a player left: reason of left, dropped or closed; their character is kept), and for a client coop.connected, coop.reconnecting (the transport dropped, joining the room again: attempt, seconds left), coop.disconnected and coop.refused (reason: full, version, closed, or mods when the host runs other mods).
  • coop.downed (a player is down: player, seconds), coop.revived (player, by), coop.bledout, coop.respawned, coop.wiped (every player present is down at once: a game over for a trigger to act on), coop.difficulty (players, count, health, damage) and interaction.requested (the interact press of a remote player on the nearest interactable in reach, as interaction.system emits it for the local player). It listens to inventory.picked and resource.gathered.

Hooks and modding #

  • coop.down: the host asks it once when a player at 0 health (or tagged dead) is about to be downed for seconds; seconds is mutable (0: the bleed-out comes at the next tick), and cancelling means no downed phase at all: the player is out at once (coop.bledout, no coop.downed) and the respawn clock starts.
  • coop.revive: the revive of a downed player is about to succeed (a teammate held revive for reviveSeconds, or revive(target, by)); health is the share given back and is mutable, and cancelling keeps the player downed, resets the progress to 0 (revive returns false) and lets the bleed-out clock run on.
  • coop.bleedout: the time of a downed player is over and they are about to bleed out; a continuous decision asked once and held: cancelled, the player stays downed and revivable while the refusal is kept, and it is released when they are revived.

A mod can tune the rules the host applies: playerHealth, downedSeconds, reviveSeconds, reviveRadius, reviveHealth, respawnSeconds, interactRadius, loot, difficulty and clickRevive. What sizes or paces the session, bounds a client or says what is replicated stays the project's.

{ "id": "last_stand", "hook": "coop.down", "set": { "seconds": 60 } }
{ "id": "medic", "hook": "coop.revive", "match": { "by": "e1" }, "set": { "health": 1 } }

When it does not do what you expect #

SymptomCause and fix
A client is refused on joiningRead coop.refused: full (maxPlayers reached), version (a client of an older wire protocol), closed (the room is closed) or mods (the host runs other mods than this game).
joinRoom or hostRoom returns falseThere is no room code, or no kit host serves the network core: install net.transport, or use host and join with your own link.
A client's attacks do nothing on the hostThe kit of that attack reads pressed(action) (this machine's keys) instead of pressedBy(actor, action), the action is registered by a kit of localKits, or it is missing from actions when you set that list.
A downed player is never revivedThe reviver is further than reviveRadius, releases the key before reviveSeconds, or a coop.revive tap cancelled it; with downedSeconds at 0 there is no downed state at all.

Limits #

  • The host owns the world; if the host leaves, the session ends for the others.
  • It runs on the web player and the native Rust host. A client keeps its own local player only on the web; hostRoom and joinRoom need a kit host that serves the network core. A 1.7 host refuses 1.0 to 1.6 clients (version).
  • One match per server process: to run many rooms, start one server per match.
  • A client gives its table of actions when it joins (at most 32): an action registered later, such as the custom inputs of a weapon equipped afterwards, is sent from its next join. The relay path (hostRoom / joinRoom) of these actions is covered by a codec test, the two-player test runs on an in-memory link.

Versions #

Kit coop.session 1.9.0 (2026-10-30): the session goes on through pauses and cinematics, localTags. 1.8.0 (2026-10-30): the game's actions of each player reach the host as the input of their character. 1.7.0 (2026-10-12): a binary wire (protocol 2), numbered deltas with resync, no periodic keyframe by default. 1.5 added reconnection (dropSeconds, rejoinSeconds), 1.4 the hooks of the downed state, 1.6 the click revive. It needs input.actions and game.engine ^1, and net.transport for room codes.

<!-- kit-services:begin -->

Services this kit uses (and that you can provide) #

CapabilityRequiredMethods
character.controloptionallookYaw, pitch, player, teleport, yaw
combat.damageoptionaladdModifier, removeModifier
combat.healthoptionalhealth, register
engine.hooksoptionalhold, release, run
engine.modsoptionalfingerprint
input.actionsrequiredaxis, clear, feed, pressed, setLocal, settings
input.schemeoptionalclearMoveOrder, held, intents, issue, moveOrder
inventory.itemsoptionalgive
net.coreoptionalclose, command, connect, create, now, query, transforms, update
net.physicsoptionalconfig
net.transportoptionalconfig, host, listen, open, unlisten
runtime.coreoptional (host)load, save
world.groundoptionalbounds, defaultSpawn, groundY

Any brick can serve them: a kit, or your engine (Godot provide_service, Unity Provide, Unreal ProvideService, Bevy provide_kit_service, C gfk_provide) — see the guide. <!-- kit-services:end -->