# Exports and Events

{% hint style="success" %}
Here is the event and export to use in your scripts to display notifications.
{% endhint %}

Via export (Client-Side)

```lua
exports['PNotifv2']:sendNotification({
    message = 'Your message here',
    type = 'info',
    title = 'Custom Header',
    duration = 5000
})
```

Via Event (Serveur to Client)

```lua
TriggerClientEvent('pnotifv2:sendNotification', source, {
    message = 'Your message here',
    type = 'info',
    title = 'Custom Header',
    duration = 5000
})
```

Example

```lua
RegisterCommand('notifyServerTest', function(source, args, rawCommand)
    TriggerClientEvent('pnotifv2:sendNotification', source, {
        title = '~r~Colored~s~ ~g~Title~s~',
        message = 'This is a test with a ~b~colored title~s~ sent from the server',
        type = 'success',
        duration = 5000
    })

    TriggerClientEvent('pnotifv2:sendNotification', source, {
        title = '~y~Warning~s~',
        message = '~o~Important~s~ message with a ~bold~bold title~s~',
        type = 'error',
        duration = 5000
    })

    TriggerClientEvent('pnotifv2:sendNotification', source, {
        title = '~lg~Great~s~ ~bold~Success~s~',
        message = 'Operation completed successfully with a ~g~colored title~s~',
        type = 'info',
        duration = 5000
    })

end)
```

You can always use `esx.ShowNotification`.\
If you make any changes in your `es_extended`, go to the file `es_extended/client/functions.lua`.<br>

**Replace**&#x20;

```lua
ESX.ShowNotification = function(msg)
	SetNotificationTextEntry('STRING')
	AddTextComponentString(msg)
	DrawNotification(0,1)
end
```

**Then, add this**

```lua
function ESX.ShowNotification(msg, texttype, length)
    local convert = {
        ["primary"] = 'info',
        ["police"] = 'lspd',
        ["ambulance"] = 'ems',
    }
    if not texttype then
        texttype = 'info'
    end
    if convert[texttype] then
        texttype = convert[texttype]
    end
    TriggerEvent('pnotifv2:sendNotification', {
        message = msg,
        type = texttype,
        duration = length or 5000
    })
end
```

To use the ESX notification trigger, use this one: <br>

#### Client

```lua
-- Simple
TriggerEvent('esx:showNotification', 'Message')

-- With type
TriggerEvent('esx:showNotification', 'Message', 'success')

-- Full
TriggerEvent('esx:showNotification', 'Message', 'bank', 8000)
```

#### Server

```lua
-- To a player
TriggerClientEvent('esx:showNotification', source, 'Message', 'success')

-- To everyone
TriggerClientEvent('esx:showNotification', -1, 'Message', 'server', 10000)

-- To a job
local xPlayers = ESX.GetExtendedPlayers('job', 'police')
for _, xPlayer in pairs(xPlayers) do
    TriggerClientEvent('esx:showNotification', xPlayer.source, 'Message', 'lspd')
end
```

QBCore \
You can always use `QBCore.Functions.Notify`.\
If you make any changes in your `qb-core`, go to the file `qb-core/client/functions.lua`.\
\
**Replace**

```lua
function QBCore.Functions.Notify(text, texttype, length, icon)
    local message = {
        action = 'notify',
        type = texttype or 'primary',
        length = length or 5000,
    }

    if type(text) == 'table' then
        message.text = text.text or 'Placeholder'
        message.caption = text.caption or 'Placeholder'
    else
        message.text = text
    end

    if icon then
        message.icon = icon
    end

    SendNUIMessage(message)
end
```

**Then, add this**

```lua
function QBCore.Functions.Notify(text, texttype, length)
    local convert = {
        ["primary"] = 'info',
        ["police"] = 'lspd',
        ["ambulance"] = 'ems',
    }
    if not texttype then
        texttype = 'info'
    end

    if convert[texttype] then
        texttype = convert[texttype]
    end

    if type(text) == "table" then
        local ttext = text.text or 'Placeholder'
        local caption = text.caption or 'Placeholder'
        length = length or 5000
        TriggerEvent('pnotifv2:sendNotification', {
            message = ttext,
            type = texttype,
            title = caption,
            duration = length
        })
    else
        length = length or 5000
        TriggerEvent('pnotifv2:sendNotification', {
            message = text,
            type = texttype,
            duration = length
        })
    end
end
```

## Client

```lua
-- Simple
QBCore.Functions.Notify('Message')

-- With type
QBCore.Functions.Notify('Message', 'success')

-- Full (type + duration)
QBCore.Functions.Notify('Message', 'bank', 8000)
```

## Server

```lua
-- To a player
TriggerClientEvent('QBCore:Notify', source, 'Message', 'success', 5000)

-- To everyone
for _, playerId in pairs(QBCore.Functions.GetPlayers()) do
    TriggerClientEvent('QBCore:Notify', playerId, 'Message', 'info', 10000)
end

-- To a specific job
local players = QBCore.Functions.GetPlayersByJob('police')
for _, playerId in pairs(players) do
    TriggerClientEvent('QBCore:Notify', playerId, 'Message', 'police', 5000)
end

```
