NOTIFICATION
Notification System Setup This section outlines the setup of a notification system using a custom event and a command in a FiveM server. The notification system allows for different types of alerts to
RegisterNetEvent('es:showNotification', function(message, title, type, length, icon)
AddNotify(message, title, type, length, icon)
end)
Parameters:
message
: The content of the notification, which will be shown to the player.title
: The title of the notification, typically summarizing the type of alert.type
: The notification type, which determines the visual style (e.g., "info", "error", "warning", "announce", "purple").length
: The duration (in milliseconds) for which the notification will be displayed.icon
: The icon associated with the notification, either as an image file or a Font Awesome icon class.
Usage
You can trigger this event from anywhere within the server code using:
TriggerEvent('es:showNotification', "This is your message", "Notification Title", "info", 5000, "fas fa-info-circle")
This will display a notification with the specified message, title, type, and icon for 5 seconds.
2. Command Registration: notify
A command named notify
is registered, which triggers a series of notifications with predefined messages. This is useful for testing or broadcasting specific notifications to the player.
Command Definition
RegisterCommand("notify", function(source, args)
AddNotify("Your phone has received a new message. Check it for important details and updates.", "PHONE NOTIFICATION", "info", 5000, "phone.png")
Wait(1000)
AddNotify("An error occurred. Please review the details to avoid potential issues.", "ERROR NOTIFICATION", "error", 5000, "fas fa-info-circle")
Wait(1000)
AddNotify("Caution! A potential issue has been detected. Immediate attention is required.", "WARNING NOTIFICATION", "warning", 5000, "fas fa-info-circle")
Wait(1000)
AddNotify("Important announcement for all players. Please read the following information carefully.", "ANNOUNCEMENT NOTIFICATION", "announce", 5000, "announce.png")
Wait(1000)
AddNotify("A special chat message has been sent to you containing unique information.", "CHAT NOTIFICATION", "purple", 5000, "chat.png")
AddNotify("Your phone has received a new message. Check it for important details and updates.", "PHONE NOTIFICATION", "info", 5000, "phone.png")
Wait(1000)
AddNotify("An error occurred. Please review the details to avoid potential issues.", "ERROR NOTIFICATION", "error", 5000, "fas fa-info-circle")
Wait(1000)
AddNotify("Caution! A potential issue has been detected. Immediate attention is required.", "WARNING NOTIFICATION", "warning", 5000, "fas fa-info-circle")
Wait(1000)
AddNotify("Important announcement for all players. Please read the following information carefully.", "ANNOUNCEMENT NOTIFICATION", "announce", 5000, "announce.png")
Wait(1000)
AddNotify("A special chat message has been sent to you containing unique information.", "CHAT NOTIFICATION", "purple", 5000, "chat.png")
end, false)
Usage:
Players can trigger this command by typing
/notify
in the chat.The command will sequentially display several predefined notifications with 1-second intervals between them.
Example Notifications
Phone Notification: Message: "Your phone has received a new message. Check it for important details and updates." Title: "PHONE NOTIFICATION" Type: "info" Icon: "phone.png"
Error Notification: Message: "An error occurred. Please review the details to avoid potential issues." Title: "ERROR NOTIFICATION" Type: "error" Icon: "fas fa-info-circle"
Warning Notification: Message: "Caution! A potential issue has been detected. Immediate attention is required." Title: "WARNING NOTIFICATION" Type: "warning" Icon: "fas fa-info-circle"
Announcement Notification: Message: "Important announcement for all players. Please read the following information carefully." Title: "ANNOUNCEMENT NOTIFICATION" Type: "announce" Icon: "announce.png"
Chat Notification: Message: "A special chat message has been sent to you containing unique information." Title: "CHAT NOTIFICATION" Type: "purple" Icon: "chat.png"
Conclusion
This setup provides a flexible way to trigger and manage notifications within the FiveM server, using either custom events or a simple command. The notifications can be easily customized to fit various scenarios, improving communication with players.
Last updated