Quick navigation

Go to

Lua API reference

API set
1,763 functions

Core & resources408

Players & characters269

Cyberware & abilities57

Vehicles209

World & environment152

NPCs, weapons & loot150

Interfaces & markers118

Camera & input78

Voice & effects77

Network & sessions72

Data & utilities173

1,763 functions Β· Open77 wiki Β· Lua 5.4

Core & resourcesclient

Global function

AddEventHandler

Listens for a local event.

Lua signature
-- client Β· _G
AddEventHandler(
    event, -- string
    handler -- function
)

Description

Registers a callback on the current resource's local event bus. The handler is owned by the current resource generation and is discarded automatically when that generation stops or reloads; it never receives network traffic unless the event was separately registered as a network event.

Parameters 2

eventstring
Required
handlerfunction
Required

Returns

  • handler id

Example

example.lua
-- Run setup when this resource starts on the client
AddEventHandler("onClientResourceStart", function(name)
    if name ~= GetCurrentResourceName() then return end
    Open77.hud.notify("Welcome to the city")
end)
Source information

ResourceHost.cpp:24468
LuaAddEventHandler

// Guides Β· Lua API

Search the docs

1,905 guides and functions indexed

Try