Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: switch from utils to lib #74

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"Lua.diagnostics.globals": [
"cache",
"lib"
"lib",
"MySQL",
"QBX",
"qbx"
]
}
2 changes: 1 addition & 1 deletion client/anpr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end

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 plate = qbx.getVehiclePlate(cache.vehicle)
local speed = GetEntitySpeed(cache.vehicle) * (config.useMPH and 2.236936 or 3.6)
local overLimit = speed - speedCam.speed

Expand Down
2 changes: 0 additions & 2 deletions client/camera.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ local function closeSecurityCamera()
FreezeEntityPosition(cache.ped, false)
end

-- Events
RegisterNetEvent('police:client:ActiveCamera', function(camId)
if GetInvokingResource() then return end
if config.cameras[camId] then
Expand Down Expand Up @@ -198,7 +197,6 @@ local function listenForCamControls()
end
end

-- Threads
CreateThread(function()
while true do
if createdCam == 0 or currentScaleform == -1 then
Expand Down
6 changes: 1 addition & 5 deletions client/evidence.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-- Variables
local config = require 'config.client'
local currentStatusList = {}
local casings = {}
Expand Down Expand Up @@ -50,7 +49,6 @@ local function dnaHash(s)
return h
end

-- Events
RegisterNetEvent('evidence:client:SetStatus', function(statusId, time)
if time > 0 and statusList[statusId] then
if not currentStatusList?[statusId] or currentStatusList[statusId].time < 20 then
Expand Down Expand Up @@ -167,8 +165,6 @@ RegisterNetEvent('evidence:client:ClearCasingsInArea', function()
end
end)

-- Threads

local function updateStatus()
if not IsLoggedIn then return end
if currentStatusList and next(currentStatusList) then
Expand Down Expand Up @@ -241,7 +237,7 @@ end
---@param args DrawEvidenceIfInRangeArgs
local function drawEvidenceIfInRange(args)
if getPlayerDistanceFromCoords(args.coords) >= 1.5 then return end
DrawText3D(args.text, args.coords)
qbx.drawText3d({text = args.text, coords = args.coords})
if IsControlJustReleased(0, 47) then
TriggerServerEvent(args.serverEventOnPickup, args.evidenceId, args.metadata)
end
Expand Down
2 changes: 1 addition & 1 deletion client/heli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ local function renderVehicleInfo(vehicle)
local pos = GetEntityCoords(vehicle)
local model = GetEntityModel(vehicle)
local vehName = GetLabelText(GetDisplayNameFromVehicleModel(model))
local licensePlate = GetPlate(vehicle)
local licensePlate = qbx.getVehiclePlate(vehicle)
local speed = math.ceil(GetEntitySpeed(vehicle) * 3.6)
local street1, street2 = GetStreetNameAtCoord(pos.x, pos.y, pos.z)
local streetLabel = GetStreetNameFromHashKey(street1)
Expand Down
38 changes: 21 additions & 17 deletions client/interactions.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-- Variables
local config = require 'config.client'
local isEscorting = false

-- Functions
exports('IsHandcuffed', function()
return QBX.PlayerData.metadata.ishandcuffed
end)
Expand Down Expand Up @@ -92,7 +90,7 @@ end
local function handcuffedEscorted()
local sleep = 1000
local anim = {{dict = 'mp_arresting', anim = 'idle'}, {dict = 'mp_arrest_paired', anim = 'crook_p2_back_right'}}

if not IsLoggedIn then return sleep end
if isEscorted then
sleep = 0
Expand All @@ -111,7 +109,6 @@ local function handcuffedEscorted()
return sleep
end

-- Events
RegisterNetEvent('police:client:SetOutVehicle', function()
if not cache.vehicle then return end
TaskLeaveVehicle(cache.ped, cache.vehicle, 16)
Expand All @@ -120,7 +117,8 @@ end)
RegisterNetEvent('police:client:PutInVehicle', function()
if not QBX.PlayerData.metadata.ishandcuffed and not isEscorted then return end

local vehicle = exports.qbx_core:GetClosestVehicle()
local coords = GetEntityCoords(cache.ped)
local vehicle = lib.getClosestVehicle(coords)
if not DoesEntityExist(vehicle) then return end

for i = GetVehicleMaxNumberOfPassengers(vehicle), 0, -1 do
Expand Down Expand Up @@ -149,24 +147,26 @@ local function isTooFar(player, distance, maxDistance)
end

RegisterNetEvent('police:client:SearchPlayer', function()
local player, distance = GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
local player, _, distance = lib.getClosestPlayer(coords)
if isTooFar(player, distance) then return end
local playerId = GetPlayerServerId(player)
exports.ox_inventory:openNearbyInventory()
TriggerServerEvent('police:server:SearchPlayer', playerId)
end)

RegisterNetEvent('police:client:SeizeCash', function()
local player, distance = GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
local player, _, distance = lib.getClosestPlayer(coords)
if isTooFar(player, distance) then return end
local playerId = GetPlayerServerId(player)
TriggerServerEvent('police:server:SeizeCash', playerId)
end)

RegisterNetEvent('police:client:RobPlayer', function()
local player, distance = GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
local player, playerPed, distance = lib.getClosestPlayer(coords)
if isTooFar(player, distance) then return end
local playerPed = GetPlayerPed(player)
local playerId = GetPlayerServerId(player)
if not (IsEntityPlayingAnim(playerPed, 'missminuteman_1ig_2', 'handsup_base', 3) or IsEntityPlayingAnim(playerPed, 'mp_arresting', 'idle', 3) or isTargetDead(playerId)) then
exports.qbx_core:Notify(Lang:t('error.no_rob'), 'error')
Expand Down Expand Up @@ -207,7 +207,8 @@ RegisterNetEvent('police:client:RobPlayer', function()
end)

RegisterNetEvent('police:client:JailPlayer', function()
local player, distance = GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
local player, _, distance = lib.getClosestPlayer(coords)
if isTooFar(player, distance) then return end
local playerId = GetPlayerServerId(player)
local dialog = lib.inputDialog(Lang:t('info.jail_time_input'), {
Expand All @@ -221,7 +222,8 @@ RegisterNetEvent('police:client:JailPlayer', function()
end)

RegisterNetEvent('police:client:BillPlayer', function()
local player, distance = GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
local player, _, distance = lib.getClosestPlayer(coords)
if isTooFar(player, distance) then return end
local playerId = GetPlayerServerId(player)
local dialog = lib.inputDialog(Lang:t('info.bill'), {
Expand All @@ -235,7 +237,8 @@ RegisterNetEvent('police:client:BillPlayer', function()
end)

local function triggerIfHandsFree(eventName)
local player, distance = GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
local player, _, distance = lib.getClosestPlayer(coords)
if isTooFar(player, distance) then return end
local playerId = GetPlayerServerId(player)
if QBX.PlayerData.metadata.ishandcuffed or isEscorted then return end
Expand All @@ -255,7 +258,8 @@ RegisterNetEvent('police:client:EscortPlayer', function()
end)

RegisterNetEvent('police:client:KidnapPlayer', function()
local player, distance = GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
local player, _, distance = lib.getClosestPlayer(coords)
if isTooFar(player, distance) then return end
local playerId = GetPlayerServerId(player)
if IsPedInAnyVehicle(GetPlayerPed(player), false) or QBX.PlayerData.metadata.ishandcuffed or isEscorted then return end
Expand All @@ -264,7 +268,8 @@ end)

RegisterNetEvent('police:client:CuffPlayerSoft', function()
if IsPedRagdoll(cache.ped) then return end
local player, distance = GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
local player, _, distance = lib.getClosestPlayer(coords)
if isTooFar(player, distance, 1.5) then return end
local playerId = GetPlayerServerId(player)
if IsPedInAnyVehicle(GetPlayerPed(player), false) or cache.vehicle then
Expand All @@ -277,8 +282,8 @@ end)

RegisterNetEvent('police:client:CuffPlayer', function()
if IsPedRagdoll(cache.ped) then return end

local player, distance = GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
local player, _, distance = lib.getClosestPlayer(coords)
if isTooFar(player, distance) then return end
if exports.ox_inventory:Search('count', config.handcuffItems) == 0 then
exports.qbx_core:Notify(Lang:t('error.no_cuff'), 'error')
Expand Down Expand Up @@ -372,7 +377,6 @@ RegisterNetEvent('police:client:GetCuffed', function(playerId, isSoftcuff)
end
end)

-- Threads
CreateThread(function()
while true do
Wait(handcuffedEscorted())
Expand Down
15 changes: 5 additions & 10 deletions client/job.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-- Variables
local config = require 'config.client'
local sharedConfig = require 'config.shared'
local currentGarage = 0
Expand Down Expand Up @@ -119,13 +118,12 @@ local function takeOutVehicle(vehicleInfo)
SetVehicleFuelLevel(veh, 100.0)
if config.vehicleSettings[vehicleInfo] then
if config.vehicleSettings[vehicleInfo].extras then
SetVehicleExtras(veh, config.vehicleSettings[vehicleInfo].extras)
qbx.setVehicleExtras(veh, config.vehicleSettings[vehicleInfo].extras)
end
if config.vehicleSettings[vehicleInfo].livery then
SetVehicleLivery(veh, config.vehicleSettings[vehicleInfo].livery)
end
end
TriggerServerEvent('inventory:server:addTrunkItems', GetPlate(veh), config.carItems)
SetVehicleEngineOn(veh, true, true, false)
end

Expand Down Expand Up @@ -167,7 +165,7 @@ local function openImpoundMenu()
else
local vehicles = exports.qbx_core:GetVehiclesByName()
for _, v in pairs(result) do
local enginePercent = math.round(v.engine / 10, 0)
local enginePercent = qbx.math.round(v.engine / 10, 0)
local currentFuel = v.fuel
local vName = vehicles[v.vehicle].name

Expand Down Expand Up @@ -307,13 +305,11 @@ local function uiPrompt(promptType, id)
end)
end

--NUI Callbacks
RegisterNUICallback('closeFingerprint', function(_, cb)
SetNuiFocus(false, false)
cb('ok')
end)

--Events
RegisterNetEvent('police:client:showFingerprint', function(playerId)
openFingerprintUi()
fingerprintSessionId = playerId
Expand Down Expand Up @@ -360,7 +356,8 @@ RegisterNetEvent('police:client:CallAnim', function()
end)

RegisterNetEvent('police:client:ImpoundVehicle', function(fullImpound, price)
local vehicle = GetClosestVehicle()
local coords = GetEntityCoords(cache.ped)
local vehicle = lib.getClosestVehicle(coords)
if not DoesEntityExist(vehicle) then return end

local bodyDamage = math.ceil(GetVehicleBodyHealth(vehicle))
Expand Down Expand Up @@ -402,7 +399,7 @@ RegisterNetEvent('police:client:ImpoundVehicle', function(fullImpound, price)
},
})
then
local plate = GetPlate(vehicle)
local plate = qbx.getVehiclePlate(vehicle)
TriggerServerEvent('police:server:Impound', plate, fullImpound, price, bodyDamage, engineDamage, totalFuel)
DeleteVehicle(vehicle)
exports.qbx_core:Notify(Lang:t('success.impounded'), 'success')
Expand Down Expand Up @@ -433,8 +430,6 @@ function ToggleDuty()
TriggerServerEvent('police:server:UpdateCurrentCops')
end

-- Threads

if config.useTarget then
CreateThread(function()
for i = 1, #sharedConfig.locations.duty do
Expand Down
6 changes: 0 additions & 6 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
local config = require 'config.shared'

-- Variables
cuffType = 1
isEscorted = false
IsLoggedIn = LocalPlayer.state.isLoggedIn
local dutyBlips = {}

-- Functions
local function CreateDutyBlips(playerId, playerLabel, playerJob, playerLocation)
local ped = GetPlayerPed(playerId)
local blip = GetBlipFromEntity(ped)
Expand Down Expand Up @@ -38,7 +35,6 @@ local function CreateDutyBlips(playerId, playerLabel, playerJob, playerLocation)
end
end

-- Events
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
TriggerServerEvent('police:server:SetHandcuffStatus', false)
TriggerServerEvent('police:server:UpdateCurrentCops')
Expand Down Expand Up @@ -189,8 +185,6 @@ RegisterNetEvent('police:client:SendPoliceEmergencyAlert', function()
TriggerServerEvent('hospital:server:ambulanceAlert', Lang:t('info.officer_down', {lastname = QBX.PlayerData.charinfo.lastname, callsign = QBX.PlayerData.metadata.callsign}))
end)

-- Threads

CreateThread(function()
for _, station in pairs(config.locations.stations) do
local blip = AddBlipForCoord(station.coords.x, station.coords.y, station.coords.z)
Expand Down
1 change: 0 additions & 1 deletion client/objects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ RegisterNetEvent('police:client:SyncSpikes', function(table)
spawnedSpikes = table
end)

-- Threads
CreateThread(function()
while true do
if IsLoggedIn then
Expand Down
3 changes: 2 additions & 1 deletion client/tracker.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RegisterNetEvent('police:client:CheckDistance', function()
local player, distance = GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
local player, _, distance = lib.getClosestPlayer(coords)
if player ~= -1 and distance < 2.5 then
local playerId = GetPlayerServerId(player)
TriggerServerEvent('police:server:SetTracker', playerId)
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version '1.0.0'

shared_scripts {
'@ox_lib/init.lua',
'@qbx_core/modules/utils.lua',
'@qbx_core/modules/lib.lua',
'@qbx_core/shared/locale.lua',
'locales/en.lua',
'locales/*.lua',
Expand Down
1 change: 0 additions & 1 deletion server/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ lib.addCommand('flagplate', {
isflagged = true,
reason = table.concat(reason, ' ')
}
TriggerClientEvent('ox_lib:notify', source, {description = Lang:t('info.vehicle_flagged', {vehicle = args[1]:upper(), reason = table.concat(reason, ' ')})})
exports.qbx_core:Notify(source, Lang:t('info.vehicle_flagged', {vehicle = args[1]:upper(), reason = table.concat(reason, ' ')}), 'inform')
end)

Expand Down
4 changes: 2 additions & 2 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ lib.callback.register('police:GetImpoundedVehicles', function()
end)

lib.callback.register('qbx_policejob:server:spawnVehicle', function(source, model, coords, plate, warp)
local netId = SpawnVehicle(source, model, coords, warp)
local netId = qbx.spawnVehicle({spawnSource = source, model = model, coords = coords, warp = warp})
if not netId or netId == 0 then return end
local veh = NetworkGetEntityFromNetworkId(netId)
if not veh or veh == 0 then return end
Expand Down Expand Up @@ -241,7 +241,7 @@ RegisterNetEvent('police:server:SetPlayerOutVehicle', function(playerId)
if not exports.qbx_core:GetPlayer(src) or not escortPlayer then return end

if escortPlayer.PlayerData.metadata.ishandcuffed or escortPlayer.PlayerData.metadata.isdead or escortPlayer.PlayerData.metadata.inlaststand then

TriggerClientEvent('police:client:SetOutVehicle', escortPlayer.PlayerData.source)
else
exports.qbx_core:Notify(src, Lang:t('error.not_cuffed_dead'), 'error')
Expand Down
Loading