Log inGet started
Package

turretsKit.package

README.md

turretsKit.net

Who is in charge of a turret, and the three multiplayer channels the kit talks on. Used by turretsKit.api (commands, events, the per-frame flush), turretsKit.combat and the turretsKit.Turret component (ownership, shot records).

Channels

FieldChannelCarries
FXturretsKit:fxShots, bolts and clouds the turret's owner fired, batched into one message a frame, so every other peer draws the same shot on the same path. Damage is never in it.
CMDturretsKit:cmdSetting changes, upgrades and sells asked for on a peer that is not in charge, carried out by the one that is.
EVTturretsKit:evtbuilt / upgraded / sold / changed events, so every peer's listeners hear them.

In charge of a turret = the owner of its synced entity, or the room host while nobody owns it (spawnerKit and aiKit use the same rule), or this peer when offline. Subscriptions are remade whenever the engine mode or the room changes; older ones go quiet (they check a generation number), so no message is handled twice. Nothing is sent when no other peer is in the room.

Functions

  • online(): boolean: whether this engine is in a multiplayer room.
  • owns(e: any): boolean: whether this peer is in charge of an entity (its owner; the host while nobody owns it; any unsynced entity; always when offline).
  • othersHere(): boolean: whether any other peer is in the room.
  • handle(kind: string, fn: (number, any) -> ()): sets the handler for "fx" (called once per record), "cmd" or "evt": fn(fromPeer, payload).
  • subscribe(): (re)subscribes to the channels if the mode or room changed.
  • queueFx(rec: any): queues a shot record for the other peers.
  • flush(): sends queued shot records as one message and re-subscribes if needed. Runs once a frame; extra calls in the same frame do nothing.
  • sendCmd(cmd: any): asks the peer in charge to do something.
  • sendEvt(evt: any): tells every other peer about an event.
  • stats(): any: what this peer has sent: { fx, records, cmd, evt }.