- Documentation
- Resources and meta.xml
Guide
Resources and meta.xml
Everything about meta.xml: server, client and shared scripts, files for players, exports and download order.
Full example
<meta>
<info author="You" name="My mode" version="1.0" type="gamemode" />
<script src="server.lua" type="server" />
<script src="client.lua" type="client" />
<script src="shared.lua" type="shared" />
<script src="secret.lua" type="client" cache="false" />
<file src="logo.png" />
<file src="music.mp3" download="false" />
<download_priority_group>10</download_priority_group>
<export function="giveReward" type="server" />
</meta>
info
Describes the resource. The type attribute is script (default) or gamemode. Game modes start last, once other resources are ready.
script
| Attribute | Meaning |
|---|---|
src | path to a .lua file in the resource folder |
type="server" | the script runs only on the server and never leaves it |
type="client" | the script is sent to the player and runs in their game |
type="shared" | the same file runs on both sides |
cache="false" | the client script is not saved on the player's disk, only downloaded on every join |
Shared scripts are handy for constant data and helper functions, such as a price table or a vehicle list. Each side runs them independently: changing a variable on the server does not change it for the player.
file
A file sent to the player: an image, sound, font or data. The player downloads it on join, and on later joins only if the file changed.
With download="false" the file is not downloaded on start. The client script fetches it when needed with downloadFile("music.mp3") and gets the result in the onClientFileDownloadComplete event.
Patterns in src
In the src of script, file and map tags you can write a pattern instead of a single name:
| Pattern | Matches |
|---|---|
* | any characters in a name, without going into subfolders (*.lua) |
** | any characters including subfolders (images/**) |
? | one character (sounds/s?.mp3) |
<meta>
<script src="shared/**/*.lua" type="shared" />
<script src="client/*.lua" type="client" />
<file src="images/**" />
</meta>
Files from one pattern are loaded in alphabetical order. A pattern in file skips files declared as script (server code never reaches players), meta.xml and hidden folders (.git etc.). A pattern that matches no file prints a warning in the server console, and the resource starts normally.
download_priority_group
Download order when a player joins. A higher number is downloaded earlier, the default is 0, negative values come last. Useful when a login screen should appear before heavy files from other resources arrive.
export
Makes a function available to other resources. You call it through exports:
-- meta.xml of the "rewards" resource: <export function="giveReward" type="server" />
function giveReward(player, amount)
givePlayerMoney(player, amount)
return true
end
exports.rewards:giveReward(player, 500)
Inside an exported function sourceResource is the resource that called it, and sourceResourceRoot its root. This lets a resource with exports clean up after resources that stopped (e.g. close their panels in onResourceStop with source == sourceResourceRoot):
local calls = {}
function giveReward(player, amount)
calls[sourceResource] = (calls[sourceResource] or 0) + 1
givePlayerMoney(player, amount)
return true
end
include
<include resource="name" /> = this resource needs another one. On start the server first starts the resources from <include> (including ones in disabled_resources), and when one of them is missing from resources/, the resource does not start and the console shows an error. A dependency loop (A needs B, B needs A) also stops the start.
<meta>
<include resource="trilogy_core" />
<script src="server.lua" type="server" />
</meta>
Which resources start and in what order
- Every folder with a
meta.xmlinresources/(also inside group subfolders) starts with the server. - Order: alphabetical by name, with
<info type="gamemode">resources last. Dependencies from<include>start before the resource that needs them. - To disable one without deleting the folder:
"disabled_resources": ["name"]inserver-config.json. You can still start it withstart nameor as another resource's dependency. - A new folder added while the server runs:
start namein the console, or from a scriptrefreshResources()andstartResource(getResourceFromName("name")).
Limits and console
A single file can be up to 64 MB, a whole resource up to 256 MB. Everything a resource creates (vehicles, objects, windows, timers) disappears when it stops.
| Command | What it does |
|---|---|
start <resource> | starts the resource |
stop <resource> | stops the resource and removes everything it created |
restart <resource> | stops and starts it again, also for players |