Skip to content

Events

loadbuffer

Called when Lua code is about to be loaded and executed. Can be used to modify, block, or replace the code before execution.

Parameters

  • name: string - Name/identifier of the chunk being loaded
  • content: string - The Lua code content to be executed
  • mode: string - Load mode ('t' for text, 'b' for binary, 'bt' for both)

Returns

  • boolean | string | nil - Return true to block execution, return a string to replace the code, or return nil to allow normal execution

Example

Autorun.on("loadbuffer", function(name, content, mode)
-- Your event handler code here
end)

You can create and trigger your own custom events using Autorun.trigger().

-- Trigger a custom event
Autorun.trigger("myCustomEvent", arg1, arg2, arg3)
-- Listen to the custom event
Autorun.on("myCustomEvent", function(arg1, arg2, arg3)
Autorun.print("Custom event triggered!", arg1, arg2, arg3)
end)

Remote events can be created that will be sent to the opposite realm (client <-> menu).

Listen to them with Autorun.onRemote(eventName, callback) and trigger them with Autorun.triggerRemote(eventName, value).

Note that, unlike traditional events, since this runs across states, you cannot send state-sensitive values, ie functions, userdata, etc.

The current supported types are:

  • nil
  • boolean
  • number
  • string

In the future basic tables will be supported.

-- Send a message to the menu when client initializes
Autorun.triggerRemote("clientGreeting", "hi")
-- Optional: Listen for responses from menu
Autorun.onRemote("menuResponse", function(message)
print("Menu says: " .. message)
end)