-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient.lua
98 lines (78 loc) · 2.02 KB
/
client.lua
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
Friends = {}
Panel = {
visible = false,
init = function(self)
RegisterNUICallback("close", function()
self:setVisible(false)
end)
RegisterNetEvent("openFriendsPanel", function(friends)
self:setVisible(not self.visible)
self:update(friends)
end)
RegisterNUICallback("sendRequest", function(data)
if not data.requestID then
return
end
ESX.TriggerServerCallback("newFriendRequest", function(result, msg)
if msg then
ESX.ShowNotification(msg)
end
self:update(result)
end, data.requestID)
end)
RegisterNUICallback("friendInteraction", function(data)
if not data.method or not data.player then
return
end
ESX.TriggerServerCallback("friendInteraction", function(friends, err)
if not friends then
return ESX.ShowNotification(err)
end
self:update(friends)
if data.method == "accept" then
ESX.ShowNotification("Friend request accepted.")
elseif data.method == "delete" then
ESX.ShowNotification("Friend removed.")
end
end, data.method, data.player)
end)
RegisterNUICallback("requestPlayerInfo", function(data, cb)
if not data.identifier then
return cb({ error = "Player not found!" })
end
ESX.TriggerServerCallback("requestPlayerInfo", function(result, err)
cb({
error = not result and err,
result = result,
})
end, data.identifier)
end)
ESX.TriggerServerCallback("requestPlayerFriends", function(friends)
self:update(friends)
end)
end,
setVisible = function(self, visible)
self.visible = visible
SendNUIMessage({ visible = visible })
SetNuiFocus(visible, visible)
end,
update = function(self, friends)
SendNUIMessage({ updatePlayers = friends })
Friends = {}
for _, friend in pairs(friends) do
if (friend.pending or 1) == 0 then
Friends[friend.friend] = friend
end
end
end,
}
Panel.__index = Panel
CreateThread(function()
while not ESX.IsPlayerLoaded() do
Wait(1)
end
Panel:init()
end)
exports("isPlayerFriend", function(identifier)
return Friends[identifier]
end)