-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
58 lines (49 loc) · 1.62 KB
/
server.lua
File metadata and controls
58 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function SendNotificationToAll(data)
TriggerClientEvent('native_notify:showNotification', -1, data)
end
function SendNotificationToPlayer(playerId, data)
TriggerClientEvent('native_notify:showNotification', playerId, data)
end
function SendNotificationToArea(coords, radius, data)
for _, playerId in ipairs(GetAllPlayers()) do
local playerPed = GetPlayerPed(playerId)
local playerCoords = GetEntityCoords(playerPed)
if #(playerCoords - coords) <= radius then
TriggerClientEvent('native_notify:showNotification', playerId, data)
end
end
end
function GetAllPlayers()
local players = {}
for i = 0, 255 do
if GetPlayerName(i) ~= "" then
table.insert(players, i)
end
end
return players
end
exports('SendNotificationToAll', SendNotificationToAll)
exports('SendNotificationToPlayer', SendNotificationToPlayer)
exports('SendNotificationToArea', SendNotificationToArea)
RegisterCommand('servernotify', function(source, args, rawCommand)
local playerId = tonumber(args[1])
local type = args[2] or 'info'
local message = args[3] or '这是一条服务器通知'
local title = args[4] or ''
local subtitle = args[5] or ''
if not playerId or playerId == 0 then
SendNotificationToAll({
type = type,
message = message,
title = title,
subtitle = subtitle
})
else
SendNotificationToPlayer(playerId, {
type = type,
message = message,
title = title,
subtitle = subtitle
})
end
end, true)