Functions
Opening web pages of the server's ui folder over the game, checking support, the screen size in CSS pixels.
Web pages (HTML, CSS, JavaScript - plain or built with any framework) drawn over the game by Chromium (CEF). Start with the Web UI guide; a page is a Browser, its JavaScript side is window.gmp. To let the player click and type, show the cursor.
Web UI (CEF)
Web pages (HTML, CSS, JavaScript - plain or built with React, Vue, Angular, Svelte...) drawn over the game by Chromium. The pages are files of the server's ui folder; the players download them on joining. A page and the script talk through window.gmp in the page and the Browser object in Lua. The whole picture with examples is in the guide.
createBrowser
createBrowser(path, x, y, width, height)Opens a page of the server's ui folder in a new browser drawn over the game. Position and size are
in CSS pixels of a 1920x1080 screen (the page looks the same at every resolution - on a 4K screen it is
rendered twice as sharp); getScreenSize gives the whole screen. The page's background is transparent
unless the page paints one. The browser shows at once; the page is ready when it says so
(gmp.trigger("ready") in its JavaScript).
local w, h = getScreenSize()
local hud = createBrowser("hud/index.html", 0, 0, w, h) -- the whole screen
local shop = createBrowser("shop/index.html", 560, 240, 800, 600) -- a window in the middle| Parameter | Type | Description |
|---|---|---|
path | string | Path of the page file in the server's ui folder, e.g. "login/index.html". |
x | integer | Left edge, CSS px. |
y | integer | Top edge, CSS px. |
width | integer | Width, CSS px (1-8192). |
height | integer | Height, CSS px (1-8192). |
Returns: Browser | nil - nil when this player's game cannot show web pages (see isBrowserSupported).
isBrowserSupported
isBrowserSupported()Whether this player's game can show web pages - the launcher downloads the Chromium component once;
without it createBrowser returns nil. A script can then fall back to e.g. chat commands.
Returns: boolean
getScreenSize
getScreenSize()Size of the whole screen in CSS pixels - the space for createBrowser. It is 1080 high from 1080p up
(1920x1080 on 16:9 screens, 2560x1080 on 21:9), the real resolution below 1080p.
Returns:
| Value | Type | Description |
|---|---|---|
width | integer | |
height | integer |
