Skip to content

Commit

Permalink
bit of refactoring pt 1
Browse files Browse the repository at this point in the history
  • Loading branch information
GhzGarage committed Dec 4, 2024
1 parent 845ad32 commit 1dd3228
Show file tree
Hide file tree
Showing 12 changed files with 1,045 additions and 1,037 deletions.
59 changes: 26 additions & 33 deletions client/anpr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local lastRadar = nil
local HasAlreadyEnteredMarker = false

local function IsInMarker(playerPos, speedCam)
return #(playerPos - vector3(speedCam.x, speedCam.y, speedCam.z)) < 20.0
return #(playerPos - speedCam) < 20.0
end

local function HandleSpeedCam(speedCam, radarID)
Expand All @@ -13,27 +13,18 @@ local function HandleSpeedCam(speedCam, radarID)
if isInMarker and not HasAlreadyEnteredMarker and lastRadar == nil then
HasAlreadyEnteredMarker = true
lastRadar = radarID

local vehicle = GetPlayersLastVehicle()
if IsPedInAnyVehicle(playerPed, false) and GetPedInVehicleSeat(vehicle, -1) == playerPed and GetVehicleClass(vehicle) ~= 18 then
local plate = QBCore.Functions.GetPlate(vehicle)
QBCore.Functions.TriggerCallback('police:IsPlateFlagged', function(isFlagged)
if isFlagged then
local coords = GetEntityCoords(playerPed)
local blipsettings = {
x = coords.x,
y = coords.y,
z = coords.z,
sprite = 488,
color = 1,
scale = 0.9,
text = Lang:t('info.camera_speed', { radarid = radarID })
}
local street1, street2 = table.unpack(GetStreetNameAtCoord(coords.x, coords.y, coords.z))
TriggerServerEvent('police:server:FlaggedPlateTriggered', radarID, plate, street1, street2, blipsettings)
end
end, plate)
end
local vehicle = GetVehiclePedIsIn(playerPed, false)
if vehicle == 0 then return end
local is_driver = GetPedInVehicleSeat(vehicle, -1) == playerPed
if not is_driver then return end
if GetVehicleClass(vehicle) == 18 then return end
local plate = QBCore.Functions.GetPlate(vehicle)
QBCore.Functions.TriggerCallback('police:server:IsPlateFlagged', function(isFlagged)
if isFlagged then
local coords = Config.Radars[radarID]
TriggerServerEvent('police:server:FlaggedPlateTriggered', coords, plate)
end
end, plate)
end

if not isInMarker and HasAlreadyEnteredMarker and lastRadar == radarID then
Expand All @@ -42,16 +33,18 @@ local function HandleSpeedCam(speedCam, radarID)
end
end

CreateThread(function()
while true do
if IsPedInAnyVehicle(PlayerPedId(), false) then
for i = 1, #Config.Radars do
local value = Config.Radars[i]
HandleSpeedCam(value, i)
if Config.EnableRadars then
CreateThread(function()
while true do
if IsPedInAnyVehicle(PlayerPedId(), false) then
for i = 1, #Config.Radars do
local value = Config.Radars[i]
HandleSpeedCam(value, i)
end
Wait(200)
else
Wait(2500)
end
Wait(200)
else
Wait(2500)
end
end
end)
end)
end
4 changes: 2 additions & 2 deletions client/heli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ local function RenderVehicleInfo(vehicle)
end

