AddEventHandler: Difference between revisions

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search
Automatyczna aktualizacja dokumentacji funkcji
 
Complete Lua function catalog
Line 37: Line 37:
* Available in both client-side and server-side resource scripts.
* Available in both client-side and server-side resource scripts.


[[Category:Lua Functions]]
[[Category:Shared Functions]]
[[Category:Shared Functions]]
[[Category:Event Functions]]
[[Category:Event Functions]]

Revision as of 09:52, 15 August 2026

addEventHandler

Attaches a Lua callback to a named event in the current resource.

Syntax

bool addEventHandler(string eventName, element attachedTo, function handler)

Parameters

Name Type Required Description
eventName string yes The event to listen for.
attachedTo element yes The attachment target. Use root for a global resource handler.
handler function yes The callback invoked when the event is triggered.

Returns

Returns true when the handler is registered; otherwise returns false.

Examples

Handle a custom event:

addEvent("quest:updated")

local function onQuestUpdated(questId)
    print("Quest updated:", questId)
end

addEventHandler("quest:updated", root, onQuestUpdated)

Notes

  • Available in both client-side and server-side resource scripts.