Перейти к основному содержанию

Network

Working with client and server packets in multiplayer and also determine stuff.

Index

Functions

addClientPacket

  • addClientPacket<T>(name: string, func: (packetData: T) => void): void
  • Event that is called when a client receives a packet with given name.


    Type parameters

    • T: object

    Parameters

    • name: string

      name of the packet

    • func: (packetData: T) => void

      Returns void

    addServerPacket

    • addServerPacket<T>(name: string, func: (client: NetworkClient, data: T) => void): void
    • Event that is called when server receives a packet with the specified name from client.


      Type parameters

      • T: object

      Parameters

      • name: string

        name of the packet

      • func: (client: NetworkClient, data: T) => void

        Returns void

      getClientForPlayer


      • Parameters

        • player: number

        Returns NetworkClient

        Client object for player by player's entity ID.

      getConnectedClients


      • Returns native.Array<NetworkClient>

        Array containing connected clients.

      getConnectedPlayers

      • getConnectedPlayers(): native.Array<number>

      • Returns native.Array<number>

        Array containing connected players UIDs.

      inRemoteWorld

      • inRemoteWorld(): boolean
      • @since

        2.1.0b57


        Returns boolean

        true if player connected to remote world.

      localToServerId

      • localToServerId(id: string | number): number
      • Converts item or block ID from local to server value.


        Parameters

        • id: string | number

        Returns number

      sendServerMessage

      • sendServerMessage(message: string): void
      • Sends message to all players.


        Parameters

        • message: string

          text of the message

        Returns void

      sendToAllClients

      • sendToAllClients(name: string, packetData: object): void
      • Sends packet object with specified name to all clients.


        Parameters

        • name: string
        • packetData: object

        Returns void

      sendToServer

      • sendToServer(name: string, packetData: object): void
      • Sends packet object with the specified name from client to server.


        Parameters

        • name: string
        • packetData: object

        Returns void

      serverToLocalId

      • serverToLocalId(id: string | number): number
      • Converts item or block ID from server to local value.


        Parameters

        • id: string | number

        Returns number