Skip to content

Commit

Permalink
refactor(policejob): Major refactor
Browse files Browse the repository at this point in the history
* fix: style edits

* , and undo canDiscoverEvidence formatting
  • Loading branch information
mafewtm authored Nov 15, 2023
1 parent 7d04117 commit a1dd2de
Show file tree
Hide file tree
Showing 13 changed files with 588 additions and 647 deletions.
10 changes: 5 additions & 5 deletions client/anpr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local function speedRange(speed)
for k, v in pairs(Config.SpeedFines) do
if speed < v.maxspeed then
TriggerServerEvent('police:server:Radar', k)
TriggerServerEvent("InteractSound_SV:PlayOnSource", 'speedcamera', 0.25)
TriggerServerEvent('InteractSound_SV:PlayOnSource', 'speedcamera', 0.25)
break
end
end
Expand All @@ -17,7 +17,7 @@ local function handleSpeedCam(speedCam, radar)
if not cache.vehicle or cache.seat ~= -1 or GetVehicleClass(cache.vehicle) == 18 then return end
local plate = GetPlate(cache.vehicle)
local speed = GetEntitySpeed(cache.vehicle) * (Config.MPH and 2.236936 or 3.6)
local overlimit = speed - speedCam.speed
local overLimit = speed - speedCam.speed

lib.callback('police:server:isPlateFlagged', false, function(result)
if not result then return end
Expand All @@ -27,11 +27,11 @@ local function handleSpeedCam(speedCam, radar)
if street2 then
street = street .. ' | ' .. street2
end
TriggerServerEvent("police:server:FlaggedPlateTriggered", radar, plate, street)
TriggerServerEvent('police:server:FlaggedPlateTriggered', radar, plate, street)
end, plate)

if not Config.SpeedFines or overlimit < 0 then return end
speedRange(overlimit)
if not Config.SpeedFines or overLimit < 0 then return end
speedRange(overLimit)
end

