-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
225 lines (196 loc) · 7.01 KB
/
client.lua
File metadata and controls
225 lines (196 loc) · 7.01 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
local notificationTypes = {
["success"] = {
icon = 1,
flash = false
},
["error"] = {
icon = 2,
flash = true
},
["info"] = {
icon = 3,
flash = false
},
["warning"] = {
icon = 4,
flash = true
},
["police"] = {
icon = 5,
flash = true
},
["phone"] = {
icon = 6,
flash = false
}
}
RegisterNetEvent('native_notify:showNotification')
AddEventHandler('native_notify:showNotification', function(data)
ShowNotification(data)
end)
RegisterNetEvent('native_notify:showNotificationToPlayer')
AddEventHandler('native_notify:showNotificationToPlayer', function(playerId, data)
if not playerId or playerId == GetPlayerServerId(PlayerId()) then
ShowNotification(data)
end
end)
function ShowNotification(data)
if not data.message then
return
end
local type = data.type or 'info'
if not notificationTypes[type] then
type = 'info'
end
local icon = data.icon or notificationTypes[type].icon
local flash = data.flash or notificationTypes[type].flash
local title = data.title or ''
local subtitle = data.subtitle or ''
local duration = data.duration or 5000
SetNotificationTextEntry('STRING')
AddTextComponentSubstringPlayerName(data.message)
local notificationId
if data.picture then
notificationId = DrawNotificationWithPicture(data.picture, data.title, data.subtitle)
elseif data.url then
notificationId = DrawNotificationWithUrl(data.url, data.title, data.subtitle, data.message)
elseif title ~= '' then
SetNotificationMessage('CHAR_DEFAULT', 'CHAR_DEFAULT', flash, icon, title, subtitle)
notificationId = DrawNotification(false, true)
else
notificationId = DrawNotification(false, flash)
end
Citizen.SetTimeout(duration, function()
RemoveNotification(notificationId)
end)
return notificationId
end
function DrawNotificationWithPicture(picture, title, subtitle)
local txd = "CHAR_BLANK_ENTRY"
if picture == "CHAR_ALL_PLAYERS_CONF" or
picture == "CHAR_AMMUNATION" or
picture == "CHAR_BANK_BOL" or
picture == "CHAR_BANK_FLEECA" or
picture == "CHAR_BANK_MAZE" or
picture == "CHAR_BUGSTARS" or
picture == "CHAR_CALL911" or
picture == "CHAR_CHAT_CALL" or
picture == "CHAR_CHEF" or
picture == "CHAR_CHOP" or
picture == "CHAR_CREDIT_INFO" or
picture == "CHAR_DEFAULT" or
picture == "CHAR_DETONATEPHONE" or
picture == "CHAR_FILMNOIR" or
picture == "CHAR_LIFEINVADER" or
picture == "CHAR_LS_CUSTOMS" or
picture == "CHAR_LS_TOURIST_BOARD" or
picture == "CHAR_LESTER" or
picture == "CHAR_LESTER_DEATHWISH" or
picture == "CHAR_MARTIN" or
picture == "CHAR_MECHANIC" or
picture == "CHAR_MICHAEL" or
picture == "CHAR_MP_ARMY_CONTACT" or
picture == "CHAR_MP_BRUCIE" or
picture == "CHAR_MP_FIB_CONTACT" or
picture == "CHAR_MP_FM_CONTACT" or
picture == "CHAR_MP_GERALD" or
picture == "CHAR_MP_JULIO" or
picture == "CHAR_MP_MECHANIC" or
picture == "CHAR_MP_MERRYWEATHER" or
picture == "CHAR_MP_MEX_BOSS" or
picture == "CHAR_MP_MEX_DOCKS" or
picture == "CHAR_MP_MEX_LT" or
picture == "CHAR_MP_MORS_MUTUAL" or
picture == "CHAR_MP_PROF_BOSS" or
picture == "CHAR_MP_RAY_LAVOY" or
picture == "CHAR_MP_ROBERTO" or
picture == "CHAR_MP_SNITCH" or
picture == "CHAR_MP_STRETCH" or
picture == "CHAR_MP_STRIPCLUB_PR" or
picture == "CHAR_RON" or
picture == "CHAR_SIMEON" or
picture == "CHAR_SOCIAL_CLUB" or
picture == "CHAR_STEVE" or
picture == "CHAR_STEVE_MIKE_CONF" or
picture == "CHAR_STEVE_TREV_CONF" or
picture == "CHAR_TAXI" or
picture == "CHAR_TREVOR" or
picture == "CHAR_WADE" then
txd = picture
end
if title and title ~= '' then
subtitle = subtitle or ""
return SetNotificationMessage(txd, txd, true, 1, title, subtitle)
else
return SetNotificationMessage(txd, txd, false, 1, GetLabelText("HUD_CASH_ITEM_STOLEN"), "")
end
end
function DrawNotificationWithUrl(url, title, subtitle, message)
if url == nil or url == '' then
return DrawNotificationWithPicture("CHAR_DEFAULT", title, subtitle)
end
local txdName = "notification_" .. math.random(1000000)
local txd = CreateRuntimeTxd(txdName)
local dui = CreateDui(url, 128, 128)
local duitxd = GetDuiHandle(dui)
CreateRuntimeTextureFromDuiHandle(txd, "notification", duitxd)
BeginTextCommandThefeedPost("STRING")
AddTextComponentSubstringPlayerName(message)
title = title or ""
subtitle = subtitle or ""
local notification
if title ~= "" then
EndTextCommandThefeedPostMessagetext(txdName, "notification", true, 1, title, subtitle)
notification = EndTextCommandThefeedPostTicker(false, true)
else
EndTextCommandThefeedPostMessagetext(txdName, "notification", false, 1, "", "")
notification = EndTextCommandThefeedPostTicker(false, false)
end
Citizen.SetTimeout(10000, function()
DestroyDui(dui)
end)
return notification
end
exports('ShowNotification', ShowNotification)
RegisterCommand('testnotify', function(source, args, rawCommand)
local type = args[1] or 'info'
local message = args[2] or '这是一条测试通知'
local title = args[3] or ''
ShowNotification({
type = type,
message = message,
title = title
})
end)
RegisterCommand('testpicnotify', function(source, args, rawCommand)
local picture = args[1] or 'CHAR_LESTER'
local message = args[2] or '这是一条带图片的测试通知'
local title = args[3] or '通知标题'
local subtitle = args[4] or ''
ShowNotification({
picture = picture,
message = message,
title = title,
subtitle = subtitle
})
end)
RegisterCommand('testnotifyy', function(source, args, rawCommand)
ShowNotification({
picture = 'CHAR_LS_TOURIST_BOARD',
message = '我们绝不容忍在公共交通工具上的恐怖行为!',
title = '洛圣都交通',
subtitle = '旅游信息'
})
end)
RegisterCommand('testurlnotify', function(source, args, rawCommand)
local url = args[1] or 'https://r2.fivemanage.com/o0SQp9T24AoAbL1nduWW2/fivem.png'
local message = args[2] or '这是一条带URL图片的测试通知'
local title = args[3] or 'URL图片通知'
local subtitle = args[4] or '自定义图片'
ShowNotification({
url = url,
message = message,
title = title,
subtitle = subtitle
})
end)