-- Events
RegisterNetEvent('heli:spotlight', function(serverID, state)
RegisterNetEvent('heli:client:spotlight', function(serverID, state)
local heli = GetVehiclePedIsIn(GetPlayerPed(GetPlayerFromServerId(serverID)), false)
SetVehicleSearchlight(heli, state, false)
end)
Expand Down Expand Up @@ -159,7 +159,7 @@ CreateThread(function()

if IsControlJustPressed(0, toggle_spotlight) and (GetPedInVehicleSeat(heli, -1) == lPed or GetPedInVehicleSeat(heli, 0) == lPed) then
spotlight_state = not spotlight_state
TriggerServerEvent('heli:spotlight', spotlight_state)
TriggerServerEvent('heli:server:spotlight', spotlight_state)
PlaySoundFrontend(-1, 'SELECT', 'HUD_FRONTEND_DEFAULT_SOUNDSET', false)
end

Expand Down
107 changes: 53 additions & 54 deletions client/objects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local spikemodel = `P_ld_stinger_s`
local ClosestSpike = nil

-- Functions

local function GetClosestPoliceObject()
local pos = GetEntityCoords(PlayerPedId(), true)
local current = nil
Expand All @@ -29,18 +30,28 @@ function GetClosestSpike()
local pos = GetEntityCoords(PlayerPedId(), true)
local current = nil
local dist = nil
local maxDistance = 50.0

for id, _ in pairs(SpawnedSpikes) do
local spikeCoords = vector3(SpawnedSpikes[id].coords.x, SpawnedSpikes[id].coords.y, SpawnedSpikes[id].coords.z)
local currentDist = #(pos - spikeCoords)

if current then
if #(pos - vector3(SpawnedSpikes[id].coords.x, SpawnedSpikes[id].coords.y, SpawnedSpikes[id].coords.z)) < dist then
if currentDist < dist then
current = id
dist = currentDist
end
else
dist = #(pos - vector3(SpawnedSpikes[id].coords.x, SpawnedSpikes[id].coords.y, SpawnedSpikes[id].coords.z))
current = id
dist = currentDist
end
end
ClosestSpike = current

if dist and dist <= maxDistance then
ClosestSpike = current
else
ClosestSpike = nil
end
end

local function DrawText3D(x, y, z, text)
Expand All @@ -59,6 +70,7 @@ local function DrawText3D(x, y, z, text)
end

-- Events

RegisterNetEvent('police:client:spawnCone', function()
QBCore.Functions.Progressbar('spawn_object', Lang:t('progressbar.place_object'), 2500, false, true, {
disableMovement = true,
Expand Down Expand Up @@ -225,72 +237,59 @@ RegisterNetEvent('police:client:SyncSpikes', function(table)
end)

-- Threads

CreateThread(function()
while true do
local sleep = 1000
if LocalPlayer.state.isLoggedIn then
GetClosestSpike()
end
Wait(500)
end
end)

CreateThread(function()
while true do
if LocalPlayer.state.isLoggedIn then
if ClosestSpike then
local tires = {
{ bone = 'wheel_lf', index = 0 },
{ bone = 'wheel_rf', index = 1 },
{ bone = 'wheel_lm', index = 2 },
{ bone = 'wheel_rm', index = 3 },
{ bone = 'wheel_lr', index = 4 },
{ bone = 'wheel_rr', index = 5 }
}
sleep = 0

for a = 1, #tires do
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local tirePos = GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, tires[a].bone))
local spike = GetClosestObjectOfType(tirePos.x, tirePos.y, tirePos.z, 15.0, spikemodel, 1, 1, 1)
local spikePos = GetEntityCoords(spike, false)
local distance = #(tirePos - spikePos)
-- Vehicle Interaction (Bursting Tires)
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if vehicle and vehicle ~= 0 then
local tires = {
{ bone = 'wheel_lf', index = 0 },
{ bone = 'wheel_rf', index = 1 },
{ bone = 'wheel_lm', index = 2 },
{ bone = 'wheel_rm', index = 3 },
{ bone = 'wheel_lr', index = 4 },
{ bone = 'wheel_rr', index = 5 }
}

if distance < 1.8 then
if not IsVehicleTyreBurst(vehicle, tires[a].index, true) or IsVehicleTyreBurst(vehicle, tires[a].index, false) then
SetVehicleTyreBurst(vehicle, tires[a].index, false, 1000.0)
for a = 1, #tires do
local tirePos = GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, tires[a].bone))
local spike = GetClosestObjectOfType(tirePos.x, tirePos.y, tirePos.z, 15.0, spikemodel, 1, 1, 1)
local spikePos = GetEntityCoords(spike, false)
local distance = #(tirePos - spikePos)

if distance < 1.8 then
if not IsVehicleTyreBurst(vehicle, tires[a].index, true) or IsVehicleTyreBurst(vehicle, tires[a].index, false) then
SetVehicleTyreBurst(vehicle, tires[a].index, false, 1000.0)
end
end
end
end
end
end

Wait(3)
end
end)

CreateThread(function()
while true do
local sleep = 1000
if LocalPlayer.state.isLoggedIn then
if ClosestSpike then
-- Ped Interaction (Deleting Spike)
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local dist = #(pos - SpawnedSpikes[ClosestSpike].coords)
if dist < 4 then
if not IsPedInAnyVehicle(PlayerPedId()) then
if PlayerJob.type == 'leo' and PlayerJob.onduty then
sleep = 0
DrawText3D(pos.x, pos.y, pos.z, Lang:t('info.delete_spike'))
if IsControlJustPressed(0, 38) then
local spike = NetToEnt(SpawnedSpikes[ClosestSpike].netid)
NetworkRegisterEntityAsNetworked(spike)
NetworkRequestControlOfEntity(spike)
SetEntityAsMissionEntity(spike)
Wait(500)
DeleteEntity(spike)
SpawnedSpikes[ClosestSpike] = nil
ClosestSpike = nil
TriggerServerEvent('police:server:SyncSpikes', SpawnedSpikes)
end
if dist < 4 and not IsPedInAnyVehicle(ped, false) then
if PlayerJob.type == 'leo' and PlayerJob.onduty then
DrawText3D(pos.x, pos.y, pos.z, Lang:t('info.delete_spike'))
if IsControlJustPressed(0, 38) then
local spike = NetToEnt(SpawnedSpikes[ClosestSpike].netid)
NetworkRegisterEntityAsNetworked(spike)
NetworkRequestControlOfEntity(spike)
SetEntityAsMissionEntity(spike)
Wait(500)
DeleteEntity(spike)
SpawnedSpikes[ClosestSpike] = nil
ClosestSpike = nil
TriggerServerEvent('police:server:SyncSpikes', SpawnedSpikes)
end
end
end
Expand Down
27 changes: 13 additions & 14 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,23 @@ Config.SecurityCameras = {
},
}

Config.EnableRadars = true -- alerts for flagged plates
Config.Radars = {
vector4(-623.44421386719, -823.08361816406, 25.25704574585, 145.0),
vector4(-652.44421386719, -854.08361816406, 24.55704574585, 325.0),
vector4(1623.0114746094, 1068.9924316406, 80.903594970703, 84.0),
vector4(-2604.8994140625, 2996.3391113281, 27.528566360474, 175.0),
vector4(2136.65234375, -591.81469726563, 94.272926330566, 318.0),
vector4(2117.5764160156, -558.51013183594, 95.683128356934, 158.0),
vector4(406.89505004883, -969.06286621094, 29.436267852783, 33.0),
vector4(657.315, -218.819, 44.06, 320.0),
vector4(2118.287, 6040.027, 50.928, 172.0),
vector4(-106.304, -1127.5530, 30.778, 230.0),
vector4(-823.3688, -1146.980, 8.0, 300.0),
vector3(1051.42, 331.11, 84.00),
vector3(544.43, -373.24, 33.14),
vector3(-2612.10, 2940.81, 16.67),
vector3(287.94, -517.44, 42.89),
vector3(2792.73, 4407.68, 48.44),
vector3(577.11, -1028.32, 37.07),
vector3(114.83, -797.89, 30.97),
vector3(74.33, -163.30, 54.67),
vector3(28.19, -971.05, 28.96),
}

Config.CarItems = {
[1] = {name = "heavyarmor", amount = 2, info = {}, type = "item", slot = 1,},
[2] = {name = "empty_evidence_bag", amount = 10, info = {}, type = "item", slot = 2,},
[3] = {name = "police_stormram", amount = 1, info = {}, type = "item", slot = 3,},
[1] = { name = 'heavyarmor', amount = 2, info = {}, type = 'item', slot = 1, },
[2] = { name = 'empty_evidence_bag', amount = 10, info = {}, type = 'item', slot = 2, },
[3] = { name = 'police_stormram', amount = 1, info = {}, type = 'item', slot = 3, },
}

Config.AuthorizedVehicles = {
Expand Down
9 changes: 7 additions & 2 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ client_scripts {
'client/interactions.lua',
'client/job.lua',
'client/heli.lua',
--'client/anpr.lua',
'client/anpr.lua',
'client/evidence.lua',
'client/objects.lua',
'client/tracker.lua'
}

server_scripts {
'@oxmysql/lib/MySQL.lua',
'server/main.lua'
'server/main.lua',
'server/commands.lua',
'server/interactions.lua',
'server/evidence.lua',
'server/objects.lua',
'server/vehicle.lua',
}

ui_page 'html/index.html'
Expand Down
3 changes: 1 addition & 2 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ local Translations = {
cuff = 'You are cuffed!',
cuffed_walk = 'You are cuffed, but you can walk',
vehicle_flagged = 'Vehicle %{vehicle} is flagged for: %{reason}',
flagged_vehicle_radar = 'Flagged vehicle spotted by radar: %{plate}',
unflag_vehicle = 'Vehicle %{vehicle} is unflagged',
tow_driver_paid = 'You paid the tow truck driver',
paid_lawyer = 'You paid a lawyer',
Expand Down Expand Up @@ -117,8 +118,6 @@ local Translations = {
officer_down = 'Officer %{lastname} | %{callsign} Down',
fine_issued = 'Fine has been issued to offender succesfully',
received_fine = 'State Debt Recovery has automatically recovered the fines owed...',
camera_speed= 'Speed camera #%{radarid} - Marked vehicle'

},
evidence = {
red_hands = 'Red hands',
Expand Down
Loading

0 comments on commit 1dd3228

Please sign in to comment.