AddEventHandler from a server-side file in your resource. The event name always follows the pattern zyra:sv_eventName.
An important particularity of server events in FiveM is the global source variable, which is automatically available inside the callback and contains the server ID of the player who originated the event. Always use it to identify and validate the involved player.
other-resource/server.lua
Event reference
zyra:sv_onPlayerConnect
zyra:sv_onPlayerConnect
Fires when a player’s data has been correctly registered on the server by the script. It is the right time to initialize information for that player in your own systems.ParametersExample
The FiveM server ID of the player who connected. Use it to identify the player in all native server calls.
The player’s unique license identifier (for example,
license:a1b2c3d4...). Use it to associate the player with records in your database.other-resource/server.lua
zyra:sv_onPlayerAction
zyra:sv_onPlayerAction
Fires on the server every time a player performs an action tracked by the script. Use it to log actions, validate operations, or apply server-side business logic.ParametersExample
A table with information specific to the action. The content varies depending on the
action value.other-resource/server.lua
zyra:sv_onAdminAction
zyra:sv_onAdminAction
Fires when an administrator executes a privileged command through the script. Ideal for building audit systems or logging sensitive administrative actions.ParametersExample
The name of the executed administrative command (for example,
"kick", "ban", "give_item").The server ID of the player target of the command, if applicable. Will be
nil if the command has no player target.other-resource/server.lua
zyra:sv_onDataSync
zyra:sv_onDataSync
Fires when the script synchronizes a player’s data across the server. You can use this event to keep your own systems updated with the player’s most recent data.ParametersExample
The synchronized data object. Contains the updated player information as managed internally by the script.
other-resource/server.lua
zyra:sv_onResourceStart
zyra:sv_onResourceStart
Fires when the Zyra Store script resource starts correctly. It is the ideal time to initialize database connections, caches, or data structures that your integration needs.ParametersThis event receives no action parameters. In the context of server events without an originating player,
source will have the value 0 (which represents the server itself).Exampleother-resource/server.lua
zyra:sv_onResourceStop
zyra:sv_onResourceStop
Fires when the Zyra Store script resource is about to stop. Take advantage of this event to save pending data, clean up active timers, and release resources correctly.ParametersThis event receives no parameters. Like
zyra:sv_onResourceStart, source will be 0.Exampleother-resource/server.lua
Security in server events
Server events are the core of your application’s logic and must be handled with care. Follow these practices to keep your server secure: Always validatesource. Never blindly trust the player ID you receive. Verify that the player exists and has the necessary permissions before processing any action.
other-resource/server.lua
zyra:sv_onAdminAction event was fired by the script, check that the player indicated in source really has administrator permissions in your systems.
Related resources
- See the Client Events for events emitted in the player environment.
- Review the Server Exports for functions you can call directly from your resource without needing to listen to events.
