Notify System
This documentation explains how the notifications script works for FiveM. The script sends messages from Lua to the NUI (using SendReactMessage) and displays custom notifications in the UI. In this version, only the required parameters are implemented: title, description, and type. An optional duration parameter is also available.
Introduction
The NUI Notifications Script was developed for FiveM to facilitate communication between the client-side (Lua) and the user interface (NUI). It sends notifications via the SendReactMessage
function. This script requires three parametersβtitle, description, and typeβto display a notification. If any required field is missing, an error message is printed in the console.
Features
Notification Delivery: Sends custom notifications to the UI with the action
triggerNotification
.Simple Validation: Checks for the required parameters (
title
,description
, andtype
). If any are missing, an error is logged.Test Command: A
/notifytest
command is provided to send sample notifications for testing purposes.
Installation and Configuration
FiveM Environment: Ensure your FiveM server is properly configured and that the resource containing this script is included in your
server.cfg
.Script Integration: Place the script in a FiveM resource and start it along with your other resources.
Usage
Export notify
The script exports a function notify
so other resources can send notifications to the UI. For example:
Test Command /notifytest
To test the notification system, use the /notifytest
command. This command sends three notifications to the UI, demonstrating the three basic types:
Success Notification
Error Notification
Info Notification
Required Parameters
The script accepts the following parameters:
title Type:
string
Description: The title of the notification.description Type:
string
Description: A detailed description for the notification.type Type:
string
Allowed values:"success"
,"error"
,"info"
Description: Determines the style and the default icon of the notification.
Note: If any of these required fields are not provided, the script will print an error in the console indicating which field(s) are missing.
An optional parameter is also available:
duration Type:
number
Description: The duration (in milliseconds) that the notification remains visible. Default is5000
.
Conclusion
This script provides a simple and effective way to send notifications to the NUI in FiveM, relying on just the essential parameters: title, description, and type (with an optional duration). It ensures that notifications are displayed correctly and that any missing required fields are reported via console errors.
Last updated
Was this helpful?