Skip to content
GAMPEONCreate
New project
Preview: this works today, but details can still change.

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.

fxmanifest.lua
fx_version 'cerulean'
shared_script 'config.lua'
server_script 'server.lua'
client_script 'client.lua'
files { 'html/index.html', 'data/*.json' }

For every started resource the server builds a package from:

  • client_script and client_scripts
  • shared_script and shared_scripts
  • files
  • 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.

  1. The player joins and passes the join check.
  2. The server sends the list of packages and the replicated convars (setr).
  3. The game downloads missing files and starts the resources in the same order as the server.
  4. Network events that the server sent before the start are delivered right after it. An event from playerJoining therefore still reaches the client script.
server.lua
AddEventHandler('playerJoining', function()
TriggerClientEvent('myres:welcome', source, GetPlayerName(source))
end)
client.lua
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 myres on the server restarts the resource on every connected client too, also when no file changed. Changed files download first.
  • stop myres stops it on all clients.
  • Resources that depend on a restarted resource restart with it, on the server and on clients.

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.

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.

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.

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.

Report a problem with this pageOther ways to give feedback