-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient.lua
276 lines (246 loc) · 7.24 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
local VORPcore = {}
local posselist = {}
Possetable = {}
local possenumber
local playid
local isinvited = false
local invitedpossename
local possename = " "
TriggerEvent("getCore", function(core)
VORPcore = core
end)
TriggerEvent('chat:addSuggestion', '/posse', 'Posse Menu Command')
RegisterCommand('posse', function()
PosseMenu()
end)
RegisterNetEvent('bcc-posse:sendinfo')
AddEventHandler('bcc-posse:sendinfo', function(posseid, inposse, radius)
local closestPlayer, closestDistance = GetClosestPlayer()
local targetid = GetPlayerServerId(closestPlayer)
possenumber = posseid
if not inposse then
inposse = false
else
inposse = true
if closestPlayer ~= -1 and closestDistance <= radius then
TriggerServerEvent('bcc-posse:checkposse', tonumber(targetid), possenumber)
end
--local id = GetPlayerServerId(GetPlayerIndex())
--table.insert(Possetable, id)
end
print(possenumber)
end)
function CheckPosseArea(coords, radius)
Possetable = {}
local pedcoords = coords
local ptable = GetActivePlayers()
for _, i in pairs(ptable) do
local targetped = GetPlayerPed(i)
playid = GetPlayerServerId(i)
if (Vdist(GetEntityCoords(targetped), pedcoords.x, pedcoords.y, pedcoords.z) < radius) then
if contains(Possetable, playid) then
print('its the same')
break
else
TriggerServerEvent('bcc-posse:grabinfo', playid, radius)
end
end
end
Wait(750)
return Possetable, #Possetable
end
function contains(table, val)
for i = 1, #table do
if table[i] == val then
return true
end
end
return false
end
RegisterNetEvent('bcc-posse:possefound')
AddEventHandler('bcc-posse:possefound', function()
table.insert(Possetable, playid)
end)
RegisterNetEvent('bcc-posse:sendposseinvites')
AddEventHandler('bcc-posse:sendposseinvites', function(posseid, posseinvites, invite)
isinvited = invite
invitedpossename = posseinvites
invitenumber = posseid
possenumber = invitenumber
print(possenumber)
end)
MenuData = {}
TriggerEvent("menuapi:getData", function(call)
MenuData = call
end)
function PosseMenu() -- Base Menu Logic
TriggerServerEvent('bcc-posse:grabinfo',source,Config.InviteDistance)
MenuData.CloseAll()
local elements = {}
if isinvited then
table.insert(elements, { label = "Create Posse", value = 'create' })
table.insert(elements, { label = "Invite to posse", value = 'invite' })
table.insert(elements, { label = "Accept Posse Invites", value = 'viewinvites' })
table.insert(elements, { label = "View Members", value = 'view' })
table.insert(elements, { label = "Leave Posse", value = 'leave' })
else
table.insert(elements, { label = "Create Posse", value = 'create' })
table.insert(elements, { label = "Invite to posse", value = 'invite' })
table.insert(elements, { label = "View Members", value = 'view' })
table.insert(elements, { label = "Leave Posse", value = 'leave' })
end
MenuData.Open('default', GetCurrentResourceName(), 'menuapi',
{
title = "Posse Menu",
align = 'left',
elements = elements,
},
function(data, menu)
if (data.current.value == 'create') then
CreatePosseMenu()
end
if (data.current.value == 'view') then
Wait(250)
TriggerServerEvent('bcc-posse:posselist', possenumber)
end
if (data.current.value == 'leave') then
Wait(100)
TriggerServerEvent('bcc-posse:leaveposse')
menu.close()
end
if (data.current.value == 'invite') then
local closestPlayer, closestDistance = GetClosestPlayer()
if closestPlayer ~= -1 and closestDistance <= 1.5 then
TriggerServerEvent('bcc-posse:beeninvitedsv', GetPlayerServerId(closestPlayer))
else
VORPcore.NotifyBottomRight("Not close enough", 4000)
end
end
if (data.current.value == 'viewinvites') then
Wait(250)
ViewPosseInvites()
end
end,
function(data, menu)
menu.close()
end)
end
function CreatePosseMenu() -- Create Posse Menu logic
MenuData.CloseAll()
local button = "Confirm"
local placeholder = "Posse Name"
local elements = {
{ label = "Posse Name: " .. possename, value = 'name' },
{ label = "Confirm Posse Name", value = 'confirm' },
}
MenuData.Open('default', GetCurrentResourceName(), 'menuapi',
{
title = "Posse Menu",
align = 'left',
elements = elements,
lastmenu = "PosseMenu"
},
function(data, menu)
if data.current == "backup" then
_G[data.trigger]()
end
if (data.current.value == 'name') then
TriggerEvent("vorpinputs:getInput", button, placeholder, function(result)
if result ~= "" or result then -- making sure its not empty or nil
possename = result
CreatePosseMenu()
else
print("its empty?") -- notify
end
end)
end
if (data.current.value == 'confirm') then
TriggerServerEvent('bcc-posse:createposse', possename)
menu.close()
end
end,
function(data, menu)
menu.close()
end)
end
function ViewPosseInvites() -- ViewInvite Logic
MenuData.CloseAll()
local elements = {
{ label = invitenumber .. " : " .. invitedpossename, value = 'posse' },
{ label = "Accept", value = 'accept' },
{ label = "Deny", value = 'deny' },
}
MenuData.Open('default', GetCurrentResourceName(), 'menuapi',
{
title = "Posse Menu",
align = 'left',
elements = elements,
lastmenu = "PosseMenu"
},
function(data, menu)
if data.current == "backup" then
_G[data.trigger]()
end
if data.current.value == "accept" then
TriggerServerEvent('bcc-posse:acceptinvite', invitenumber)
isinvited = false
menu.close()
end
if data.current.value == "deny" then
isinvited = false
menu.close()
end
end,
function(data, menu)
end)
end
RegisterNetEvent('bcc-posse:ViewMembersMenu', function(result)
-- View Member Logic
MenuData.CloseAll()
local elements, elementindex = {}, 1
for key, v in pairs(result) do
elements[elementindex] = {
label = v.firstname .. " " .. v.lastname,
value = "players"
}
elementindex = elementindex + 1
end
MenuData.Open('default', GetCurrentResourceName(), 'menuapi',
{
title = "Posse Menu",
align = 'left',
elements = elements,
lastmenu = "PosseMenu"
},
function(data, menu)
if data.current == "backup" then
_G[data.trigger]()
end
end,
function(data, menu)
menu.close()
end)
end)
function GetClosestPlayer()
local players, closestDistance, closestPlayer = GetActivePlayers(), -1, -1
local playerPed, playerId = PlayerPedId(), PlayerId()
local coords, usePlayerPed = coords, false
if coords then
coords = vector3(coords.x, coords.y, coords.z)
else
usePlayerPed = true
coords = GetEntityCoords(playerPed)
end
for i = 1, #players, 1 do
local tgt = GetPlayerPed(players[i])
if not usePlayerPed or (usePlayerPed and players[i] ~= playerId) then
local targetCoords = GetEntityCoords(tgt)
local distance = #(coords - targetCoords)
if closestDistance == -1 or closestDistance > distance then
closestPlayer = players[i]
closestDistance = distance
end
end
end
return closestPlayer, closestDistance
end