pNotify:
pNotify simply implements a Javascript notification library called NOTY.
I didn’t like all of the notifications in the chat box so I threw this together real quick, I didn’t plan on making it public so this may confuse some people. Just look at the examples and you should be able to understand how it works. This just simply sends a NUI message which then runs a JS function, that creates a notification, provided by the NOTY library.
Download:
https://github.com/Nick78111/pNotify
Preview:
http://i.imgur.com/QJm4ovX.jpg
Sorry for the low bit rate, I had to keep it low because I have a horrible upload speed.
The code ran in this video will be posted below in the examples.
Sending A Notification:
Client:
exports.pNotify:SendNotification({options})
or
TriggerEvent("pNotify:SendNotification", {options})
Server:
TriggerClientEvent("pNotify:SendNotification", -1, {options})
Setting a Queues Max:
~ This sets how many notifications, in the same queue, can be visible at a given time ~ If this isn't called before sending the first notification of that queue, it will be set to 5. It only needs to be set once.Client:
exports.pNotify:SetQueueMax(queueName, Max)
or
TriggerEvent("pNotify:SetQueueMax", queueName, Max)
Server:
TriggerClientEvent("pNotify:SetQueueMax", -1, queueName, Max)
Options:
~ This is an array that contains the properties of the notification- type
- layout
- theme
- text
- timeout
- queue
- killer
You can view what these options do on their website.
There are also a lot more options but I won’t go ever them.
Valid Options:
~ Options marked with * are default- layout
- top, topLeft, topCenter, topRight *
- center, cenerLeft, centerRight
- bottom, bottomLeft, bottomCenter, bottomRight
- type
- alert
- success *
- error
- warning
- info
- theme - Changes the look of the notifications, you can edit or create custom themes inside html/themes.css
- gta *
- mint
- relax
- metroui
queue is set to “global” by default
Finally, an Example:
~ The result of these examples are in the screenshot above ~ These were ran in a chatCommand EventHandlerClient:
if cmd == "/notify" then
exports.pNotify:SetQueueMax("global", 8)
for i = 0, 5 do
exports.pNotify:SendNotification({text = "Testing Notification", type = "error", timeout = math.random(1000, 10000)})
end
for i = 0, 3 do
exports.pNotify:SendNotification({text = "You were given $100", type = "success", timeout = math.random(1000, 10000)})
end
for i = 0, 4 do
exports.pNotify:SendNotification({text = "Press F8 for more info", type = "info", timeout = math.random(1000, 10000)})
end
end
if cmd == "/notify2" then
exports.pNotify:SetQueueMax("left", 4)
for i = 0, 5 do
exports.pNotify:SendNotification({
text = "Testing Notification",
type = "error",
timeout = math.random(1000, 10000),
layout = "centerLeft",
queue = "left"
})
end
for i = 0, 3 do
exports.pNotify:SendNotification({
text = "You were given $100",
type = "success",
timeout = math.random(1000, 10000),
layout = "centerLeft",
queue = "left"
})
end
for i = 0, 4 do
exports.pNotify:SendNotification({
text = "Press F8 for more info",
type = "info",
timeout = math.random(1000, 10000),
layout = "centerLeft",
queue = "left"
})
end
end
if cmd == "/notify3" then
TriggerEvent("pNotify:SetQueueMax", "right", 2)
for i = 0, 5 do
TriggerEvent("pNotify:SendNotification", {
text = "SUCCCCEEESSSS",
type = "success",
timeout = math.random(1000, 10000),
layout = "centerRight",
queue = "right"
})
end
for i = 0, 3 do
TriggerEvent("pNotify:SendNotification", {
text = "THIS BE A WARNING",
type = "warning",
timeout = math.random(1000, 10000),
layout = "centerRight",
queue = "right"
})
end
exports.pNotify:SendNotification({text = "SUCCESS", type = "success", timeout = 200, layout = "centerRight", queue = "right"})
exports.pNotify:SendNotification({text = "Hello?", type = "info", timeout = 2000, layout = "centerRight", queue = "right"})
exports.pNotify:SendNotification({text = "Vehicle unlocked", type = "success", timeout = 200, layout = "centerRight", queue = "right"})
end
Error notification code:
- The sound doesn’t come with the download
local oldError = error
function error(...)
exports.pNotify:SetQueueMax("error", 2)
exports.pNotify:SendNotification({
text = "<b style='color:yellow'>There was a Lua error!</b> <br /><br /> <b style='color:red'> ".. ... .."</b><br /><br /><b style='color:yellow'>Press F8 to view it in the console.</b>",
type = "error",
queue = "error",
timeout = 15000,
layout = "bottomRight",
sounds = {
sources = {"sound-example.wav"}, -- For sounds to work, you place your sound in the html folder and then add it to the files array in the __resource.lua file.
volume = 0.2,
conditions = {"docVisible"} -- This means it will play the sound when the notification becomes visible.
}
})
oldError(unpack({...}))
end
Server:
if message == "/notify4" then
TriggerClientEvent("pNotify:SetQueueMax", -1, "lmao", 1)
for i = 0 , 5 do
TriggerClientEvent("pNotify:SendNotification", -1, {
text = "Testing Notification",
type = "error",
queue = "lmao",
timeout = 10000,
layout = "bottomCenter"
})
end
end
If this is too confusing, you can look at the documentation for NOTY here.