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

Built-in events

A resource has started. Fired for every resource, including your own. Server and client.

Argument Type Description
resourceName string Name of the resource that started.
AddEventHandler('onResourceStart', function(name)
if name == GetCurrentResourceName() then
print('ready')
end
end)

A resource is stopping. Save data here. Server and client.

Argument Type Description
resourceName string Name of the resource that stops.
AddEventHandler('onResourceStop', function(name)
if name == GetCurrentResourceName() then
-- save state
end
end)

A player joined and was verified. source is the new player ID. Server only.

Argument Type Description
oldId string Player ID as string (same as source).
AddEventHandler('playerJoining', function()
print(GetPlayerName(source) .. ' joined')
end)

A player left. source is the player ID; GetPlayerName and GetPlayerIdentifiers still work inside the handler. Server only.

Argument Type Description
reason string Why the player left.
AddEventHandler('playerDropped', function(reason)
print(GetPlayerName(source) .. ' left: ' .. reason)
end)

The player pressed Enter in the chat window of the game. The built-in chat resource handles it. Client only.

Argument Type Description
text string What the player typed, at most 512 bytes, without control characters. Starts with / for commands.
AddEventHandler('gampeon:chatInput', function(text)
print('typed: ' .. text)
end)

The player held Escape for 2 seconds and took mouse and keyboard back from a web interface. The page stays visible, so close your menu here. Client only.

Argument Type Description
resourceName string Resource whose page had the focus.
AddEventHandler('gampeon:nuiFocusReleased', function(name)
if name == GetCurrentResourceName() then
SendNUIMessage({ action = 'close' })
end
end)

A player wants to dig a block. source is the player. Call CancelEvent to keep the block, before any Wait. Server only.

Argument Type Description
x integer Block x.
y integer Block y.
z integer Block z.
block string The block that would be removed.
AddEventHandler('blockBreak', function(x, y, z, block)
if block == 'crystal' and not HasPickaxe(source) then
CancelEvent()
return
end
AddItem(source, block, 1)
end)

A player wants to place a block. source is the player. Call CancelEvent to refuse, before any Wait. Server only.

Argument Type Description
x integer Block x.
y integer Block y.
z integer Block z.
block string The block from the selected hotbar slot.
AddEventHandler('blockPlace', function(x, y, z, block)
if not TakeItem(source, block, 1) then
CancelEvent()
end
end)

A block changed, by a player or by SetBlock. Arrives right after the change, in the next server tick. Server only.

Argument Type Description
x integer Block x.
y integer Block y.
z integer Block z.
oldBlock string Block before.
newBlock string Block now.
player integer Player ID, 0 for scripts.
AddEventHandler('blockChanged', function(x, y, z, old, new, player)
print(('%s: %s -> %s at %d %d %d'):format(player, old, new, x, y, z))
end)

The player picked another slot of the hotbar. Client only.

Argument Type Description
slot integer Slot from 1, 0 when the hotbar is empty.
block `string nil`
AddEventHandler('blockHotbarSelect', function(slot, block)
SendNUIMessage({ type = 'slot', slot = slot })
end)

Report a problem with this pageOther ways to give feedback