forked from KrnkTV/LG-Identification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
110 lines (93 loc) · 3.17 KB
/
client.lua
File metadata and controls
110 lines (93 loc) · 3.17 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
local CurrentData = {
image = nil,
name = nil,
age = nil,
sex = nil,
number_id = nil,
rank = nil,
department = nil
}
RegisterCommand("showid", function()
ShowID()
end, false)
RegisterCommand("editid", function()
EditID()
end, false)
RegisterCommand("hideid", function()
SendNUIMessage({type = "hide"})
SetNuiFocus(false, false)
end, false)
RegisterNUICallback("editSubmit", function(data, cb)
if not (Config.Functions.CanEditIdentity()) then return end
local data = Config.Functions.OnEditSubmit(data)
SetIdentification(data)
SetNuiFocus(false, false)
end)
RegisterNetEvent("lg-identification:identify")
AddEventHandler("lg-identification:identify", function(data, coords)
if #(coords - GetEntityCoords(PlayerPedId())) < Config.Data.DisplayDistance then
SendNUIMessage({type = "id", data = data})
end
end)
Citizen.CreateThread(function()
local data = GetResourceKvpString("ID_DATA")
if data then
CurrentData = json.decode(data)
else
SetIdentification(CurrentData)
end
Citizen.Wait(100)
SendNUIMessage({type = "config", data = Config.Data})
end)
function SetIdentification(data)
CurrentData = data
SetResourceKvp("ID_DATA", json.encode(CurrentData))
end
function GetIdentification()
return CurrentData
end
function ShowID()
if not Config.Functions.CanDisplayIdentity() then return end
TriggerServerEvent("lg-identification:identify", CurrentData)
local model = GetHashKey("prop_fib_badge")
local anim = {dictionary = "paper_1_rcm_alt1-9", animation = "player_one_dual-9"}
RequestModel(model)
while not HasModelLoaded(model) do
RequestModel(model)
Wait(10)
end
RequestAnimDict(anim.dictionary)
while not HasAnimDictLoaded(anim.dictionary) do
Citizen.Wait(100)
end
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local badgeProp = CreateObject(model, coords.x, coords.y, coords.z + 0.2, true, true, true)
local boneIndex = GetPedBoneIndex(ped, 28422)
AttachEntityToEntity(badgeProp, ped, boneIndex, 0.065, 0.029, -0.035, 80.0, -1.90, 75.0, true, true, false, true, 1, true)
TaskPlayAnim(ped, anim.dictionary, anim.animation, 8.0, -8, 10.0, 49, 0, 0, 0, 0)
Citizen.Wait(3000)
ClearPedSecondaryTask(ped)
DeleteObject(badgeProp)
end
function EditID()
if not (Config.Functions.CanEditIdentity()) then return end
SendNUIMessage({type = "edit", data = CurrentData})
SetNuiFocus(true, true)
end
RegisterNetEvent("lg-identification:editID")
AddEventHandler("lg-identification:editID", function(data)
EditID()
end)
RegisterNetEvent("lg-identification:showID")
AddEventHandler("lg-identification:showID", function()
ShowID()
end)
RegisterNetEvent("lg-identification:set")
AddEventHandler("lg-identification:set", function(data)
SetIdentification(data)
end)
exports("EditID", EditID)
exports("ShowID", ShowID)
exports("SetIdentification", SetIdentification)
exports("GetIdentification", GetIdentification)