Skip to main content

Resource

A resource is a collection of script files that enables interaction with the game. It can be started and stopped at any time during server operation.

Structure

The structure is represented by a folder within the resources directory in the server files, accompanied by a meta file (meta.xml). The meta file specifies the essential details about the resource. Inside this folder, you should organize all resource files as outlined in the meta file. The internal structure of the folder is flexible, allowing you to arrange files in a way that makes sense to you.

Server Folder
HappinessMP.Server.exe
resources/
├── my-resource-01/
│ ├── bank/
│ │ ├── cl_bank.lua
│ │ └── sv_bank.lua
│ ├── client.lua
│ ├── server.lua
│ └── meta.xml
├── my-resource-02/
│ ├── meta.xml
│ └── ...
addons/
settings.xml

Category Folders

Resources may be grouped into subfolders of any depth. The path below resources/ then becomes part of the resource's name, and that full name is what you use everywhere: in settings.xml, in the server console, and in every script function that takes a resource name.

Server Folder
resources/
└── gamemodes/
└── freeroam/
└── meta.xml
settings.xml
<resource>gamemodes/freeroam</resource>
Resource.GetState("gamemodes/freeroam")

Meta File

The meta file is the configuration file of a resource. It defines which files are loaded and how they should be handled.

meta.xml
<meta type="lua">
<script type="client" src="cl_main.lua" />
<script type="server" src="sv_main.lua" />

<export type="client" function="myClientFunc" />
<export type="server" function="myServerFunc" />

<file src="UI/test.html" />
<file src="UI/script.js" />
</meta>
tip

Both <script> and <file> support glob patterns such as *, **, and ?.
This allows you to include multiple files or entire directories without listing each file individually.

  • The <meta> element is used to specify the scripting language of the resource (lua / squirrel). The attribute is required.
  • Use <script> elements to specify the scripts to be loaded and define them as client / server or shared script. Both src and type are required.
    • Client scripts are stored encrypted in the server cache and are downloaded and executed by each connecting player.
    • Server scripts are executed exclusively by the server.
    • Shared scripts do both.
    • The file extension has to match the resource type: .lua for type="lua", .nut or .sq for type="squirrel".
  • Use <export> elements to export functions from this resource, so other resources can use them. function and type (client / server / shared) are required. See Exports.
  • With <file> elements, you can define files that are to be downloaded by the client in their raw version and are required at a later time. This is necessary for WebUIs, for example.
info

A resource that fails to load never starts silently. The reason (a missing src, a missing type, a script with the wrong extension) is written to the server log.