CreateThread(function()
Expand Down
88 changes: 44 additions & 44 deletions client/camera.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local currentCameraIndex = 0
local createdCamera = 0
local currentCamIndex = 0
local createdCam = 0
local currentScaleform = -1

local function getCurrentTime()
Expand All @@ -11,30 +11,30 @@ local function getCurrentTime()
if minutes < 10 then
minutes = tostring(0 .. GetClockMinutes())
end
return tostring(hours .. ":" .. minutes)
return tostring(hours .. ':' .. minutes)
end

local function createInstructionalScaleform(scaleform)
scaleform = lib.requestScaleformMovie(scaleform)
PushScaleformMovieFunction(scaleform, "CLEAR_ALL")
PushScaleformMovieFunction(scaleform, 'CLEAR_ALL')
PopScaleformMovieFunctionVoid()

PushScaleformMovieFunction(scaleform, "SET_CLEAR_SPACE")
PushScaleformMovieFunction(scaleform, 'SET_CLEAR_SPACE')
PushScaleformMovieFunctionParameterInt(200)
PopScaleformMovieFunctionVoid()

PushScaleformMovieFunction(scaleform, "SET_DATA_SLOT")
PushScaleformMovieFunction(scaleform, 'SET_DATA_SLOT')
PushScaleformMovieFunctionParameterInt(1)
ScaleformMovieMethodAddParamPlayerNameString(GetControlInstructionalButton(1, 194, true))
BeginTextCommandScaleformString("STRING")
BeginTextCommandScaleformString('STRING')
AddTextComponentScaleform(Lang:t('info.close_camera'))
EndTextCommandScaleformString()
PopScaleformMovieFunctionVoid()

PushScaleformMovieFunction(scaleform, "DRAW_INSTRUCTIONAL_BUTTONS")
PushScaleformMovieFunction(scaleform, 'DRAW_INSTRUCTIONAL_BUTTONS')
PopScaleformMovieFunctionVoid()

PushScaleformMovieFunction(scaleform, "SET_BACKGROUND_COLOUR")
PushScaleformMovieFunction(scaleform, 'SET_BACKGROUND_COLOUR')
PushScaleformMovieFunctionParameterInt(0)
PushScaleformMovieFunctionParameterInt(0)
PushScaleformMovieFunctionParameterInt(0)
Expand All @@ -45,29 +45,29 @@ local function createInstructionalScaleform(scaleform)
end

local function changeSecurityCamera(x, y, z, r)
if createdCamera ~= 0 then
DestroyCam(createdCamera, false)
createdCamera = 0
if createdCam ~= 0 then
DestroyCam(createdCam, false)
createdCam = 0
end

if currentScaleform ~= -1 then
SetScaleformMovieAsNoLongerNeeded(currentScaleform)
currentScaleform = -1
end

local cam = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
local cam = CreateCam('DEFAULT_SCRIPTED_CAMERA', true)
SetCamCoord(cam, x, y, z)
SetCamRot(cam, r.x, r.y, r.z, 2)
RenderScriptCams(true, false, 0, true, true)
Wait(250)
createdCamera = cam
currentScaleform = createInstructionalScaleform("instructional_buttons")
createdCam = cam
currentScaleform = createInstructionalScaleform('instructional_buttons')
end

local function closeSecurityCamera()
DestroyCam(createdCamera, false)
DestroyCam(createdCam, false)
RenderScriptCams(false, false, 1, true, true)
createdCamera = 0
createdCam = 0
SetScaleformMovieAsNoLongerNeeded(currentScaleform)
currentScaleform = -1
ClearTimecycleModifier()
Expand All @@ -79,40 +79,40 @@ local function closeSecurityCamera()
end

-- Events
RegisterNetEvent('police:client:ActiveCamera', function(cameraId)
RegisterNetEvent('police:client:ActiveCamera', function(camId)
if GetInvokingResource() then return end
if Config.SecurityCameras.cameras[cameraId] then
if Config.SecurityCameras.cameras[camId] then
DoScreenFadeOut(250)
while not IsScreenFadedOut() do
Wait(0)
end
SendNUIMessage({
type = "enablecam",
label = Config.SecurityCameras.cameras[cameraId].label,
id = cameraId,
connected = Config.SecurityCameras.cameras[cameraId].isOnline,
type = 'enablecam',
label = Config.SecurityCameras.cameras[camId].label,
id = camId,
connected = Config.SecurityCameras.cameras[camId].isOnline,
time = getCurrentTime(),
})
local firstCamX = Config.SecurityCameras.cameras[cameraId].coords.x
local firstCamY = Config.SecurityCameras.cameras[cameraId].coords.y
local firstCamZ = Config.SecurityCameras.cameras[cameraId].coords.z
local firstCamR = Config.SecurityCameras.cameras[cameraId].r
local firstCamX = Config.SecurityCameras.cameras[camId].coords.x
local firstCamY = Config.SecurityCameras.cameras[camId].coords.y
local firstCamZ = Config.SecurityCameras.cameras[camId].coords.z
local firstCamR = Config.SecurityCameras.cameras[camId].r
SetFocusArea(firstCamX, firstCamY, firstCamZ, firstCamX, firstCamY, firstCamZ)
changeSecurityCamera(firstCamX, firstCamY, firstCamZ, firstCamR)
currentCameraIndex = cameraId
currentCamIndex = camId
DoScreenFadeIn(250)
elseif cameraId == 0 then
elseif camId == 0 then
DoScreenFadeOut(250)
while not IsScreenFadedOut() do
Wait(0)
end
closeSecurityCamera()
SendNUIMessage({
type = "disablecam",
type = 'disablecam',
})
DoScreenFadeIn(250)
else
exports.qbx_core:Notify(Lang:t("error.no_camera"), "error")
exports.qbx_core:Notify(Lang:t('error.no_camera'), 'error')
end
end)

Expand Down Expand Up @@ -143,9 +143,9 @@ RegisterNetEvent('police:client:SetCamera', function(key, isOnline)
end
end)

local function listenForCameraControls()
local function listenForCamControls()
DrawScaleformMovieFullscreen(currentScaleform, 255, 255, 255, 255, 0)
SetTimecycleModifier("scanline_cam_cheap")
SetTimecycleModifier('scanline_cam_cheap')
SetTimecycleModifierStrength(1.0)

if Config.SecurityCameras.hideradar then
Expand All @@ -160,50 +160,50 @@ local function listenForCameraControls()
end
closeSecurityCamera()
SendNUIMessage({
type = "disablecam",
type = 'disablecam',
})
DoScreenFadeIn(250)
end

---------------------------------------------------------------------------
-- CAMERA ROTATION CONTROLS
---------------------------------------------------------------------------
if Config.SecurityCameras.cameras[currentCameraIndex].canRotate then
local getCameraRot = GetCamRot(createdCamera, 2)
if Config.SecurityCameras.cameras[currentCamIndex].canRotate then
local getCamRot = GetCamRot(createdCam, 2)

-- ROTATE UP
if IsControlPressed(0, 32) then
if getCameraRot.x <= 0.0 then
SetCamRot(createdCamera, getCameraRot.x + 0.7, 0.0, getCameraRot.z, 2)
if getCamRot.x <= 0.0 then
SetCamRot(createdCam, getCamRot.x + 0.7, 0.0, getCamRot.z, 2)
end
end

-- ROTATE DOWN
if IsControlPressed(0, 8) then
if getCameraRot.x >= -50.0 then
SetCamRot(createdCamera, getCameraRot.x - 0.7, 0.0, getCameraRot.z, 2)
if getCamRot.x >= -50.0 then
SetCamRot(createdCam, getCamRot.x - 0.7, 0.0, getCamRot.z, 2)
end
end

-- ROTATE LEFT
if IsControlPressed(0, 34) then
SetCamRot(createdCamera, getCameraRot.x, 0.0, getCameraRot.z + 0.7, 2)
SetCamRot(createdCam, getCamRot.x, 0.0, getCamRot.z + 0.7, 2)
end

-- ROTATE RIGHT
if IsControlPressed(0, 9) then
SetCamRot(createdCamera, getCameraRot.x, 0.0, getCameraRot.z - 0.7, 2)
SetCamRot(createdCam, getCamRot.x, 0.0, getCamRot.z - 0.7, 2)
end
end
end

-- Threads
CreateThread(function()
while true do
if createdCamera == 0 or currentScaleform == -1 then
if createdCam == 0 or currentScaleform == -1 then
Wait(2000)
else
listenForCameraControls()
listenForCamControls()
Wait(0)
end
end
Expand Down
18 changes: 9 additions & 9 deletions client/evidence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local statusList = {
confused = Lang:t('evidence.confused'),
alcohol = Lang:t('evidence.alcohol'),
heavyalcohol = Lang:t('evidence.heavy_alcohol'),
agitated = Lang:t('evidence.agitated')
agitated = Lang:t('evidence.agitated'),
}

local ignoredWeapons = {
Expand Down Expand Up @@ -92,7 +92,7 @@ end)

RegisterNetEvent('evidence:client:ClearBlooddropsInArea', function()
local pos = GetEntityCoords(cache.ped)
local blooddropList = {}
local bloodDropList = {}
if lib.progressCircle({
duration = 5000,
position = 'bottom',
Expand All @@ -103,17 +103,17 @@ RegisterNetEvent('evidence:client:ClearBlooddropsInArea', function()
move = false,
car = false,
combat = true,
mouse = false,
mouse = false
}
})
then
if bloodDrops and next(bloodDrops) then
for bloodId in pairs(bloodDrops) do
if #(pos - bloodDrops[bloodId].coords) < 10.0 then
blooddropList[#blooddropList + 1] = bloodId
bloodDropList[#bloodDropList + 1] = bloodId
end
end
TriggerServerEvent('evidence:server:ClearBlooddrops', blooddropList)
TriggerServerEvent('evidence:server:ClearBlooddrops', bloodDropList)
exports.qbx_core:Notify(Lang:t('success.blood_clear'), 'success')
end
else
Expand Down Expand Up @@ -299,10 +299,10 @@ end)

local function canDiscoverEvidence()
return IsLoggedIn
and QBX.PlayerData.job.type == 'leo'
and QBX.PlayerData.job.onduty
and IsPlayerFreeAiming(cache.playerId)
and cache.weapon == `WEAPON_FLASHLIGHT`
and QBX.PlayerData.job.type == 'leo'
and QBX.PlayerData.job.onduty
and IsPlayerFreeAiming(cache.playerId)
and cache.weapon == `WEAPON_FLASHLIGHT`
end

---@param evidence table<number, {coords: vector3}>
Expand Down
Loading

0 comments on commit a1dd2de

Please sign in to comment.