sm.event
The event library is used to trigger Lua events across different script class instances.
Most built-in script class callbacks (see the Script Class Types documentation) are blacklisted.
As such, methods such as server_onFixedUpdate and similar ones cannot be called using this library.
Functions
sendToCharacter
local found = sm.event.sendToCharacter(character, callback, data)
Sends an event to the specified Character's script class instance.
The callback function is executed in the next Lua tick.
Parameters:
character(Character): The character.callback(string): The name of the callback function in the character script.data(any, optional): Extra data to send to the callback function.
Returns:
found(boolean): Whether the callback function was found or not.
sendToGame
local found = sm.event.sendToGame(callback, data)
Sends an event to the game script class instance.
The callback function is executed in the next Lua tick.
If this function is used too early in the game's loading process (such as from the root of an AutoTool script), the game script does not exist yet, causing a game crash.
Parameters:
callback(string): The name of the callback function in the game script.data(any, optional): Extra data to send to the callback function.
Returns:
found(boolean): Whether the callback function was found or not.
sendToHarvestable
local found = sm.event.sendToHarvestable(harvestable, callback, data)
Sends an event to the specified Harvestable's script class instance.
The callback function is executed in the next Lua tick.
Parameters:
harvestable(Harvestable): The harvestable.callback(string): The name of the callback function in the harvestable script.data(any, optional): Extra data to send to the callback function.
Returns:
found(boolean): Whether the callback function was found or not.
sendToInteractable
local found = sm.event.sendToInteractable(interactable, callback, data)
Sends an event to the specified Interactable's script class instance.
The callback function is executed in the next Lua tick.
Parameters:
interactable(Interactable): The interactable.callback(string): The name of the callback function in the interactable script.data(any, optional): Extra data to send to the callback function.
Returns:
found(boolean): Whether the callback function was found or not.
sendToPlayer
local found = sm.event.sendToPlayer(player, callback, data)
Sends an event to the specified Player's script class instance.
The callback function is executed in the next Lua tick.
Parameters:
player(Player): The player.callback(string): The name of the callback function in the player script.data(any, optional): Extra data to send to the callback function.
Returns:
found(boolean): Whether the callback function was found or not.
sendToScriptableObject
local found = sm.event.sendToScriptableObject(scriptableObject, callback, data)
Sends an event to the specified ScriptableObject's script class instance.
The callback function is executed in the next Lua tick.
Parameters:
scriptableObject(ScriptableObject): The scriptable object.callback(string): The name of the callback function in the scriptableObject's script.data(any, optional): Extra data to send to the callback function.
Returns:
found(boolean): Whether the callback function was found or not.
sendToTool
local found = sm.event.sendToTool(tool, callback, data)
Sends an event to the specified Tool's script class instance.
The callback function is executed in the next Lua tick.
Parameters:
tool(Tool): The tool.callback(string): The name of the callback function in the tool script.data(any, optional): Extra data to send to the callback function.
Returns:
found(boolean): Whether the callback function was found or not.
sendToUnit
local found = sm.event.sendToUnit(unit, callback, data)
Sends an event to the specified Unit's script class instance.
The callback function is executed in the next Lua tick.
Parameters:
unit(Unit): The unit.callback(string): The name of the callback function in the unit script.data(any, optional): Extra data to send to the callback function.
Returns:
found(boolean): Whether the callback function was found or not.
sendToWorld
local found = sm.event.sendToWorld(world, callback, data)
Sends an event to the specified World's script class instance.
The callback function is executed in the next Lua tick.
Parameters:
world(World): The world.callback(string): The name of the callback function in the world script.data(any, optional): Extra data to send to the callback function.
Returns:
found(boolean): Whether the callback function was found or not.