diff --git a/client/main.lua b/client/main.lua index 5a245560..93bb1eff 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,32 +1,7 @@ -local Keys = { - ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57, - ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177, - ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18, - ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182, - ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81, - ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70, - ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178, - ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173, - ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118 -} - -local PlayerData = {} -local HasAlreadyEnteredMarker = false -local LastStation, LastPart, LastPartNum, LastEntity -local CurrentAction = nil -local CurrentActionMsg = '' -local CurrentActionData = {} -local IsHandcuffed = false -local HandcuffTimer = {} -local DragStatus = {} -DragStatus.IsDragged = false -local hasAlreadyJoined = false -local blipsCops = {} -local isDead = false -local CurrentTask = {} -local playerInService = false -local spawnedVehicles, isInShopMenu = {}, false - +local PlayerData, CurrentActionData, handcuffTimer, dragStatus, blipsCops, currentTask, spawnedVehicles = {}, {}, {}, {}, {}, {}, {} +local HasAlreadyEnteredMarker, isDead, IsHandcuffed, hasAlreadyJoined, playerInService, isInShopMenu = false, false, false, false, false, false +local LastStation, LastPart, LastPartNum, LastEntity, CurrentAction, CurrentActionMsg +dragStatus.isDragged = false ESX = nil Citizen.CreateThread(function() @@ -53,7 +28,7 @@ end function setUniform(job, playerPed) TriggerEvent('skinchanger:getSkin', function(skin) if skin.sex == 0 then - if Config.Uniforms[job].male ~= nil then + if Config.Uniforms[job].male then TriggerEvent('skinchanger:loadClothes', skin, Config.Uniforms[job].male) else ESX.ShowNotification(_U('no_outfit')) @@ -63,7 +38,7 @@ function setUniform(job, playerPed) SetPedArmour(playerPed, 100) end else - if Config.Uniforms[job].female ~= nil then + if Config.Uniforms[job].female then TriggerEvent('skinchanger:loadClothes', skin, Config.Uniforms[job].female) else ESX.ShowNotification(_U('no_outfit')) @@ -77,7 +52,6 @@ function setUniform(job, playerPed) end function OpenCloakroomMenu() - local playerPed = PlayerPedId() local grade = PlayerData.job.grade_name @@ -111,17 +85,14 @@ function OpenCloakroomMenu() ESX.UI.Menu.CloseAll() - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'cloakroom', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'cloakroom', { title = _U('cloakroom'), align = 'top-left', elements = elements }, function(data, menu) - cleanPlayer(playerPed) if data.current.value == 'citizen_wear' then - if Config.EnableNonFreemodePeds then ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin) local isMale = skin.sex == 0 @@ -141,10 +112,8 @@ function OpenCloakroomMenu() end if Config.MaxInService ~= -1 then - ESX.TriggerServerCallback('esx_service:isInService', function(isInService) if isInService then - playerInService = false local notification = { @@ -162,7 +131,6 @@ function OpenCloakroomMenu() end end, 'police') end - end if Config.MaxInService ~= -1 and data.current.value ~= 'citizen_wear' then @@ -175,7 +143,6 @@ function OpenCloakroomMenu() if not canTakeService then ESX.ShowNotification(_U('service_max', inServiceCount, maxInService)) else - serviceOk = true playerInService = true @@ -185,7 +152,7 @@ function OpenCloakroomMenu() msg = _U('service_in_announce', GetPlayerName(PlayerId())), iconType = 1 } - + TriggerServerEvent('esx_service:notifyAllInService', notification, 'police') TriggerEvent('esx_policejob:updateBlip') ESX.ShowNotification(_U('service_in')) @@ -238,9 +205,7 @@ function OpenCloakroomMenu() TriggerEvent('esx:restoreLoadout') end) end) - end - end, function(data, menu) menu.close() @@ -264,8 +229,7 @@ function OpenArmoryMenu(station) ESX.UI.Menu.CloseAll() - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory', { title = _U('armory'), align = 'top-left', elements = elements @@ -306,7 +270,6 @@ function OpenVehicleSpawnerMenu(type, station, part, partNum) align = 'top-left', elements = elements }, function(data, menu) - if data.current.action == 'buy_vehicle' then local shopElements, shopCoords = {} @@ -411,20 +374,16 @@ function OpenVehicleSpawnerMenu(type, station, part, partNum) end, function(data2, menu2) menu2.close() end) - else ESX.ShowNotification(_U('garage_empty')) end end, type) - elseif data.current.action == 'store_garage' then StoreNearbyVehicle(playerCoords) end - end, function(data, menu) menu.close() end) - end function StoreNearbyVehicle(playerCoords) @@ -517,17 +476,13 @@ function OpenShopMenu(elements, restoreCoords, shopCoords) align = 'top-left', elements = elements }, function(data, menu) - - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_shop_confirm', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_shop_confirm', { title = _U('vehicleshop_confirm', data.current.name, data.current.price), align = 'top-left', elements = { - { label = _U('confirm_no'), value = 'no' }, - { label = _U('confirm_yes'), value = 'yes' } - } - }, function(data2, menu2) - + {label = _U('confirm_no'), value = 'no'}, + {label = _U('confirm_yes'), value = 'yes'} + }}, function(data2, menu2) if data2.current.value == 'yes' then local newPlate = exports['esx_vehicleshop']:GeneratePlate() local vehicle = GetVehiclePedIsIn(playerPed, false) @@ -540,11 +495,10 @@ function OpenShopMenu(elements, restoreCoords, shopCoords) isInShopMenu = false ESX.UI.Menu.CloseAll() - DeleteSpawnedVehicles() FreezeEntityPosition(playerPed, false) SetEntityVisible(playerPed, true) - + ESX.Game.Teleport(playerPed, restoreCoords) else ESX.ShowNotification(_U('vehicleshop_money')) @@ -554,12 +508,10 @@ function OpenShopMenu(elements, restoreCoords, shopCoords) else menu2.close() end - end, function(data2, menu2) menu2.close() end) - - end, function(data, menu) + end, function(data, menu) isInShopMenu = false ESX.UI.Menu.CloseAll() @@ -626,13 +578,7 @@ function WaitForVehicleToLoad(modelHash) while not HasModelLoaded(modelHash) do Citizen.Wait(0) - - DisableControlAction(0, Keys['TOP'], true) - DisableControlAction(0, Keys['DOWN'], true) - DisableControlAction(0, Keys['LEFT'], true) - DisableControlAction(0, Keys['RIGHT'], true) - DisableControlAction(0, 176, true) -- ENTER key - DisableControlAction(0, Keys['BACKSPACE'], true) + DisableAllControlActions(0) drawLoadingText(_U('vehicleshop_awaiting_model'), 255, 255, 255, 255) end @@ -648,7 +594,7 @@ function drawLoadingText(text, red, green, blue, alpha) SetTextOutline() SetTextCentre(true) - BeginTextCommandDisplayText("STRING") + BeginTextCommandDisplayText('STRING') AddTextComponentSubstringPlayerName(text) EndTextCommandDisplayText(0.5, 0.5) end @@ -656,36 +602,31 @@ end function OpenPoliceActionsMenu() ESX.UI.Menu.CloseAll() - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'police_actions', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'police_actions', { title = 'Police', align = 'top-left', elements = { - {label = _U('citizen_interaction'), value = 'citizen_interaction'}, - {label = _U('vehicle_interaction'), value = 'vehicle_interaction'}, - {label = _U('object_spawner'), value = 'object_spawner'} - } - }, function(data, menu) - + {label = _U('citizen_interaction'), value = 'citizen_interaction'}, + {label = _U('vehicle_interaction'), value = 'vehicle_interaction'}, + {label = _U('object_spawner'), value = 'object_spawner'} + }}, function(data, menu) if data.current.value == 'citizen_interaction' then local elements = { - {label = _U('id_card'), value = 'identity_card'}, - {label = _U('search'), value = 'body_search'}, - {label = _U('handcuff'), value = 'handcuff'}, - {label = _U('drag'), value = 'drag'}, - {label = _U('put_in_vehicle'), value = 'put_in_vehicle'}, - {label = _U('out_the_vehicle'), value = 'out_the_vehicle'}, - {label = _U('fine'), value = 'fine'}, - {label = _U('unpaid_bills'), value = 'unpaid_bills'} + {label = _U('id_card'), value = 'identity_card'}, + {label = _U('search'), value = 'body_search'}, + {label = _U('handcuff'), value = 'handcuff'}, + {label = _U('drag'), value = 'drag'}, + {label = _U('put_in_vehicle'), value = 'put_in_vehicle'}, + {label = _U('out_the_vehicle'), value = 'out_the_vehicle'}, + {label = _U('fine'), value = 'fine'}, + {label = _U('unpaid_bills'), value = 'unpaid_bills'} } - + if Config.EnableLicenses then table.insert(elements, { label = _U('license_check'), value = 'license' }) end - - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'citizen_interaction', - { + + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'citizen_interaction', { title = _U('citizen_interaction'), align = 'top-left', elements = elements @@ -714,7 +655,6 @@ function OpenPoliceActionsMenu() elseif action == 'unpaid_bills' then OpenUnpaidBillsMenu(closestPlayer) end - else ESX.ShowNotification(_U('no_players_nearby')) end @@ -724,38 +664,34 @@ function OpenPoliceActionsMenu() elseif data.current.value == 'vehicle_interaction' then local elements = {} local playerPed = PlayerPedId() - local coords = GetEntityCoords(playerPed) - local vehicle = ESX.Game.GetVehicleInDirection() - + local vehicle = ESX.Game.GetVehicleInDirection() + if DoesEntityExist(vehicle) then - table.insert(elements, {label = _U('vehicle_info'), value = 'vehicle_infos'}) - table.insert(elements, {label = _U('pick_lock'), value = 'hijack_vehicle'}) - table.insert(elements, {label = _U('impound'), value = 'impound'}) + table.insert(elements, {label = _U('vehicle_info'), value = 'vehicle_infos'}) + table.insert(elements, {label = _U('pick_lock'), value = 'hijack_vehicle'}) + table.insert(elements, {label = _U('impound'), value = 'impound'}) end - + table.insert(elements, {label = _U('search_database'), value = 'search_database'}) - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'vehicle_interaction', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_interaction', { title = _U('vehicle_interaction'), align = 'top-left', elements = elements }, function(data2, menu2) - coords = GetEntityCoords(playerPed) + local coords = GetEntityCoords(playerPed) vehicle = ESX.Game.GetVehicleInDirection() action = data2.current.value - + if action == 'search_database' then LookupVehicle() elseif DoesEntityExist(vehicle) then - local vehicleData = ESX.Game.GetVehicleProperties(vehicle) if action == 'vehicle_infos' then + local vehicleData = ESX.Game.GetVehicleProperties(vehicle) OpenVehicleInfosMenu(vehicleData) - elseif action == 'hijack_vehicle' then if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 3.0) then - TaskStartScenarioInPlace(playerPed, "WORLD_HUMAN_WELDING", 0, true) + TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_WELDING', 0, true) Citizen.Wait(20000) ClearPedTasksImmediately(playerPed) @@ -764,34 +700,32 @@ function OpenPoliceActionsMenu() ESX.ShowNotification(_U('vehicle_unlocked')) end elseif action == 'impound' then - -- is the script busy? - if CurrentTask.Busy then + if currentTask.busy then return end ESX.ShowHelpNotification(_U('impound_prompt')) - TaskStartScenarioInPlace(playerPed, 'CODE_HUMAN_MEDIC_TEND_TO_DEAD', 0, true) - - CurrentTask.Busy = true - CurrentTask.Task = ESX.SetTimeout(10000, function() + + currentTask.busy = true + currentTask.task = ESX.SetTimeout(10000, function() ClearPedTasks(playerPed) ImpoundVehicle(vehicle) Citizen.Wait(100) -- sleep the entire script to let stuff sink back to reality end) - + -- keep track of that vehicle! Citizen.CreateThread(function() - while CurrentTask.Busy do + while currentTask.busy do Citizen.Wait(1000) - + vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 3.0, 0, 71) - if not DoesEntityExist(vehicle) and CurrentTask.Busy then + if not DoesEntityExist(vehicle) and currentTask.busy then ESX.ShowNotification(_U('impound_canceled_moved')) - ESX.ClearTimeout(CurrentTask.Task) + ESX.ClearTimeout(currentTask.task) ClearPedTasks(playerPed) - CurrentTask.Busy = false + currentTask.busy = false break end end @@ -804,73 +738,55 @@ function OpenPoliceActionsMenu() end, function(data2, menu2) menu2.close() end) - elseif data.current.value == 'object_spawner' then - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'citizen_interaction', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'citizen_interaction', { title = _U('traffic_interaction'), align = 'top-left', elements = { - {label = _U('cone'), value = 'prop_roadcone02a'}, - {label = _U('barrier'), value = 'prop_barrier_work05'}, - {label = _U('spikestrips'), value = 'p_ld_stinger_s'}, - {label = _U('box'), value = 'prop_boxpile_07d'}, - {label = _U('cash'), value = 'hei_prop_cash_crate_half_full'} - } - }, function(data2, menu2) - local model = data2.current.value + {label = _U('cone'), model = 'prop_roadcone02a'}, + {label = _U('barrier'), model = 'prop_barrier_work05'}, + {label = _U('spikestrips'), model = 'p_ld_stinger_s'}, + {label = _U('box'), model = 'prop_boxpile_07d'}, + {label = _U('cash'), model = 'hei_prop_cash_crate_half_full'} + }}, function(data2, menu2) local playerPed = PlayerPedId() local coords = GetEntityCoords(playerPed) local forward = GetEntityForwardVector(playerPed) local x, y, z = table.unpack(coords + forward * 1.0) - if model == 'prop_roadcone02a' then + if data2.current.model == 'prop_roadcone02a' then z = z - 2.0 end - ESX.Game.SpawnObject(model, { - x = x, - y = y, - z = z - }, function(obj) + ESX.Game.SpawnObject(data2.current.model, {x = x, y = y, z = z}, function(obj) SetEntityHeading(obj, GetEntityHeading(playerPed)) PlaceObjectOnGroundProperly(obj) end) - end, function(data2, menu2) menu2.close() end) end - end, function(data, menu) menu.close() end) end function OpenIdentityCardMenu(player) - ESX.TriggerServerCallback('esx_policejob:getOtherPlayerData', function(data) + local elements = {} + local nameLabel = _U('name', data.name) + local jobLabel, sexLabel, dobLabel, heightLabel, idLabel - local elements = {} - local nameLabel = _U('name', data.name) - local jobLabel = nil - local sexLabel = nil - local dobLabel = nil - local heightLabel = nil - local idLabel = nil - - if data.job.grade_label ~= nil and data.job.grade_label ~= '' then + if data.job.grade_label and data.job.grade_label ~= '' then jobLabel = _U('job', data.job.label .. ' - ' .. data.job.grade_label) else jobLabel = _U('job', data.job.label) end - + if Config.EnableESXIdentity then - nameLabel = _U('name', data.firstname .. ' ' .. data.lastname) - - if data.sex ~= nil then + + if data.sex then if string.lower(data.sex) == 'm' then sexLabel = _U('sex', _U('male')) else @@ -879,78 +795,66 @@ function OpenIdentityCardMenu(player) else sexLabel = _U('sex', _U('unknown')) end - - if data.dob ~= nil then + + if data.dob then dobLabel = _U('dob', data.dob) else dobLabel = _U('dob', _U('unknown')) end - - if data.height ~= nil then + + if data.height then heightLabel = _U('height', data.height) else heightLabel = _U('height', _U('unknown')) end - - if data.name ~= nil then + + if data.name then idLabel = _U('id', data.name) else idLabel = _U('id', _U('unknown')) end - end - + local elements = { - {label = nameLabel, value = nil}, - {label = jobLabel, value = nil}, + {label = nameLabel}, + {label = jobLabel} } - + if Config.EnableESXIdentity then - table.insert(elements, {label = sexLabel, value = nil}) - table.insert(elements, {label = dobLabel, value = nil}) - table.insert(elements, {label = heightLabel, value = nil}) - table.insert(elements, {label = idLabel, value = nil}) + table.insert(elements, {label = sexLabel}) + table.insert(elements, {label = dobLabel}) + table.insert(elements, {label = heightLabel}) + table.insert(elements, {label = idLabel}) end - - if data.drunk ~= nil then - table.insert(elements, {label = _U('bac', data.drunk), value = nil}) + + if data.drunk then + table.insert(elements, {label = _U('bac', data.drunk)}) end - - if data.licenses ~= nil then - - table.insert(elements, {label = _U('license_label'), value = nil}) - + + if data.licenses then + table.insert(elements, {label = _U('license_label')}) + for i=1, #data.licenses, 1 do - table.insert(elements, {label = data.licenses[i].label, value = nil}) + table.insert(elements, {label = data.licenses[i].label}) end - end - - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'citizen_interaction', - { + + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'citizen_interaction', { title = _U('citizen_interaction'), align = 'top-left', - elements = elements, - }, function(data, menu) - - end, function(data, menu) + elements = elements + }, nil, function(data, menu) menu.close() end) - end, GetPlayerServerId(player)) - end function OpenBodySearchMenu(player) - ESX.TriggerServerCallback('esx_policejob:getOtherPlayerData', function(data) - local elements = {} for i=1, #data.accounts, 1 do - if data.accounts[i].name == 'black_money' and data.accounts[i].money > 0 then - table.insert(elements, { label = _U('confiscate_dirty', ESX.Math.Round(data.accounts[i].money)), value = 'black_money', @@ -960,10 +864,9 @@ function OpenBodySearchMenu(player) break end - end - table.insert(elements, {label = _U('guns_label'), value = nil}) + table.insert(elements, {label = _U('guns_label')}) for i=1, #data.weapons, 1 do table.insert(elements, { @@ -974,7 +877,7 @@ function OpenBodySearchMenu(player) }) end - table.insert(elements, {label = _U('inventory_label'), value = nil}) + table.insert(elements, {label = _U('inventory_label')}) for i=1, #data.inventory, 1 do if data.inventory[i].count > 0 then @@ -987,35 +890,23 @@ function OpenBodySearchMenu(player) end end - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'body_search', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'body_search', { title = _U('search'), align = 'top-left', - elements = elements, - }, - function(data, menu) - - local itemType = data.current.itemType - local itemName = data.current.value - local amount = data.current.amount - - if data.current.value ~= nil then - TriggerServerEvent('esx_policejob:confiscatePlayerItem', GetPlayerServerId(player), itemType, itemName, amount) + elements = elements + }, function(data, menu) + if data.current.value then + TriggerServerEvent('esx_policejob:confiscatePlayerItem', GetPlayerServerId(player), data.current.itemType, data.current.value, data.current.amount) OpenBodySearchMenu(player) end - end, function(data, menu) menu.close() end) - end, GetPlayerServerId(player)) - end function OpenFineMenu(player) - - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'fine', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'fine', { title = _U('fine'), align = 'top-left', elements = { @@ -1023,58 +914,46 @@ function OpenFineMenu(player) {label = _U('minor_offense'), value = 1}, {label = _U('average_offense'), value = 2}, {label = _U('major_offense'), value = 3} - } - }, function(data, menu) + }}, function(data, menu) OpenFineCategoryMenu(player, data.current.value) end, function(data, menu) menu.close() end) - end function OpenFineCategoryMenu(player, category) - ESX.TriggerServerCallback('esx_policejob:getFineList', function(fines) - local elements = {} - for i=1, #fines, 1 do + for k,fine in ipairs(fines) do table.insert(elements, { - label = fines[i].label .. ' $' .. fines[i].amount .. '', - value = fines[i].id, - amount = fines[i].amount, - fineLabel = fines[i].label + label = ('%s %s'):format(fine.label, _U('armory_item', ESX.Math.GroupDigits(fine.amount))), + value = fine.id, + amount = fine.amount, + fineLabel = fine.label }) end - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'fine_category', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'fine_category', { title = _U('fine'), align = 'top-left', - elements = elements, + elements = elements }, function(data, menu) - - local label = data.current.fineLabel - local amount = data.current.amount - menu.close() if Config.EnablePlayerManagement then - TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), 'society_police', _U('fine_total', label), amount) + TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), 'society_police', _U('fine_total', data.current.fineLabel), data.current.amount) else - TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), '', _U('fine_total', label), amount) + TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), '', _U('fine_total', data.current.fineLabel), data.current.amount) end ESX.SetTimeout(300, function() OpenFineCategoryMenu(player, category) end) - end, function(data, menu) menu.close() end) - end, category) - end function LookupVehicle() @@ -1114,13 +993,13 @@ function ShowPlayerLicense(player) end end end - + if Config.EnableESXIdentity then targetName = data.firstname .. ' ' .. data.lastname else targetName = data.name end - + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'manage_license', { title = _U('license_revoke'), @@ -1129,9 +1008,9 @@ function ShowPlayerLicense(player) }, function(data, menu) ESX.ShowNotification(_U('licence_you_revoked', data.current.label, targetName)) TriggerServerEvent('esx_policejob:message', GetPlayerServerId(player), _U('license_revoked', data.current.label)) - + TriggerServerEvent('esx_license:removeLicense', GetPlayerServerId(player), data.current.type) - + ESX.SetTimeout(300, function() ShowPlayerLicense(player) end) @@ -1146,55 +1025,44 @@ function OpenUnpaidBillsMenu(player) local elements = {} ESX.TriggerServerCallback('esx_billing:getTargetBills', function(bills) - for i=1, #bills, 1 do + for k,bill in ipairs(bills) do table.insert(elements, { - label = bills[i].label .. ' - $' .. bills[i].amount .. '', - value = bills[i].id + label = ('%s - %s'):format(bill.label, _U('armory_item', ESX.Math.GroupDigits(bill.amount))), + billId = bills[i].id }) end - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'billing', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'billing', { title = _U('unpaid_bills'), align = 'top-left', elements = elements - }, function(data, menu) - - end, function(data, menu) + }, nil, function(data, menu) menu.close() end) end, GetPlayerServerId(player)) end function OpenVehicleInfosMenu(vehicleData) - ESX.TriggerServerCallback('esx_policejob:getVehicleInfos', function(retrivedInfo) - - local elements = {} - - table.insert(elements, {label = _U('plate', retrivedInfo.plate), value = nil}) + local elements = {{label = _U('plate', retrivedInfo.plate)}} if retrivedInfo.owner == nil then - table.insert(elements, {label = _U('owner_unknown'), value = nil}) + table.insert(elements, {label = _U('owner_unknown')}) else - table.insert(elements, {label = _U('owner', retrivedInfo.owner), value = nil}) + table.insert(elements, {label = _U('owner', retrivedInfo.owner)}) end - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_infos', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_infos', { title = _U('vehicle_info'), align = 'top-left', elements = elements }, nil, function(data, menu) menu.close() end) - end, vehicleData.plate) - end function OpenGetWeaponMenu() - ESX.TriggerServerCallback('esx_policejob:getArmoryWeapons', function(weapons) local elements = {} @@ -1207,24 +1075,20 @@ function OpenGetWeaponMenu() end end - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory_get_weapon', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory_get_weapon', { title = _U('get_weapon_menu'), align = 'top-left', elements = elements }, function(data, menu) - menu.close() ESX.TriggerServerCallback('esx_policejob:removeArmoryWeapon', function() OpenGetWeaponMenu() end, data.current.value) - end, function(data, menu) menu.close() end) end) - end function OpenPutWeaponMenu() @@ -1243,26 +1107,22 @@ function OpenPutWeaponMenu() end end - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory_put_weapon', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory_put_weapon', { title = _U('put_weapon_menu'), align = 'top-left', elements = elements }, function(data, menu) - menu.close() ESX.TriggerServerCallback('esx_policejob:addArmoryWeapon', function() OpenPutWeaponMenu() end, data.current.value, true) - end, function(data, menu) menu.close() end) end function OpenBuyWeaponsMenu() - local elements = {} local playerPed = PlayerPedId() PlayerData = ESX.GetPlayerData() @@ -1270,13 +1130,11 @@ function OpenBuyWeaponsMenu() for k,v in ipairs(Config.AuthorizedWeapons[PlayerData.job.grade_name]) do local weaponNum, weapon = ESX.GetWeapon(v.weapon) local components, label = {} - local hasWeapon = HasPedGotWeapon(playerPed, GetHashKey(v.weapon), false) if v.components then for i=1, #v.components do if v.components[i] then - local component = weapon.components[i] local hasComponent = HasPedGotWeaponComponent(playerPed, GetHashKey(v.weapon), component.hash) @@ -1330,7 +1188,6 @@ function OpenBuyWeaponsMenu() align = 'top-left', elements = elements }, function(data, menu) - if data.current.hasWeapon then if #data.current.components > 0 then OpenWeaponComponentShop(data.current.components, data.current.name, menu) @@ -1343,18 +1200,15 @@ function OpenBuyWeaponsMenu() end menu.close() - OpenBuyWeaponsMenu() else ESX.ShowNotification(_U('armory_money')) end end, data.current.name, 1) end - end, function(data, menu) menu.close() end) - end function OpenWeaponComponentShop(components, weaponName, parentShop) @@ -1363,7 +1217,6 @@ function OpenWeaponComponentShop(components, weaponName, parentShop) align = 'top-left', elements = components }, function(data, menu) - if data.current.hasComponent then ESX.ShowNotification(_U('armory_hascomponent')) else @@ -1375,23 +1228,19 @@ function OpenWeaponComponentShop(components, weaponName, parentShop) menu.close() parentShop.close() - OpenBuyWeaponsMenu() else ESX.ShowNotification(_U('armory_money')) end end, weaponName, 2, data.current.componentNum) end - end, function(data, menu) menu.close() end) end function OpenGetStocksMenu() - ESX.TriggerServerCallback('esx_policejob:getStockItems', function(items) - local elements = {} for i=1, #items, 1 do @@ -1401,19 +1250,16 @@ function OpenGetStocksMenu() }) end - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'stocks_menu', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'stocks_menu', { title = _U('police_stock'), align = 'top-left', elements = elements }, function(data, menu) - local itemName = data.current.value ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'stocks_menu_get_item_count', { title = _U('quantity') }, function(data2, menu2) - local count = tonumber(data2.value) if count == nil then @@ -1426,23 +1272,17 @@ function OpenGetStocksMenu() Citizen.Wait(300) OpenGetStocksMenu() end - end, function(data2, menu2) menu2.close() end) - end, function(data, menu) menu.close() end) - end) - end function OpenPutStocksMenu() - ESX.TriggerServerCallback('esx_policejob:getPlayerInventory', function(inventory) - local elements = {} for i=1, #inventory.items, 1 do @@ -1457,19 +1297,16 @@ function OpenPutStocksMenu() end end - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'stocks_menu', - { + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'stocks_menu', { title = _U('inventory'), align = 'top-left', elements = elements }, function(data, menu) - local itemName = data.current.value ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'stocks_menu_put_item_count', { title = _U('quantity') }, function(data2, menu2) - local count = tonumber(data2.value) if count == nil then @@ -1482,22 +1319,19 @@ function OpenPutStocksMenu() Citizen.Wait(300) OpenPutStocksMenu() end - end, function(data2, menu2) menu2.close() end) - end, function(data, menu) menu.close() end) end) - end RegisterNetEvent('esx:setJob') AddEventHandler('esx:setJob', function(job) PlayerData.job = job - + Citizen.Wait(5000) TriggerServerEvent('esx_policejob:forceBlip') end) @@ -1515,7 +1349,7 @@ end) -- don't show dispatches if the player isn't in service AddEventHandler('esx_phone:cancelMessage', function(dispatchNumber) - if type(PlayerData.job.name) == 'string' and PlayerData.job.name == 'police' and PlayerData.job.name == dispatchNumber then + if PlayerData.job and PlayerData.job.name == 'police' and PlayerData.job.name == dispatchNumber then -- if esx_service is enabled if Config.MaxInService ~= -1 and not playerInService then CancelEvent() @@ -1524,38 +1358,27 @@ AddEventHandler('esx_phone:cancelMessage', function(dispatchNumber) end) AddEventHandler('esx_policejob:hasEnteredMarker', function(station, part, partNum) - if part == 'Cloakroom' then CurrentAction = 'menu_cloakroom' CurrentActionMsg = _U('open_cloackroom') CurrentActionData = {} - elseif part == 'Armory' then - CurrentAction = 'menu_armory' CurrentActionMsg = _U('open_armory') CurrentActionData = {station = station} - elseif part == 'Vehicles' then - CurrentAction = 'menu_vehicle_spawner' CurrentActionMsg = _U('garage_prompt') CurrentActionData = {station = station, part = part, partNum = partNum} - elseif part == 'Helicopters' then - CurrentAction = 'Helicopters' CurrentActionMsg = _U('helicopter_prompt') CurrentActionData = {station = station, part = part, partNum = partNum} - elseif part == 'BossActions' then - CurrentAction = 'menu_boss_actions' CurrentActionMsg = _U('open_bossmenu') CurrentActionData = {} - end - end) AddEventHandler('esx_policejob:hasExitedMarker', function(station, part, partNum) @@ -1569,7 +1392,7 @@ end) AddEventHandler('esx_policejob:hasEnteredEntityZone', function(entity) local playerPed = PlayerPedId() - if PlayerData.job ~= nil and PlayerData.job.name == 'police' and IsPedOnFoot(playerPed) then + if PlayerData.job and PlayerData.job.name == 'police' and IsPedOnFoot(playerPed) then CurrentAction = 'remove_entity' CurrentActionMsg = _U('remove_prop') CurrentActionData = {entity = entity} @@ -1618,18 +1441,15 @@ AddEventHandler('esx_policejob:handcuff', function() DisplayRadar(false) if Config.EnableHandcuffTimer then - - if HandcuffTimer.Active then - ESX.ClearTimeout(HandcuffTimer.Task) + if handcuffTimer.active then + ESX.ClearTimeout(handcuffTimer.task) end StartHandcuffTimer() end - else - - if Config.EnableHandcuffTimer and HandcuffTimer.Active then - ESX.ClearTimeout(HandcuffTimer.Task) + if Config.EnableHandcuffTimer and handcuffTimer.active then + ESX.ClearTimeout(handcuffTimer.task) end ClearPedSecondaryTask(playerPed) @@ -1640,7 +1460,6 @@ AddEventHandler('esx_policejob:handcuff', function() DisplayRadar(true) end end) - end) RegisterNetEvent('esx_policejob:unrestrain') @@ -1657,20 +1476,20 @@ AddEventHandler('esx_policejob:unrestrain', function() DisplayRadar(true) -- end timer - if Config.EnableHandcuffTimer and HandcuffTimer.Active then - ESX.ClearTimeout(HandcuffTimer.Task) + if Config.EnableHandcuffTimer and handcuffTimer.active then + ESX.ClearTimeout(handcuffTimer.task) end end end) RegisterNetEvent('esx_policejob:drag') -AddEventHandler('esx_policejob:drag', function(copID) +AddEventHandler('esx_policejob:drag', function(copId) if not IsHandcuffed then return end - DragStatus.IsDragged = not DragStatus.IsDragged - DragStatus.CopId = tonumber(copID) + dragStatus.isDragged = not dragStatus.isDragged + dragStatus.CopId = copId end) Citizen.CreateThread(function() @@ -1683,19 +1502,19 @@ Citizen.CreateThread(function() if IsHandcuffed then playerPed = PlayerPedId() - if DragStatus.IsDragged then - targetPed = GetPlayerPed(GetPlayerFromServerId(DragStatus.CopId)) + if dragStatus.isDragged then + targetPed = GetPlayerPed(GetPlayerFromServerId(dragStatus.CopId)) -- undrag if target is in an vehicle if not IsPedSittingInAnyVehicle(targetPed) then AttachEntityToEntity(playerPed, targetPed, 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true) else - DragStatus.IsDragged = false + dragStatus.isDragged = false DetachEntity(playerPed, true, false) end if IsPedDeadOrDying(targetPed, true) then - DragStatus.IsDragged = false + dragStatus.isDragged = false DetachEntity(playerPed, true, false) end @@ -1732,7 +1551,7 @@ AddEventHandler('esx_policejob:putInVehicle', function() if freeSeat then TaskWarpPedIntoVehicle(playerPed, vehicle, freeSeat) - DragStatus.IsDragged = false + dragStatus.isDragged = false end end end @@ -1753,7 +1572,7 @@ end) -- Handcuff Citizen.CreateThread(function() while true do - Citizen.Wait(1) + Citizen.Wait(0) local playerPed = PlayerPedId() if IsHandcuffed then @@ -1763,32 +1582,32 @@ Citizen.CreateThread(function() DisableControlAction(0, 257, true) -- Attack 2 DisableControlAction(0, 25, true) -- Aim DisableControlAction(0, 263, true) -- Melee Attack 1 - DisableControlAction(0, Keys['W'], true) -- W - DisableControlAction(0, Keys['A'], true) -- A - DisableControlAction(0, 31, true) -- S (fault in Keys table!) - DisableControlAction(0, 30, true) -- D (fault in Keys table!) + DisableControlAction(0, 32, true) -- W + DisableControlAction(0, 34, true) -- A + DisableControlAction(0, 31, true) -- S + DisableControlAction(0, 30, true) -- D - DisableControlAction(0, Keys['R'], true) -- Reload - DisableControlAction(0, Keys['SPACE'], true) -- Jump - DisableControlAction(0, Keys['Q'], true) -- Cover - DisableControlAction(0, Keys['TAB'], true) -- Select Weapon - DisableControlAction(0, Keys['F'], true) -- Also 'enter'? + DisableControlAction(0, 45, true) -- Reload + DisableControlAction(0, 22, true) -- Jump + DisableControlAction(0, 44, true) -- Cover + DisableControlAction(0, 37, true) -- Select Weapon + DisableControlAction(0, 23, true) -- Also 'enter'? - DisableControlAction(0, Keys['F1'], true) -- Disable phone - DisableControlAction(0, Keys['F2'], true) -- Inventory - DisableControlAction(0, Keys['F3'], true) -- Animations - DisableControlAction(0, Keys['F6'], true) -- Job + DisableControlAction(0, 288, true) -- Disable phone + DisableControlAction(0, 289, true) -- Inventory + DisableControlAction(0, 170, true) -- Animations + DisableControlAction(0, 167, true) -- Job - DisableControlAction(0, Keys['V'], true) -- Disable changing view - DisableControlAction(0, Keys['C'], true) -- Disable looking behind - DisableControlAction(0, Keys['X'], true) -- Disable clearing animation - DisableControlAction(2, Keys['P'], true) -- Disable pause screen + DisableControlAction(0, 0, true) -- Disable changing view + DisableControlAction(0, 26, true) -- Disable looking behind + DisableControlAction(0, 73, true) -- Disable clearing animation + DisableControlAction(2, 199, true) -- Disable pause screen DisableControlAction(0, 59, true) -- Disable steering in vehicle DisableControlAction(0, 71, true) -- Disable driving forward in vehicle DisableControlAction(0, 72, true) -- Disable reversing in vehicle - DisableControlAction(2, Keys['LEFTCTRL'], true) -- Disable going stealth + DisableControlAction(2, 36, true) -- Disable going stealth DisableControlAction(0, 47, true) -- Disable weapon DisableControlAction(0, 264, true) -- Disable melee @@ -1833,10 +1652,9 @@ end) -- Display markers Citizen.CreateThread(function() while true do - Citizen.Wait(0) - if PlayerData.job ~= nil and PlayerData.job.name == 'police' then + if PlayerData.job and PlayerData.job.name == 'police' then local playerPed = PlayerPedId() local coords = GetEntityCoords(playerPed) @@ -1914,9 +1732,8 @@ Citizen.CreateThread(function() end if isInMarker and not HasAlreadyEnteredMarker or (isInMarker and (LastStation ~= currentStation or LastPart ~= currentPart or LastPartNum ~= currentPartNum)) then - if - (LastStation ~= nil and LastPart ~= nil and LastPartNum ~= nil) and + (LastStation and LastPart and LastPartNum) and (LastStation ~= currentStation or LastPart ~= currentPart or LastPartNum ~= currentPartNum) then TriggerEvent('esx_policejob:hasExitedMarker', LastStation, LastPart, LastPartNum) @@ -1929,7 +1746,6 @@ Citizen.CreateThread(function() LastPartNum = currentPartNum TriggerEvent('esx_policejob:hasEnteredMarker', currentStation, currentPart, currentPartNum) - end if not hasExited and not isInMarker and HasAlreadyEnteredMarker then @@ -1944,7 +1760,6 @@ Citizen.CreateThread(function() else Citizen.Wait(500) end - end end) @@ -1987,7 +1802,7 @@ Citizen.CreateThread(function() LastEntity = closestEntity end else - if LastEntity ~= nil then + if LastEntity then TriggerEvent('esx_policejob:hasExitedEntityZone', LastEntity) LastEntity = nil end @@ -1998,13 +1813,12 @@ end) -- Key Controls Citizen.CreateThread(function() while true do - Citizen.Wait(0) - if CurrentAction ~= nil then + if CurrentAction then ESX.ShowHelpNotification(CurrentActionMsg) - if IsControlJustReleased(0, Keys['E']) and PlayerData.job ~= nil and PlayerData.job.name == 'police' then + if IsControlJustReleased(0, 38) and PlayerData.job and PlayerData.job.name == 'police' then if CurrentAction == 'menu_cloakroom' then OpenCloakroomMenu() @@ -2046,12 +1860,12 @@ Citizen.CreateThread(function() elseif CurrentAction == 'remove_entity' then DeleteEntity(CurrentActionData.entity) end - + CurrentAction = nil end end -- CurrentAction end - - if IsControlJustReleased(0, Keys['F6']) and not isDead and PlayerData.job ~= nil and PlayerData.job.name == 'police' and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'police_actions') then + + if IsControlJustReleased(0, 167) and not isDead and PlayerData.job and PlayerData.job.name == 'police' and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'police_actions') then if Config.MaxInService == -1 then OpenPoliceActionsMenu() elseif playerInService then @@ -2060,13 +1874,13 @@ Citizen.CreateThread(function() ESX.ShowNotification(_U('service_not')) end end - - if IsControlJustReleased(0, Keys['E']) and CurrentTask.Busy then + + if IsControlJustReleased(0, 38) and currentTask.busy then ESX.ShowNotification(_U('impound_canceled')) - ESX.ClearTimeout(CurrentTask.Task) + ESX.ClearTimeout(currentTask.task) ClearPedTasks(PlayerPedId()) - - CurrentTask.Busy = false + + currentTask.busy = false end end end) @@ -2084,19 +1898,19 @@ function createBlip(id) SetBlipNameToPlayerName(blip, id) -- update blip name SetBlipScale(blip, 0.85) -- set scale SetBlipAsShortRange(blip, true) - + table.insert(blipsCops, blip) -- add blip to array so we can remove it later end end RegisterNetEvent('esx_policejob:updateBlip') AddEventHandler('esx_policejob:updateBlip', function() - + -- Refresh all blips for k, existingBlip in pairs(blipsCops) do RemoveBlip(existingBlip) end - + -- Clean the blip table blipsCops = {} @@ -2108,9 +1922,9 @@ AddEventHandler('esx_policejob:updateBlip', function() if not Config.EnableJobBlip then return end - + -- Is the player a cop? In that case show all the blips for other cops - if PlayerData.job ~= nil and PlayerData.job.name == 'police' then + if PlayerData.job and PlayerData.job.name == 'police' then ESX.TriggerServerCallback('esx_society:getOnlinePlayers', function(players) for i=1, #players, 1 do if players[i].job.name == 'police' then @@ -2128,7 +1942,7 @@ end) AddEventHandler('playerSpawned', function(spawn) isDead = false TriggerEvent('esx_policejob:unrestrain') - + if not hasAlreadyJoined then TriggerServerEvent('esx_policejob:spawned') end @@ -2148,24 +1962,24 @@ AddEventHandler('onResourceStop', function(resource) TriggerServerEvent('esx_service:disableService', 'police') end - if Config.EnableHandcuffTimer and HandcuffTimer.Active then - ESX.ClearTimeout(HandcuffTimer.Task) + if Config.EnableHandcuffTimer and handcuffTimer.active then + ESX.ClearTimeout(handcuffTimer.task) end end end) -- handcuff timer, unrestrain the player after an certain amount of time function StartHandcuffTimer() - if Config.EnableHandcuffTimer and HandcuffTimer.Active then - ESX.ClearTimeout(HandcuffTimer.Task) + if Config.EnableHandcuffTimer and handcuffTimer.active then + ESX.ClearTimeout(handcuffTimer.task) end - HandcuffTimer.Active = true + handcuffTimer.active = true - HandcuffTimer.Task = ESX.SetTimeout(Config.HandcuffTimer, function() + handcuffTimer.task = ESX.SetTimeout(Config.handcuffTimer, function() ESX.ShowNotification(_U('unrestrained_timer')) TriggerEvent('esx_policejob:unrestrain') - HandcuffTimer.Active = false + handcuffTimer.active = false end) end @@ -2174,7 +1988,7 @@ end -- - message owner that his vehicle has been impounded function ImpoundVehicle(vehicle) --local vehicleName = GetLabelText(GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))) - ESX.Game.DeleteVehicle(vehicle) + ESX.Game.DeleteVehicle(vehicle) ESX.ShowNotification(_U('impound_successful')) - CurrentTask.Busy = false + currentTask.busy = false end diff --git a/server/main.lua b/server/main.lua index b4898a9b..fb356401 100644 --- a/server/main.lua +++ b/server/main.lua @@ -26,7 +26,7 @@ AddEventHandler('esx_policejob:confiscatePlayerItem', function(target, itemType, -- does the target player have enough in their inventory? if targetItem.count > 0 and targetItem.count <= amount then - + -- can the player carry the said amount of x item? if sourceItem.limit ~= -1 and (sourceItem.count + amount) > sourceItem.limit then TriggerClientEvent('esx:showNotification', _source, _U('quantity_invalid')) @@ -112,7 +112,7 @@ AddEventHandler('esx_policejob:getStockItem', function(itemName, count) -- is there enough in the society? if count > 0 and inventoryItem.count >= count then - + -- can the player carry the said amount of x item? if sourceItem.limit ~= -1 and (sourceItem.count + count) > sourceItem.limit then TriggerClientEvent('esx:showNotification', _source, _U('quantity_invalid')) @@ -513,24 +513,24 @@ end) AddEventHandler('playerDropped', function() -- Save the source in case we lose it (which happens a lot) local _source = source - + -- Did the player ever join? if _source ~= nil then local xPlayer = ESX.GetPlayerFromId(_source) - + -- Is it worth telling all clients to refresh? if xPlayer ~= nil and xPlayer.job ~= nil and xPlayer.job.name == 'police' then Citizen.Wait(5000) TriggerClientEvent('esx_policejob:updateBlip', -1) end - end + end end) RegisterServerEvent('esx_policejob:spawned') AddEventHandler('esx_policejob:spawned', function() local _source = source local xPlayer = ESX.GetPlayerFromId(_source) - + if xPlayer ~= nil and xPlayer.job ~= nil and xPlayer.job.name == 'police' then Citizen.Wait(5000) TriggerClientEvent('esx_policejob:updateBlip', -1)