Example package: hello

hello is the smallest useful package. It has a server part and a client part and shows how they talk to each other. It does four things:

The example is the folder examples/hello of the server sources. Its layout matches the server folder you run, so you copy it over:

hello/
      node/packages/hello/index.js          server part
      client_packages/index.js              the entry of the client scripts: loads ./hello
      client_packages/hello/index.js        client part
      client_packages/hello/ui/hello.html   the page that shows the greeting on the screen

Install

  1. Stop the server if it is running.
  2. Copy the contents of the hello folder into your server folder:
    • Windows archive: copy node\packages\hello into the archive's node\packages folder, and client_packages into the archive's client_packages folder (merge the folders; if you already have a client_packages\index.js, add the line require('./hello'); to it instead of replacing the file).
    • Linux container: copy node/packages/hello into the packages folder and client_packages into the client_packages folder next to compose.yml.
  3. Start the server (see Server configuration). The log shows loading package hello, then [hello] loaded.

The resources.watch setting rebuilds the client files by itself when they change, but a server script is read only at start: restart the server after you change node/packages/hello/index.js.

Run

  1. In the launcher use "Connect by address" and enter your server's address (127.0.0.1:31130 on the same computer).
  2. When you are in the game, the greeting Hello, <your name>! appears at the top of the screen for a few seconds.
  3. Press H: the greeting appears again. The server log shows [hello] greeted <name>.
  4. Press T, type /hello and press Enter: the same handler runs, the greeting appears on the screen and a Hello, <your name>! line appears in the chat. The built-in chat sends a line that starts with / as a command. See Events.

The marker and the blip are created on the server once, five metres from the first player who becomes ready (the server waits for that player's first real position, at most 10 seconds). The marker is streamed to players who come within the server's streamingRange; the blip is sent to every player.

How it works

Each step above was checked in the game: the greeting when the client is ready, the H key, the /hello command, the page loading from package://hello/ui/hello.html, the marker next to the player and the blip. For how the game shows each kind of marker and blip, see the member in the API reference.

Change the files, restart the server, join again, and players receive the changed client files.

A game mode: freeroam

freeroam is a small but complete game mode to start your own from. It is server-only: the player sees it through the built-in chat and the map, so there is nothing to put into client_packages.

It is the folder examples/freeroam; copy its node/packages/freeroam into your server's node/packages (the Windows archive) or packages (the Linux container) and restart the server. Its README.md lists every command and setting. The vehicle names in its config.json are GTA VI vehicles; add a name only after you have seen it appear in the game.