forked from OhTanoshi/jsfour-dna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
204 lines (184 loc) · 6.11 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
local ESX = nil
local killer = nil
local weapon = nil
local killername = nil
local deadname = nil
local dna = {}
local weapons = {
[-1569615261] = {name = 'WEAPON_UNARMED', hash = 2725352035, text = 'Unarmed'},
[-1716189206] = {name = 'WEAPON_KNIFE', hash = 2578778090, text = 'Knife'},
[1737195953] = {name = 'WEAPON_NIGHTSTICK', hash = 1737195953, text = 'Baton'},
[2508868239] = {name = 'WEAPON_BAT', hash = 2508868239, text = 'Baseball Bat'},
[1317494643] = {name = 'WEAPON_HAMMER', hash = 1317494643, text = 'Hammer'},
[1141786504] = {name = 'WEAPON_GOLFCLUB', hash =1141786504, text = 'Golf Club'},
[2227010557] = {name = 'WEAPON_CROWBAR', hash =2227010557, text = 'Crowbar'},
[2460120199] = {name = 'WEAPON_DAGGER', hash =2460120199, text = 'Dagger'},
[3638508604] = {name = 'WEAPON_KNUCKLE', hash =3638508604, text = 'Brass Knuckles'},
[4191993645] = {name = 'WEAPON_HATCHET', hash =4191993645, text = 'Hatchet'},
[3713923289] = {name = 'WEAPON_MACHETE', hash =3713923289, text = 'Machete'},
[3756226112] = {name = 'WEAPON_SWITCHBLADE', hash =3756226112, text = 'Knife'},
[3441901897] = {name = 'WEAPON_BATTLEAXE', hash =3441901897, text = 'Axe'},
[2484171525] = {name = 'WEAPON_POOLCUE', hash =2484171525, text = 'Pool stick'},
[419712736] = {name = 'WEAPON_WRENCH', hash =419712736, text = 'Wrench'}
}
local inMarker = false
local PlayerData = {}
local dnaOpen = false
-- ESX
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
PlayerData = xPlayer
end)
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
PlayerData.job = job
end)
function notification(text)
SetTextComponentFormat("STRING")
AddTextComponentString(text)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end
-- Display marker, Enter/Exit events
Citizen.CreateThread(function ()
while true do
Wait(0)
if PlayerData.job ~= nil and PlayerData.job.name ~= 'unemployed' and PlayerData.job.name == "police" then
v = Config.Computer
if( v.Type ~= -1 and GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), v.Pos.x, v.Pos.y, v.Pos.z, true) < 50 ) then
DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
end
if( v.Type ~= -1 and GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x ) then
inMarker = true
notification(v.Hint)
else
inMarker = false
end
end
end
end)
-- Key events
Citizen.CreateThread(function ()
while true do
Wait(0)
if inMarker and IsControlJustReleased(0, 38) then
SetNuiFocus(true, true)
dnaOpen = true
SendNUIMessage({
action = "open"
})
end
end
end)
-- Remove DNA (empty the array)
RegisterNetEvent('jsfour-dna:remove')
AddEventHandler('jsfour-dna:remove', function()
dna = {}
end)
-- Grab DNA from a player
RegisterNetEvent('jsfour-dna:get')
AddEventHandler('jsfour-dna:get', function( player )
if dna.p == nil then
local ped = GetPlayerPed(player)
if IsPedFatallyInjured(ped) then
killerped = GetPedSourceOfDeath(ped)
killerid = GetPlayerServerId(NetworkGetPlayerIndexFromPed(killerped))
killername = GetPlayerName(NetworkGetPlayerIndexFromPed(killerped))
deadname = GetPlayerName(player)
_weapon = GetPedCauseOfDeath(GetPlayerPed(player))
for k, v in pairs(weapons) do
if k == _weapon then
weapon = v.text
end
end
Citizen.Wait(1000)
if weapon ~= nil then
dna = {k = killername, d = GetPlayerServerId(player), w = weapon, p = killerid}
ESX.ShowNotification('Took DNA samples from a crime scene..')
else
ESX.ShowNotification('Found no traces of DNA..')
end
else
dna = {k = nil, d = nil, w = nil, p = GetPlayerServerId(player)}
ESX.ShowNotification('Tog DNA-prov från en person..')
end
else
ESX.ShowNotification('You already have a DNA on you, submit it first..')
end
end)
-- Freeze ped if dna menu is open
Citizen.CreateThread(function()
while true do
if dnaOpen then
local ply = GetPlayerPed(-1)
local active = true
DisableControlAction(0, 1, active) -- LookLeftRight
DisableControlAction(0, 2, active) -- LookUpDown
DisableControlAction(0, 24, active) -- Attack
DisablePlayerFiring(ply, true) -- Disable weapon firing
DisableControlAction(0, 142, active) -- MeleeAttackAlternate
DisableControlAction(0, 106, active) -- VehicleMouseControlOverride
end
Citizen.Wait(0)
end
end)
-- Server callback
RegisterNetEvent('jsfour-dna:callback')
AddEventHandler('jsfour-dna:callback', function(_type, data, _type1, val)
SendNUIMessage({
action = _type,
array = data,
atype = _type1,
value = val
})
if data == 'upload-failed' then
dna = {}
end
end)
-- Javascript callbacks
-- Upload DNA
RegisterNUICallback('upload', function(data, cb)
if dna.p ~= nil then
TriggerServerEvent('jsfour-dna:save', dna)
dna = {}
cb('ok')
else
SendNUIMessage({
action = "callback",
array = 'upload-fail'
})
cb('error')
end
end)
-- Fetch DNA
RegisterNUICallback('fetch', function(data, cb)
TriggerServerEvent('jsfour-dna:fetch', data.type)
cb('ok')
end)
-- Remove DNA
RegisterNUICallback('remove', function(data, cb)
if data.name ~= nil then
TriggerServerEvent('jsfour-dna:remove', 'name', data.name)
elseif data.id ~= nil then
TriggerServerEvent('jsfour-dna:remove', 'id', data.id)
elseif data.match ~= nil then
TriggerServerEvent('jsfour-dna:remove', 'match', data.match)
end
cb('ok')
end)
-- Try to match DNA
RegisterNUICallback('match', function(data, cb)
TriggerServerEvent('jsfour-dna:match', data.id)
cb('ok')
end)
-- Close DNA menu
RegisterNUICallback('escape', function(data, cb)
SetNuiFocus(false, false)
dnaOpen = false
cb('ok')
end)