Event (type)

From FiguraMC
Not to be confused with Events.

The event type is used for events such as events.TICK. To create an event function, use one of the following.

 local tick = 0
function events.WORLD_TICK()
  tick = tick + 1
end
-- OR
local tick = 0
events.WORLD_TICK:register(function()
  tick = tick + 1
end, "TICK_COUNTER")

Methods

Method Description
remove Takes in a string with the name of the event, and removes it, stopping it from being called
clear Clears the event of all methods
register Takes in a function to run when the event is fired, with an optional name argument (string)
getRegisteredCount Returns the amount of functions registered, with an optional name argument (string)

remove


Removes a function from an event, returning how many were removed

Overloads:

Arguments Return
name: string integer
function: function integer
local tick = 0
function tickThing()
  tick = tick + 1
  print("tick " .. tick)
  if tick > 5 then
    events.TICK:remove("thing:)
  end
end
events.TICK:register(tickThing, "tickThing")

clear


Similar to remove, but removes every event

Overloads:

Arguments Return
none nil
-- Example function to clear all events
function clearEvents()
  for _, v in pairs(events:getEvents()) do
    v:clear()
  end
end

register

Registers a function to an event

Overloads:

Arguments Return
func: function, name: string Event
func: function Event
local fps = 0
events.RENDER:register(function()
  fps = client.getFPS()
end)

getRegisteredCount

Gets the number of registered functions in an event, optionally filtering by name

Overloads:

Arguments Return
name: Integer Event
none Integer
local fps = 0
events.RENDER:register(function()
  fps = client.getFPS()
end)