Alert

This resource provides a synchronous (blocking) Alert Dialog system. It utilizes Citizen.Await to pause code execution until the user interacts with the alert, making logic flows linear and easy to write.
⚙️ Exports
You can access these functions from any other resource using the exports handler.
ShowAlert
Opens a customizable alert dialog and awaits a user response.
local result = exports['ak47_lib']:ShowAlert(data)Parameters (data table):
| Property | Type | Default | Description |
|---|---|---|---|
header |
string |
nil |
The title text of the alert. |
content |
string |
nil |
The body text. Supports \n for new lines and Markdown (e.g., **bold**). |
centered |
boolean |
false |
If true, centers the text within the dialog. |
cancel |
boolean |
false |
If true, displays a "Cancel" button alongside the confirm button. |
size |
string |
config |
The width of the dialog. Options usually include 'sm', 'md', 'lg'. |
labels |
table |
nil |
Custom text for buttons. See Label Object below. |
colors |
table |
config |
Custom Hex colors. See Color Object below. |
borders |
table |
config |
Array of border positions (e.g., {'bottom'}). |
Return Value:
'confirm': User clicked the confirm button.'cancel': User clicked cancel, the alert was overwritten, or the UI was forcibly closed.
Note: If an alert is already active when
ShowAlertis called, the new function call will immediately return'cancel'to prevent overlapping UIs.
HideAlert
Forcibly closes the currently active alert (if any) and resolves its promise as 'cancel'.
exports['ak47_lib']:HideAlert()🧩 Data Objects
Label Object
Used inside the labels parameter to change button text.
{
confirm = "Yes, Do it", -- Text for the primary button
cancel = "No, Go back" -- Text for the secondary button (if cancel = true)
}Color Object
Used inside the colors parameter to override default styling.
{
colorPrimary = '#1F1F1F', -- Background color
colorSecondary = '#FF5555', -- Accent/Button color
colorText = '#FFFFFF' -- Text color
}💡 Examples
Example 1: Basic Information
A simple notification that pauses the script until acknowledged.
local result = exports['ak47_lib']:ShowAlert({
header = 'Welcome',
content = 'Welcome to the server! Please read the rules.',
centered = true,
size = 'sm'
})
print('User acknowledged the alert.')Example 2: Confirmation Logic
Using the return value to determine the next step.
local choice = exports['ak47_lib']:ShowAlert({
header = 'Purchase Vehicle',
content = 'Are you sure you want to buy this vehicle for **$50,000**?',
cancel = true, -- Enable cancel button
labels = {
confirm = 'Purchase',
cancel = 'Walk Away'
}
})
if choice == 'confirm' then
TriggerServerEvent('buyVehicle')
print('Vehicle purchased')
else
print('Purchase cancelled')
endExample 3: Danger/Warning Style
Customizing colors to indicate a dangerous action (red styling).
local confirmation = exports['ak47_lib']:ShowAlert({
header = 'DELETE CHARACTER',
content = 'This action is **irreversible**.\nAre you sure?',
centered = true,
cancel = true,
size = 'md',
colors = {
colorPrimary = '#360000', -- Dark Red Background
colorSecondary = '#FF0000', -- Bright Red Buttons
colorText = '#FFFFFF'
},
borders = {'bottom', 'top'},
labels = { confirm = 'PERMANENTLY DELETE', cancel = 'Cancel' }
})
if confirmation == 'confirm' then
-- Delete logic here
endExample 4: Handling Overlaps
Since the function returns immediately if another alert is open, you can handle that edge case.
local status = exports['ak47_lib']:ShowAlert({ header = 'Test' })
if status == 'cancel' then
-- Note: This could mean the user clicked cancel OR
-- simply that the UI was already open.
print('Alert closed or could not open.')
end