Resources and packages

A SixL game mode is made of packages: folders of JavaScript. There are two kinds. Server packages run on the server. Client packages run on every player's computer; the server gives them to players when they join.

Both kinds use the mp object (SixL is the same object) with the server and client API reference that ships with the server (typings in the types folder). Events are listed in Events; a complete small package is in Examples.

Folder layout

<server folder>/
      server.json
      node/
        packages/
          my-mode/
            index.js          a server package
          other-package/
            index.js
      client_packages/
        index.js              the one entry of the client scripts
        my-mode/
          client.js           files that index.js loads
          ui/
            hud.html          pages and other files for players

In the Windows archive the node and client_packages folders are in the archive's root. In the Linux container setup the two folders are packages/ and client_packages/ next to compose.yml. The folder names come from node.scriptsPath (its packages subfolder) and resources.sourceDir in server.json.

Server packages

npm modules in a server package

A server package can use npm modules (a database driver, a validation library and so on). Install them into the package's own folder, so node_modules sits next to its index.js:

node/packages/my-mode/
      index.js
      package.json
      node_modules/

Editor support: the typings

The archive's types folder holds the typings of the API: types/server for server scripts and types/client for client scripts. They give your editor completion, the descriptions of every member and a check of your calls. The server and the client both have a global mp with different members, so each side gets its own project file.

For server packages written in JavaScript, put a jsconfig.json into the node folder:

{
      "compilerOptions": { "target": "ES2022", "module": "commonjs", "checkJs": true, "noEmit": true, "types": [] },
      "include": ["packages/**/*.js", "../types/server/*.d.ts"]
    }

For client scripts, put one into client_packages:

{
      "compilerOptions": { "target": "ES2022", "module": "commonjs", "checkJs": true, "noEmit": true, "types": [] },
      "include": ["**/*.js", "../types/client/**/*.d.ts"]
    }

Open the server folder in Visual Studio Code: a misspelt member is underlined (for example player.outputChatBoxx is reported with a hint to outputChatBox). checkJs turns the check on; leave it out if you want completion only. For TypeScript, tsconfig.example.json at the archive's root is the starting point for server packages (node/packages/**/*.ts); compile to JavaScript before you start the server, which loads index.js files only.

To try a mode, run it on your own server on this computer (see Make your own server) and join it with "Connect by address".

Client packages

How players receive client scripts

  1. The server builds client_packages into its build folder when it starts (resources.buildDir), and again a moment after any file in client_packages changes (resources.watch).
  2. Before the first join, the player's game asks the server for the list of files with their SHA-256 hashes and sizes.
  3. Each player keeps a separate folder of downloaded files for each server. A file that is already there with the same size and hash is not downloaded again. A file that is new or changed (a different hash) is downloaded. A file that is no longer in the list is deleted from the player's folder.
  4. Every downloaded file is checked against its hash, and all files are checked once more before the scripts start. A file that does not match stops the join: nothing runs and the player does not enter the server.
  5. The scripts start only after everything is in place, so a handler registered while the scripts load is always ready before the player is.

What this means for you:

Limits and file names

What a client script can and cannot do

A client script runs in an isolated environment, not in Node.js. What you can use:

What is not there, and what you must not rely on:

Pages opened with mp.browsers.new are web pages in the overlay and have their own rules: they load package:// addresses from your client resources, or https:// addresses from the internet (the owner of such a host then sees the player's IP address); other address schemes do not load.

A player can turn on «Server pages only from the server itself» in the launcher's settings (off by default). Then a page reaches only package:// and your server's own address, the one the player connected to (an IP address if they connected by IP, not a domain name of the same server): any other host fails to load, for the page itself, its frames, images, scripts, fetch, WebSocket and redirects alike, and the page gets the usual load failure. Keep the pages your mode needs in your client resources, or on your server's address, and they work for every player.

Talking between server and client