IMIsle Modkit
Pages in this area

Creating a resource

A resource is a folder under resources\ with a manifest.lua. It can hold server scripts, client scripts and files for UI pages or textures.

The quick way

Type this in the runner console.

new resource myresource

The runner creates resources\myresource\ with manifest.lua, server.lua, client.lua and ui\index.html, and adds load myresource to server.cfg. Type restart to load it.

manifest.lua

name "myresource"
author "you"
description "what it does"
version "1.0"

server "server.lua"
client "client.lua"
files { "ui/*", "textures/*" }

The manifest is a Lua file, but it runs in an empty Lua state without any libraries. Only these declarations exist.

Declaration Meaning
server "file.lua" Script that runs in the game server. Also servers { ... } and server_scripts { ... }.
client "file.lua" Script that runs in the player's game. Also clients { ... } and client_scripts { ... }.
files { ... } Files that are sent to the client, for example HTML, CSS, JS, PNG.
nui "ui/index.html" Same effect as one files entry. The page is delivered, nothing opens by itself. Open it with modkit.browser.add.
name, author, description, version Accepted and ignored. The resource name is the folder name.

Each declaration takes one string or a table of strings. You can repeat a declaration. Scripts run in the order you list them.

Wildcards work for the last path part, for example "ui/*" or "*.lua". They do not descend into sub folders. "ui/*" does not include ui\img\logo.png. List "ui/img/*" as well.

manifest.lua itself is always sent to the client.

Server scripts

modkit.events.add("playerSpawned", function(player)
  player:message("Welcome " .. player.name .. ", you are a " .. player.species)
end)

modkit.commands.add("hello", function(player, ...)
  player:message("hello " .. player.name .. " " .. table.concat({ ... }, " "))
end)

Every resource has its own Lua state. Globals of one resource are not visible in another. All server scripts of one resource share one state, so skins.lua can define a global table that server.lua reads.

Server scripts have the full Lua 5.4 standard library.

Client scripts

modkit.events.add("onClientReady", function()
  print("myresource client loaded")
  modkit.events.callRemote("ping", 1)
end)

modkit.events.add("pong", function(value)
  print("server answered " .. tostring(value))
end)

Client scripts run with a reduced standard library. io, package, require, debug, load, loadfile, dofile and the file and process functions of os are missing. See core.

UI pages

Put the page under ui\, list it in files, and open it from a client script.

local ui = modkit.browser.add("ui/index.html")

The NUI guide shows how the page and the script talk to each other.

Enable it

Add a line to server.cfg and restart the game server.

load myresource

The server plugin logs one line per resource to server-plugin.log.

resource 'myresource' loaded (1 server scripts, 3 client files)

A Lua error in a script is logged with the resource name in front. The other scripts keep running.