shared
AddEventHandler
FiveM shared native documentation with a Lua example.
Summary
Attaches a handler to an event. For LOCAL events (like onResourceStart) use it alone; for NETWORKED events you must also RegisterNetEvent.
Returns
handler reference
Parameters
eventNamestringThe event to listen for.handlerfunctionThe callback.Example
AddEventHandler('onResourceStart', function(resource)
if resource == GetCurrentResourceName() then
print('my resource started')
end
end)Common pitfalls
- For events triggered over the network (client↔server), AddEventHandler alone won't fire — you also need RegisterNetEvent.
- onResourceStart fires for EVERY resource — always check it's yours with GetCurrentResourceName().
Related natives
Related guides
FiveM scripts done right
Optimized, dual-framework scripts for QBCore and ESX from Viper Development — escrow protected, delivered instantly to your Cfx portal.
Browse Scripts →