Client scripts
Client scripts run in every player’s game. The server sends them when a player joins, so players never install anything by hand. This works like FiveM: list the files in fxmanifest.lua, and GAMPEON does the rest.
fx_version 'cerulean'
shared_script 'config.lua'server_script 'server.lua'client_script 'client.lua'files { 'html/index.html', 'data/*.json' }What players get
Section titled “What players get”For every started resource the server builds a package from:
client_scriptandclient_scriptsshared_scriptandshared_scriptsfiles- the manifest itself
Server scripts never leave the server, even if they are in the same folder.
When a player joins, the game downloads only the files it does not have yet. Files are stored by their SHA-256 hash under %LOCALAPPDATA%/GAMPEON/cache, so joining again after a small change only downloads the changed files. The game checks every file against its hash before it uses it.
When client scripts start
Section titled “When client scripts start”- The player joins and passes the join check.
- The server sends the list of packages and the replicated convars (
setr). - The game downloads missing files and starts the resources in the same order as the server.
- Network events that the server sent before the start are delivered right after it. An event from
playerJoiningtherefore still reaches the client script.
AddEventHandler('playerJoining', function() TriggerClientEvent('myres:welcome', source, GetPlayerName(source))end)RegisterNetEvent('myres:welcome', function(name) print('welcome ' .. name) TriggerServerEvent('myres:ready', GetPlayerServerId(PlayerId()))end)In client scripts, source of a network event is 65535 (the server), like in FiveM.
Restart and stop
Section titled “Restart and stop”restart myreson the server restarts the resource on every connected client too, also when no file changed. Changed files download first.stop myresstops it on all clients.- Resources that depend on a restarted resource restart with it, on the server and on clients.
What client scripts can do
Section titled “What client scripts can do”Client scripts have the same Lua runtime as server scripts, with a stricter sandbox: no PerformHttpRequest, no MySQL, no SaveResourceFile, and convars are read-only. See Sandbox and limits.
| Function | What it does |
|---|---|
TriggerServerEvent(name, ...) |
Sends a network event to server scripts, at most 60000 bytes |
RegisterNetEvent(name, handler) |
Receives events from TriggerClientEvent |
GetConvar(name, default) |
Reads convars the server set with setr |
PlayerId(), GetPlayerServerId(PlayerId()) |
Your own player and its server ID |
GetPlayerName(PlayerId()) |
Your own display name |
RegisterCommand(name, handler) |
A command players can run in chat with /name or in the game console with gpc <command> |
LoadResourceFile(resource, file) |
Reads files from files { } of a running resource |
PlayerPedId(), GetPlayerPed(-1) |
Your own character |
GetEntityCoords(ped), GetEntityHeading(ped), GetEntityForwardVector(ped), GetEntityVelocity(ped) |
Where your character is, in meters and degrees |
TriggerEvent('chat:addMessage', { args = { 'Me', 'hi' } }) |
Writes a line into your own chat. See Text chat |
ExecuteCommand(line) |
Runs a client command; unknown commands go to the server and run there with your permissions |
Client scripts can read the world but not move anything: SetEntityCoords is for server scripts. Other players’ characters, vehicles and objects come in a later step. See World and entities and Platform status.
Which servers may send client scripts
Section titled “Which servers may send client scripts”The client sandbox has not had its security review yet. Until it has, the game only runs client scripts from servers it trusts:
- servers on your own computer (
localhost, for testing) - GAMPEON test servers listed in the game build
- any server if you start the game with
-gpclientscripts
On other servers the game skips client scripts and you play without them. The server log then shows client scripts blocked by the player's game.
Download speed
Section titled “Download speed”Files travel through the game connection at up to half of the connection’s bandwidth, about 50 KB/s per player, so movement stays smooth. Small resources start within a second or two. Large frameworks with many megabytes of client files take longer. A separate HTTP download like in FiveM is planned for that.
Test without the game
Section titled “Test without the game”gampeon-server can run client scripts too. gp_fakeplayer client <name> joins with a client inside the same process, which downloads the packages and runs the client scripts. Their output is marked [client <id>/<resource>]. See Test without the game.