Notifications
The notification system provides toast-style notifications with support for multiple types, positions, and animations. Notifications are non-blocking and automatically dismiss after a specified durati

Notifications Module
The Notifications module provides a comprehensive toast-style notification system with support for multiple types, positions, animations, and advanced queue management. Notifications are non-blocking, automatically dismiss after a specified duration, and support both client-side and server-side triggering.
Features
Multiple Notification Types: Success, error, warning, info with distinct styling and icons
Flexible Positioning: 9-position grid system for precise screen placement
Auto-dismiss System: Configurable duration with automatic cleanup and queue management
Queue Management: Multiple notifications with smart positioning and overflow handling
Theme Support: Adapts to dark/light themes with customizable styling
Icon Support: Optional type-specific icons for visual clarity
Server Integration: Server-side functions to notify specific players or all players
State Management: Track active notifications and clear them programmatically
Performance Optimized: Efficient rendering and memory management
Available Functions
notify
Display a notification message with customizable options and styling.
Parameters:
playerId(number, server-side only): Player server ID to send the notification tooptions(table): Notification configuration optionsmessage(string): The notification message texttype(string, optional): Notification type - 'success', 'error', 'warning', 'info' (default: 'info')title(string, optional): Notification title displayed above messageduration(number, optional): Display duration in milliseconds (default: from config)position(string, optional): Position on screen (default: from config)showIcon(boolean, optional): Whether to show type-specific icon (default: from config)playSound(boolean, optional): Whether to play notification sound (default: from config)backgroundColor(string, optional): Custom background color overridetextColor(string, optional): Custom text color overrideborderColor(string, optional): Custom border color override
Returns: number|boolean - Notification ID on success, false on failure
Example:
clearNotifications
Clear all active notifications immediately with optional fade animation.
Returns: boolean - Success status
Example:
getNotifications
Get an array of all currently active notifications with their properties.
Returns: table - Array of active notification objects
id(number): Unique notification identifiertype(string): Notification typetitle(string): Notification titlemessage(string): Notification messageduration(number): Display durationposition(string): Screen positiontimestamp(number): Creation timestampshowIcon(boolean): Icon visibility state
Example:
notifyAll (Server-side only)
Send a notification to all online players simultaneously.
Parameters:
options(table): Notification configuration options (same as notify function)
Returns: boolean - Success status
Example:
notifyPlayer (Server-side only)
Convenience function to send a notification to a specific player with simplified parameters.
Parameters:
playerId(number): Player server IDmessage(string|table): Message text or full options tabletype(string, optional): Notification type (default: 'info')title(string, optional): Notification title
Returns: boolean - Success status
Example:
clearNotificationsPlayer (Server-side only)
Clear all notifications for a specific player from server-side.
Parameters:
playerId(number): Player server ID
Returns: boolean - Success status
Example:
Notification Types
Success Notifications
Used for positive feedback and successful operations.
Error Notifications
Used for error messages and failed operations.
Warning Notifications
Used for warnings and cautionary messages.
Info Notifications
Used for general information and neutral messages.
Positioning System
Notifications support a comprehensive 9-position grid system for precise placement:
Corner Positions:
'top-left'- Upper left corner'top-right'- Upper right corner'bottom-left'- Lower left corner'bottom-right'- Lower right corner
Center Positions:
'center'- Screen center'top-center'- Top center'bottom-center'- Bottom center
Side Positions:
'center-left'- Left side center'center-right'- Right side center
Server-Side Usage
Notify Specific Player
Notify All Players
Conditional Server Notifications
Bulk Notifications
Configuration
Configure notification defaults in config.lua:
Advanced Examples
Conditional Notifications with Health Monitoring
Progress Notifications with Chaining
Notification with State Tracking and Management
Server-Side Event-Driven Notifications
Custom Styled Notifications
Events
The notification system triggers the following events:
Client-Side Events
b2lib:notification:shown- Triggered when a notification is displayedb2lib:notification:hidden- Triggered when a notification is dismissedb2lib:notification:clicked- Triggered when a notification is clicked (if enabled)
Server-Side Events
b2lib:server:notify- Internal event for server-to-client notificationsb2lib:server:notifyAll- Internal event for broadcasting notifications
Best Practices
Use Appropriate Types - Match notification type to the message context for better user experience
Keep Messages Concise - Short, clear messages are more effective and readable
Consider Duration - Important messages should have longer durations, routine messages shorter
Avoid Notification Spam - Don't overwhelm users with too many notifications at once
Use Positioning Wisely - Place notifications where they won't obstruct important gameplay elements
Provide Context with Titles - Use titles to give immediate context to the message content
Test with Different Themes - Ensure notifications are readable in both dark and light themes
Handle Edge Cases - Always validate input parameters and handle failures gracefully
Use Server-Side for Important Messages - Critical notifications should come from server to ensure delivery
Implement Cleanup - Clear notifications when appropriate to prevent UI clutter
Troubleshooting
Notifications Not Showing
Check Message Parameter: Ensure the message parameter is provided and not empty
Verify B2Lib Initialization: Confirm B2Lib is properly initialized before calling functions
Validate Position: Ensure the position value is valid (check Config.ValidPositions)
Check Console Errors: Look for error messages from B2Lib.Debug in the console
Test with Simple Example: Try a basic notification without optional parameters
Notifications Overlapping or Positioning Issues
Use Different Positions: Assign different positions for concurrent notifications
Adjust maxVisible Config: Modify the maxVisible value in Config.Notifications
Clear Old Notifications: Use clearNotifications() before showing new important ones
Check Spacing Configuration: Verify spacing settings in notification config
Performance Issues
Limit Notification Frequency: Avoid showing too many notifications rapidly
Use Reasonable Durations: Set appropriate durations to prevent buildup
Clear When Appropriate: Clear notifications when no longer needed
Monitor Active Count: Use getNotifications() to monitor active notification count
Implement Queuing: Use the built-in queue system for high-frequency notifications
Server-Side Issues
Check Player Validity: Ensure player ID is valid before sending notifications
Handle Disconnections: Account for players disconnecting during notification sending
Validate Permissions: Check player permissions before sending sensitive notifications
Test Event Triggering: Verify server events are properly registered and triggered
Theme and Styling Issues
Test Both Themes: Verify notifications work in both dark and light themes
Check Custom Colors: Ensure custom colors have sufficient contrast
Validate CSS: Check that custom styling doesn't break the notification layout
Test on Different Resolutions: Verify positioning works on various screen sizes
Last updated