-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient.lua
145 lines (127 loc) · 4.65 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
--====================================================================================
-- #Author: Jonathan D @ Gannon
--
-- Développée pour la communauté n3mtv
--====================================================================================
-- Configuration
local KeyToucheClose = 177 -- PhoneCancel
local distMaxCheck = 3
-- Variable | 0 close | 1 Identity | 2 register
local menuIsOpen = 0
local myIdentity = {}
--====================================================================================
-- TEMPORAIRE thead interaction
--====================================================================================
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if menuIsOpen ~= 0 then
if IsControlJustPressed(1, KeyToucheClose) and menuIsOpen == 1 then
closeGui()
elseif menuIsOpen == 2 then
local ply = GetPlayerPed(-1)
DisableControlAction(0, 1, true)
DisableControlAction(0, 2, true)
DisableControlAction(0, 24, true)
DisablePlayerFiring(ply, true)
DisableControlAction(0, 142, true)
DisableControlAction(0, 106, true)
DisableControlAction(0,KeyToucheClose,true)
if IsDisabledControlJustReleased(0, 142) then
SendNUIMessage({method = "clickGui"})
end
end
end
end
end)
--====================================================================================
-- User Event
--====================================================================================
RegisterNetEvent("gcIdentity:showIdentity")
AddEventHandler("gcIdentity:showIdentity", function()
local p , dist = GetClosestPlayer(distMaxCheck)
if p ~= -1 then
TriggerServerEvent('gcIdentity:openIdentity', GetPlayerServerId(p))
end
end)
RegisterNetEvent("gcIdentity:openMeIdentity")
AddEventHandler("gcIdentity:openMeIdentity", function()
openGuiIdentity(myIdentity)
end)
--====================================================================================
-- Gestion des evenements Server
--====================================================================================
RegisterNetEvent("gcIdentity:showIdentity")
AddEventHandler("gcIdentity:showIdentity", function(data)
openGuiIdentity(data)
end)
RegisterNetEvent("gcIdentity:showRegisterIdentity")
AddEventHandler("gcIdentity:showRegisterIdentity", function()
openGuiRegisterIdentity()
end)
RegisterNetEvent("gcIdentity:setIdentity")
AddEventHandler("gcIdentity:setIdentity", function(identity)
myIdentity = identity
end)
RegisterNUICallback('register', function(data, cb)
closeGui()
TriggerServerEvent('gcIdentity:setIdentity', data)
myIdentity = data
cb()
end)
--====================================================================================
-- Gestion UI
--====================================================================================
function openGuiIdentity(data)
--SetNuiFocus(true)
SendNUIMessage({method = 'openGuiIdentity', data = data})
Citizen.Trace('Data : ' .. json.encode(data))
menuIsOpen = 1
end
function openGuiRegisterIdentity()
SetNuiFocus(true)
SendNUIMessage({method = 'openGuiRegisterIdentity'})
menuIsOpen = 2
end
function closeGui()
SetNuiFocus(false)
SendNUIMessage({method = 'closeGui'})
menuIsOpen = 0
end
--====================================================================================
-- export function
--====================================================================================
function getIdentity()
return myIdentity
end
--====================================================================================
-- Utils function
--====================================================================================
function GetClosestPlayer(distmax)
local players = GetPlayers()
local closestDistance = distmax or -1
local closestPlayer = -1
local ply = GetPlayerPed(-1)
local plyCoords = GetEntityCoords(ply, 0)
for _ ,value in ipairs(players) do
local target = GetPlayerPed(value)
if(target ~= ply) then
local targetCoords = GetEntityCoords(GetPlayerPed(value), 0)
local distance = GetDistanceBetweenCoords(targetCoords["x"], targetCoords["y"], targetCoords["z"], plyCoords["x"], plyCoords["y"], plyCoords["z"], true)
if(closestDistance == -1 or closestDistance > distance) then
closestPlayer = value
closestDistance = distance
end
end
end
return closestPlayer, closestDistance
end
function GetPlayers()
local players = {}
for i = 0, 31 do
if NetworkIsPlayerActive(i) then
table.insert(players, i)
end
end
return players
end