Skip to content

Commit

Permalink
Merge pull request #21 from jeann2013/develop
Browse files Browse the repository at this point in the history
Clean code and better code
  • Loading branch information
GhzGarage authored Jan 2, 2024
2 parents cb35b2a + f530fe3 commit 60a5728
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 35 deletions.
33 changes: 20 additions & 13 deletions client/job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@ local FingerPrintSessionId = nil

function CreatePrompts()
for k,v in pairs(Config.Locations['duty']) do
exports['qbr-core']:createPrompt('duty_prompt_' .. k, v, 0xF3830D8E, 'Toggle duty status', {
exports['qbr-core']:createPrompt('duty_prompt_' .. k, v, 0xF3830D8E, Lang:t('prompt.toggle_duty_status'), {
type = 'client',
event = 'qb-policejob:ToggleDuty',
args = {},
})
end

for k,v in pairs(Config.Locations['evidence']) do
exports['qbr-core']:createPrompt('evidence_prompt_' .. k, v, 0xF3830D8E, 'Open Evidence Stash', {
exports['qbr-core']:createPrompt('evidence_prompt_' .. k, v, 0xF3830D8E, Lang:t('prompt.open_evidence_stash'), {
type = 'client',
event = 'police:client:EvidenceStashDrawer',
args = { k },
})
end

for k,v in pairs(Config.Locations['stash']) do
exports['qbr-core']:createPrompt('stash_prompt_' .. k, v, 0xF3830D8E, 'Open Personal Stash', {
exports['qbr-core']:createPrompt('stash_prompt_' .. k, v, 0xF3830D8E, Lang:t('prompt.open_personal_stash'), {
type = 'client',
event = 'police:client:OpenPersonalStash',
args = {},
})
end

for k,v in pairs(Config.Locations['armory']) do
exports['qbr-core']:createPrompt('armory_prompt_' .. k, v, 0xF3830D8E, 'Open Armory', {
exports['qbr-core']:createPrompt('armory_prompt_' .. k, v, 0xF3830D8E, Lang:t('prompt.open_armory'), {
type = 'client',
event = 'police:client:OpenArmory',
args = {},
Expand Down Expand Up @@ -91,13 +91,18 @@ local function IsArmoryWhitelist() -- being removed
end

local function SetWeaponSeries()
for k, v in pairs(Config.Items.items) do
for k, v in ipairs(Config.Items.items) do
if k < 6 then
Config.Items.items[k].info.serie = tostring(exports['qbr-core']:RandomInt(2) .. exports['qbr-core']:RandomStr(3) .. exports['qbr-core']:RandomInt(1) .. exports['qbr-core']:RandomStr(2) .. exports['qbr-core']:RandomInt(3) .. exports['qbr-core']:RandomStr(4))
local randomInt = exports['qbr-core']:RandomInt
local randomStr = exports['qbr-core']:RandomStr

local serie = tostring(randomInt(2) .. randomStr(3) .. randomInt(1) .. randomStr(2) .. randomInt(3) .. randomStr(4))
Config.Items.items[k].info.serie = serie
end
end
end


RegisterNetEvent('police:client:ImpoundVehicle', function(fullImpound, price)
local vehicle = exports['qbr-core']:GetClosestVehicle()
local bodyDamage = math.ceil(GetVehicleBodyHealth(vehicle))
Expand Down Expand Up @@ -181,20 +186,22 @@ RegisterNetEvent('police:client:OpenArmory', function()
slots = 30,
items = {}
}
-- local index = 1
for index, armoryItem in pairs(Config.Items.items) do
for i=1, #armoryItem.authorizedJobGrades do
if armoryItem.authorizedJobGrades[i] == PlayerJob.grade.level then
authorizedItems.items[index] = armoryItem
authorizedItems.items[index].slot = index
-- index = index + 1

for index, armoryItem in ipairs(Config.Items.items) do
for _, authorizedJobGrade in ipairs(armoryItem.authorizedJobGrades) do
if authorizedJobGrade == PlayerJob.grade.level then
armoryItem.slot = index
table.insert(authorizedItems.items, armoryItem)
break -- Exit the loop after finding a match
end
end
end

SetWeaponSeries()
TriggerServerEvent("inventory:server:OpenInventory", "shop", "police", authorizedItems)
end)


-- Threads

-- Toggle Duty
Expand Down
55 changes: 33 additions & 22 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,79 @@ onDuty = false
local DutyBlips = {}

-- Functions
local function CreateDutyBlips(playerId, playerLabel, playerJob, playerLocation)
local function CreateDutyBlip(playerId, playerLabel, playerJob, playerLocation)
local ped = GetPlayerPed(playerId)
local blip = GetBlipFromEntity(ped)

if not DoesBlipExist(blip) then
if NetworkIsPlayerActive(playerId) then
blip = Citizen.InvokeNative(0x30822554, ped)
else
blip = Citizen.InvokeNative(0x554D9D53F696D002, 1664425300, playerLocation.x, playerLocation.y, playerLocation.z)
end

SetBlipSprite(blip, 54149631, 1)
SetBlipScale(blip, 0.7)
Citizen.InvokeNative(0x9CB1A1623062F402, blip, playerLabel)
DutyBlips[#DutyBlips+1] = blip

table.insert(DutyBlips, blip)
end

if GetBlipFromEntity(PlayerPedId()) == blip then
-- Ensure we remove our own blip.
local playerBlip = GetBlipFromEntity(PlayerPedId())
if playerBlip and playerBlip == blip then
RemoveBlip(blip)
end
end

function LocalInput(text, number, window)
AddTextEntry('FMMC_MPM_NA', text)
DisplayOnscreenKeyboard(1, "FMMC_MPM_NA", "", windows or "", "", "", "", number or 30)
DisplayOnscreenKeyboard(1, "FMMC_MPM_NA", "", window or "", "", "", "", number or 30)

while (UpdateOnscreenKeyboard() == 0) do
while UpdateOnscreenKeyboard() == 0 do
DisableAllControlActions(0)
Wait(0)
end

if (GetOnscreenKeyboardResult()) then
local result = GetOnscreenKeyboardResult()
return result
local result = nil
if GetOnscreenKeyboardResult() then
result = GetOnscreenKeyboardResult()
end

return result
end


-- Events
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
local player = exports['qbr-core']:GetPlayerData()
PlayerJob = player.job
onDuty = player.job.onduty
isHandcuffed = false

TriggerServerEvent("QBCore:Server:SetMetaData", "ishandcuffed", false)
TriggerServerEvent("police:server:SetHandcuffStatus", false)
TriggerServerEvent("police:server:UpdateBlips")
TriggerServerEvent("police:server:UpdateCurrentCops")

if PlayerJob and PlayerJob.name ~= "police" then
if DutyBlips then
for k, v in pairs(DutyBlips) do
RemoveBlip(v)
end
end
DutyBlips = {}
ClearDutyBlips()
end

if PlayerJob and PlayerJob.name == 'police' then
CreatePrompts()
end
end)

function ClearDutyBlips()
if DutyBlips then
for _, blip in pairs(DutyBlips) do
RemoveBlip(blip)
end
DutyBlips = {}
end
end


RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
TriggerServerEvent('police:server:UpdateBlips')
TriggerServerEvent("police:server:SetHandcuffStatus", false)
Expand Down Expand Up @@ -136,7 +148,7 @@ RegisterNetEvent('police:client:UpdateBlips', function(players)
if players then
for k, data in pairs(players) do
local id = GetPlayerFromServerId(data.source)
CreateDutyBlips(id, data.label, data.job, data.location)
CreateDutyBlip(id, data.label, data.job, data.location)
end
end
end
Expand All @@ -156,15 +168,14 @@ RegisterNetEvent('police:client:policeAlert', function(coords, text)
Citizen.InvokeNative(0x662D364ABF16DE2F, blip2, GetHashKey('BLIP_MODIFIER_AREA_PULSE'))
SetBlipScale(blip, 0.8)
SetBlipScale(blip2, 2.0)
Citizen.InvokeNative(0x9CB1A1623062F402, blip, blipText)
while transG ~= 0 do
Citizen.InvokeNative(0x9CB1A1623062F402, blip, blipText)
while transG > 0 do
Wait(180 * 4)
transG = transG - 1
if transG == 0 then
RemoveBlip(blip)
return
end
end

RemoveBlip(blip)
RemoveBlip(blip2)
end)

RegisterNetEvent('police:client:SendToJail', function(time)
Expand Down
6 changes: 6 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ local Translations = {
place_object = 'Placing object..',
remove_object = 'Removing object..',
},
prompt = {
toggle_duty_status = 'Toggle duty status',
open_evidence_stash = 'Open Evidence Stash',
open_personal_stash = 'Open Personal Stash',
open_armory = 'Open Armory',
},
}

Lang = Locale:new({
Expand Down
6 changes: 6 additions & 0 deletions locales/es.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ local Translations = {
place_object = 'Colocando objeto..',
remove_object = 'Eliminando objeto..',
},
prompt = {
toggle_duty_status = 'Alternar estado de servicio',
open_evidence_stash = 'Abrir inventario de pruebas',
open_personal_stash = 'Abrir inventario personal',
open_armory = 'Abrir Armería',
},
}

if GetConvar('qbr_locale', 'en') == 'es' then
Expand Down

0 comments on commit 60a5728

Please sign in to comment.