scripting Module
The scripting
module provides APIs for interacting with the server-side
scripting engine. Primarily this takes the form of registering callbacks
with which the scripting engine will invoke a script under certain
conditions (e.g. a specific event is received).
Callback Registration Functions
AddEventCallback(eventId, callback)
Definition
- scripting.AddEventCallback(eventId, callback)
Registers a callback to handle the given type of event.
- Parameters:
eventId (
integer
) – Event ID that this callback should respond to.callback (
function
) – Callback function. The function must accept a single argument having the event details type, or zero arguments for event types without details.
Example
Registering an event callback using `scripting.AddEventCallback(eventId, callback).
function on_player_entered(event)
local playerEntityId = event.EntityId
util.LogInfo(string.format("Player ID %s has logged in.", playerEntityId))
end
scripting.AddEventCallback(events.Server_Persistence_PlayerEnteredWorld, on_player_entered)