-
Notifications
You must be signed in to change notification settings - Fork 7
/
client.lua
125 lines (107 loc) · 3.98 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
ESX = exports["es_extended"]:getSharedObject()
RegisterCommand('lockvehicle', function()
local vehicle, dist = ESX.Game.GetClosestVehicle()
if dist < 10 and vehicle > 0 then
ClearPedTasks(PlayerPedId())
Wait(100)
TriggerServerEvent('carkeys:RequestVehicleLock', VehToNet(vehicle), GetVehicleDoorLockStatus(vehicle))
else
ESX.ShowNotification(_U('no_vehicle_found'))
end
end)
RegisterKeyMapping('lockvehicle', _U('lock_vehicle'), 'keyboard', 'f10')
RegisterNetEvent('carlock:CarLockedEffect', function(netId, lockStatus)
local vehicle = NetToVeh(netId)
if DoesEntityExist(vehicle) then
local ped = PlayerPedId()
local prop = GetHashKey('p_car_keys_01')
RequestModel(prop)
while not HasModelLoaded(prop) do
Citizen.Wait(10)
end
local keyObj = CreateObject(prop, 1.0, 1.0, 1.0, 1, 1, 0)
AttachEntityToEntity(keyObj, ped, GetPedBoneIndex(ped, 57005), 0.08, 0.039, 0.0, 0.0, 0.0, 0.0, true, true, false, true, 1, true)
local dict = "anim@mp_player_intmenu@key_fob@"
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
Citizen.Wait(0)
end
if not IsPedInAnyVehicle(PlayerPedId(), true) then
TaskPlayAnim(ped, dict, "fob_click_fp", 8.0, 8.0, -1, 48, 1, false, false, false)
end
PlayVehicleDoorCloseSound(vehicle, 1)
SetVehicleDoorsLockedForAllPlayers(vehicle, lockStatus)
if lockStatus then
ESX.ShowNotification(_U('vehicle_locked'))
else
ESX.ShowNotification(_U('vehicle_unlocked'))
end
SetVehicleLights(vehicle, 2)
Citizen.Wait(250)
SetVehicleLights(vehicle, 0)
Citizen.Wait(250)
SetVehicleLights(vehicle, 2)
Citizen.Wait(250)
SetVehicleLights(vehicle, 0)
Wait(600)
DetachEntity(keyObj, false, false)
DeleteEntity(keyObj)
end
end)
RegisterCommand('givekeys', function()
local closestP, closestD = ESX.Game.GetClosestPlayer()
local vehicle, dist = ESX.Game.GetClosestVehicle()
if DoesEntityExist(vehicle) and closestP ~= -1 and closestD < 4 and dist < 10 then
local plate = GetVehicleNumberPlateText(vehicle)
TriggerServerEvent('carkeys:GiveKeyToPerson', plate, GetPlayerServerId(closestP))
end
end)
function Draw3DText(x, y, z, text)
SetTextScale(0.22, 0.22)
SetTextFont(13)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
AddTextComponentString(text)
SetDrawOrigin(x,y,z, 0)
DrawText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawRect(0.0, 0.0+0.0125, 0.015+ factor, 0.03, 0, 0, 0, 75)
ClearDrawOrigin()
end
local centralPos = vector3(-25.94, -624.51, 35.5)
Citizen.CreateThread(function()
while true do
Wait(0)
local playerPed = PlayerPedId()
local dist = #(GetEntityCoords(playerPed) - centralPos)
if dist < 15.0 then
Draw3DText(centralPos.x, centralPos.y, centralPos.z, _U('change_locks_for', Config.Price))
if dist < 2 then
if IsControlJustPressed(0, 38) then
local veh = GetVehiclePedIsIn(playerPed)
if DoesEntityExist(veh) then
TriggerServerEvent('carkeys:NewLocks', GetVehicleNumberPlateText(veh))
Wait(5000)
else
ESX.ShowNotification(_U('must_in_vehicle'))
end
end
end
else
Wait(500)
end
end
end)
Citizen.CreateThread(function()
local blip = AddBlipForCoord(centralPos)
SetBlipSprite (blip, 186)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 0.9)
SetBlipColour (blip, 73)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(AddTextComponentString(_U('locksmith')))
EndTextCommandSetBlipName(blip)
end)