Skip to content

Commit 7d6b043

Browse files
committed
v2
[+] Optimisation [+] Minor fixes [+] ox_lib log [+] Code rework [/] Removed useless features
1 parent 612f573 commit 7d6b043

File tree

11 files changed

+936
-1004
lines changed

11 files changed

+936
-1004
lines changed

client/client.lua

Lines changed: 18 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,204 +1,30 @@
1-
CORE = exports.zrx_utility:GetUtility()
2-
COOLDOWN = false
3-
BLIP_DATA, SPEEDLIMIT_DATA, REMOVECARS_DATA = {}, {}, {}
1+
BREAK, VEHICLE, IS_WHITELIST, BLIP_DATA = {}, {}, {}, {}
42

5-
CORE.Client.RegisterKeyMappingCommand(Config.Command, Strings.cmd_desc, Config.Key, function()
3+
RegisterKeyMapping(Config.Command, Strings.cmd_desc, 'keyboard', Config.Keybind)
4+
RegisterCommand(Config.Command, function()
65
OpenMainMenu()
6+
end, false)
7+
TriggerEvent('chat:addSuggestion', ('/%s'):format(Config.Command), Strings.cmd_desc, {})
8+
9+
RegisterNetEvent('zrx_restrictedzone:client:zone', function(action, data)
10+
if action == 'create' then
11+
CreateZone(data)
12+
elseif action == 'update' then
13+
UpdateZone(data)
14+
elseif action == 'remove' then
15+
RemoveZone(data)
16+
end
717
end)
818

919
RegisterNetEvent('onClientResourceStop', function(res)
1020
if res ~= GetCurrentResourceName() then return end
1121

12-
if DoesEntityExist(cache.vehicle) then
13-
SetVehicleMaxSpeed(cache.vehicle, 0.0)
22+
if DoesEntityExist(VEHICLE[data.bId]) then
23+
SetVehicleMaxSpeed(VEHICLE[data.bId], 9999)
1424
end
1525

16-
for i, data in pairs(BLIP_DATA) do
17-
RemoveBlip(data.displayBlip)
26+
for bId, data in pairs(BLIP_DATA) do
27+
RemoveBlip(data.blip)
1828
RemoveBlip(data.radiusBlip)
1929
end
20-
end)
21-
22-
RegisterNetEvent('zrx_restrictedzone:client:startBlip', function(data)
23-
local temp = Config.Templates[data.cindex]
24-
25-
if data.playSound then
26-
PlaySoundFrontend(-1, 'BASE_JUMP_PASSED', 'HUD_AWARDS', false)
27-
end
28-
29-
if data.speedlimit then
30-
SPEEDLIMIT_DATA[#SPEEDLIMIT_DATA + 1] = {
31-
speed = Config.KPH and data.speedlimit / 3.6 or data.speedlimit / 2.236936,
32-
coords = data.coords,
33-
range = data.radius,
34-
allowedJobs = data.allowedJobs
35-
}
36-
37-
local pedCoords = GetEntityCoords(cache.ped)
38-
if DoesEntityExist(cache.vehicle) and #(vector3(data.coords.x, data.coords.y, data.coords.z) - vector3(pedCoords.x, pedCoords.y, pedCoords.z)) <= data.radius then
39-
SetVehicleMaxSpeed(cache.vehicle, data.speed)
40-
Entity(cache.vehicle).state.zrx_r_speedlimit = {}
41-
Entity(cache.vehicle).state.zrx_r_speedlimit[#SPEEDLIMIT_DATA] = true
42-
end
43-
end
44-
45-
if data.removeCars then
46-
REMOVECARS_DATA[#REMOVECARS_DATA + 1] = {
47-
coords = data.coords,
48-
range = data.radius
49-
}
50-
end
51-
52-
BLIP_DATA[#BLIP_DATA + 1] = {
53-
creator = data.creator,
54-
allowedJobs = data.allowedJobs,
55-
cindex = data.cindex,
56-
displayBlip = temp.displayBlip(vector3(data.coords.x, data.coords.y, data.coords.z)),
57-
radiusBlip = temp.radiusBlip(vector3(data.coords.x, data.coords.y, data.coords.z), data.radius),
58-
speedlimit = data.speedlimit,
59-
timeout = data.timeout,
60-
removeCars = data.removeCars,
61-
playSound = data.playSound,
62-
speedlimitI = data.speedlimit == true and #SPEEDLIMIT_DATA or false,
63-
removeCarsI = data.removeCars == true and #REMOVECARS_DATA or false,
64-
street = data.street,
65-
radius = data.radius,
66-
coords = data.coords
67-
}
68-
end)
69-
70-
RegisterNetEvent('zrx_restrictedzone:client:editBlip', function(data, index)
71-
local oldData = BLIP_DATA[index]
72-
local temp = Config.Templates[data.cindex]
73-
74-
if data.playSound and not oldData.playSound then
75-
PlaySoundFrontend(-1, 'BASE_JUMP_PASSED', 'HUD_AWARDS', false)
76-
end
77-
78-
if not data.playSound and oldData.playSound then
79-
PlaySoundFrontend(-1, 'PEYOTE_COMPLETED', 'HUD_AWARDS', false)
80-
end
81-
82-
if data.speedlimit then
83-
SPEEDLIMIT_DATA[data.speedlimitI or #SPEEDLIMIT_DATA + 1] = {
84-
speed = Config.KPH and data.speedlimit / 3.6 or data.speedlimit / 2.236936,
85-
coords = data.coords,
86-
range = data.radius,
87-
allowedJobs = data.allowedJobs
88-
}
89-
90-
local pedCoords = GetEntityCoords(cache.ped)
91-
if DoesEntityExist(cache.vehicle) and #(vector3(data.coords.x, data.coords.y, data.coords.z) - vector3(pedCoords.x, pedCoords.y, pedCoords.z)) <= data.radius then
92-
SetVehicleMaxSpeed(cache.vehicle, data.speed)
93-
Entity(cache.vehicle).state.zrx_r_speedlimit = {}
94-
Entity(cache.vehicle).state.zrx_r_speedlimit[data.speedlimitI or #SPEEDLIMIT_DATA] = true
95-
end
96-
end
97-
98-
if data.removeCars then
99-
REMOVECARS_DATA[data.removeCarsI or #REMOVECARS_DATA + 1] = {
100-
coords = data.coords,
101-
range = data.radius
102-
}
103-
end
104-
105-
RemoveBlip(oldData.displayBlip)
106-
RemoveBlip(oldData.radiusBlip)
107-
108-
BLIP_DATA[index] = {
109-
creator = data.creator,
110-
allowedJobs = data.allowedJobs,
111-
cindex = data.cindex,
112-
displayBlip = temp.displayBlip(vector3(data.coords.x, data.coords.y, data.coords.z)),
113-
radiusBlip = temp.radiusBlip(vector3(data.coords.x, data.coords.y, data.coords.z), data.radius),
114-
speedlimit = data.speedlimit,
115-
timeout = data.timeout,
116-
removeCars = data.removeCars,
117-
playSound = data.playSound,
118-
speedlimitI = data.speedlimit == true and #SPEEDLIMIT_DATA or false,
119-
removeCarsI = data.removeCars == true and #REMOVECARS_DATA or false,
120-
street = data.street,
121-
radius = data.radius,
122-
coords = data.coords
123-
}
124-
end)
125-
126-
RegisterNetEvent('zrx_restrictedzone:client:removeBlip', function(index)
127-
local temp = BLIP_DATA[index]
128-
129-
if temp.playSound then
130-
PlaySoundFrontend(-1, 'PEYOTE_COMPLETED', 'HUD_AWARDS', false)
131-
end
132-
133-
if temp.speedlimit then
134-
if DoesEntityExist(cache.vehicle) and Entity(cache.vehicle).state.zrx_r_speedlimit[temp.speedlimitI] then
135-
SetVehicleMaxSpeed(cache.vehicle, 0.0)
136-
end
137-
138-
SPEEDLIMIT_DATA[temp.speedlimitI] = nil
139-
end
140-
141-
if temp.removeCars then
142-
REMOVECARS_DATA[temp.removeCarsI] = nil
143-
end
144-
145-
RemoveBlip(temp.displayBlip)
146-
RemoveBlip(temp.radiusBlip)
147-
148-
BLIP_DATA[index] = nil
149-
end)
150-
151-
CreateThread(function()
152-
local pedCoords, popType, vehCoords
153-
local vehicles = {}
154-
155-
lib.waitFor(function()
156-
return NetworkIsPlayerActive(cache.playerId)
157-
end, 'Timeout', 120000)
158-
159-
while true do
160-
if #REMOVECARS_DATA >= 1 then
161-
pedCoords = GetEntityCoords(cache.ped)
162-
vehicles = GetGamePool('CVehicle')
163-
164-
for i, data in pairs(REMOVECARS_DATA) do
165-
if #(vector3(pedCoords.x, pedCoords.y, pedCoords.z) - vector3(data.coords.x, data.coords.y, data.coords.z)) <= data.range then
166-
for k, data2 in pairs(vehicles) do
167-
vehCoords = GetEntityCoords(data2)
168-
popType = GetEntityPopulationType(data2)
169-
170-
--| GetPedInVehicleSeat(data2, -1) ~= 0 and not IsPedAPlayer(GetPedInVehicleSeat(data2, -1)) | I think pop type is a better check
171-
if #(vector3(vehCoords.x, vehCoords.y, vehCoords.z) - vector3(data.coords.x, data.coords.y, data.coords.z)) <= data.range + 20 and
172-
(popType == 2 or popType == 3 or popType == 4 or popType == 5) then
173-
SetEntityAsMissionEntity(data2, true, true)
174-
DeleteVehicle(data2)
175-
end
176-
end
177-
end
178-
end
179-
end
180-
181-
if #SPEEDLIMIT_DATA >= 1 and DoesEntityExist(cache.vehicle) then
182-
pedCoords = GetEntityCoords(cache.ped)
183-
184-
Entity(cache.vehicle).state.zrx_r_speedlimit = {}
185-
SetVehicleMaxSpeed(cache.vehicle, 0.0)
186-
for i, data in pairs(SPEEDLIMIT_DATA) do
187-
if not data.allowedJobs[CORE.Bridge.getPlayerObject().job.name] and #(vector3(pedCoords.x, pedCoords.y, pedCoords.z) - vector3(data.coords.x, data.coords.y, data.coords.z)) <= data.range then
188-
Entity(cache.vehicle).state.zrx_r_speedlimit[i] = true
189-
SetVehicleMaxSpeed(cache.vehicle, data.speed)
190-
end
191-
end
192-
end
193-
194-
Wait(1000)
195-
end
196-
end)
197-
198-
exports('activeBlips', function()
199-
return BLIP_DATA
200-
end)
201-
202-
exports('hasCooldown', function()
203-
return COOLDOWN
20430
end)

0 commit comments

Comments
 (0)