From 249b9394a4370b63391c86f726bd7aa44c62a426 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Wed, 13 Sep 2023 22:56:30 +0200 Subject: [PATCH 1/4] chore: (esx_drivingschooljob) initial changes --- .../esx_drivingschooljob/client/main.lua | 69 ++++++++----------- 1 file changed, 27 insertions(+), 42 deletions(-) diff --git a/server-data/resources/[esx_addons]/esx_drivingschooljob/client/main.lua b/server-data/resources/[esx_addons]/esx_drivingschooljob/client/main.lua index 1f968bf4f..7f65e7fbd 100644 --- a/server-data/resources/[esx_addons]/esx_drivingschooljob/client/main.lua +++ b/server-data/resources/[esx_addons]/esx_drivingschooljob/client/main.lua @@ -10,29 +10,19 @@ local Keys = { ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118 } -local PlayerData = {} -local GUI = {} + local HasAlreadyEnteredMarker = false local LastZone = nil local CurrentAction = nil local CurrentActionMsg = '' local CurrentActionData = {} -local TargetCoords = nil -local Blips = {} local Licenses = {} local CurrentTest = nil -local CurrentTestType = nil - +local GUI = {} ESX = nil GUI.Time = 0 -CreateThread(function() - ESX = exports["es_extended"]:getSharedObject() - while ESX.GetPlayerData().job == nil do - Wait(10) - end - ESX.PlayerData = ESX.GetPlayerData() -end) +ESX = exports["es_extended"]:getSharedObject() function OpenDrivingSchoolMenu() ESX.UI.Menu.CloseAll() @@ -48,16 +38,16 @@ function OpenDrivingSchoolMenu() if data.current.value == 'give' then local elements = { - {label = _U('traffic_give'), value = 'trg'}} + {label = _U('traffic_give'), value = 'trg'}} if ESX.PlayerData.job.grade_name == 'examiner' then table.insert(elements, {label = _U('car_give'), value = 'carg'}) end - + if ESX.PlayerData.job.grade_name == 'examiner' then table.insert(elements, {label = _U('motor_give'), value = 'motg'}) end - + if ESX.PlayerData.job.grade_name == 'examiner' then table.insert(elements, {label = _U('truck_give'), value = 'truckg'}) end @@ -93,11 +83,11 @@ elseif data.current.value == 'remove' then if ESX.PlayerData.job.grade_name == 'carinstr' or ESX.PlayerData.job.grade_name == 'examiner' then table.insert(elements, {label = _U('car_remove'), value = 'carr'}) end - + if ESX.PlayerData.job.grade_name == 'motorinstr' or ESX.PlayerData.job.grade_name == 'examiner' then table.insert(elements, {label = _U('motor_remove'), value = 'motr'}) end - + if ESX.PlayerData.job.grade_name == 'truckinstr' or ESX.PlayerData.job.grade_name == 'examiner' then table.insert(elements, {label = _U('truck_remove'), value = 'truckrr'}) end @@ -124,13 +114,13 @@ ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'remove', { else ESX.ShowNotification(_U('no_players_nearby')) end - end, function(data2, menu2) + end, function(_, menu2) menu2.close() end) elseif data.current.value == 'bill' then OpenBillingMenu() end -end, function(data, menu) +end, function(_, menu) menu.close() end) end @@ -140,7 +130,7 @@ function OpenBillingMenu() ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'bil', { title = 'billing_amount' }, function(data, menu) - + local amount = tonumber(data.value) local player, distance = ESX.Game.GetClosestPlayer() @@ -155,7 +145,7 @@ function OpenBillingMenu() else ESX.ShowNotification(_U('no_players_nearby')) end - end, function(data, menu) + end, function(_, menu) menu.close() end) end @@ -206,7 +196,7 @@ function OpenDMVSchoolMenu() label = (('%s: %s'):format(_U('theory_test'), _U('school_item', ESX.Math.GroupDigits(Config.TheoryPrice)))), value = 'theory_test' }) - + end ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'dmvschool_actions', { @@ -218,7 +208,7 @@ function OpenDMVSchoolMenu() menu.close() StartTheoryTest() end - end, function(data, menu) + end, function(_, menu) menu.close() CurrentAction = 'theory_menu' @@ -227,19 +217,19 @@ function OpenDMVSchoolMenu() end) end -RegisterNUICallback('question', function(data, cb) +RegisterNUICallback('question', function(_, cb) SendNUIMessage({ openSection = 'question' }) cb() end) -RegisterNUICallback('close', function(data, cb) +RegisterNUICallback('close', function(_, cb) StopTheoryTest(true) cb() end) -RegisterNUICallback('kick', function(data, cb) +RegisterNUICallback('kick', function(_, cb) StopTheoryTest(false) cb() end) @@ -257,13 +247,12 @@ function OpenDrivingActionsMenu() end ESX.UI.Menu.CloseAll() - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'driving_actions', + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'driving_actions', { title = _U('vehicle_list'), elements = elements }, - function(data, menu) + function(data) if data.current.value == 'vehicle_list' then if Config.EnableSocietyOwnedVehicles then @@ -276,8 +265,7 @@ function OpenDrivingActionsMenu() table.insert(elements, {label = GetDisplayNameFromVehicleModel(vehicles[i].model) .. ' [' .. vehicles[i].plate .. ']', value = vehicles[i]}) end - ESX.UI.Menu.Open( - 'default', GetCurrentResourceName(), 'vehicle_spawner', + ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_spawner', { title = _U('service_vehicle'), align = 'top-left', @@ -312,15 +300,15 @@ function OpenDrivingActionsMenu() {label = 'Motor', value = 'sanchez'}, {label = 'Truck', value = 'mule'} } - + if ESX.PlayerData.job.grade_name == 'carinstr' then table.insert(elements, {label = _U('car'), value = 'issi2'}) end - + if ESX.PlayerData.job.grade_name == 'motorinstr' then table.insert(elements, {label = _U('motor'), value = 'esskey'}) end - + if ESX.PlayerData.job.grade_name == 'truckinstr' then table.insert(elements, {label = _U('truck'), value = 'packer'}) end @@ -479,7 +467,7 @@ CreateThread(function() local coords = GetEntityCoords(GetPlayerPed(-1)) local isInMarker = false local currentZone = nil - + if ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'driving' then local coords = GetEntityCoords(GetPlayerPed(-1)) local isInMarker = false @@ -499,7 +487,7 @@ CreateThread(function() HasAlreadyEnteredMarker = false TriggerEvent('esx_drivingschooljob:hasExitedMarker', LastZone) end - else + else for a,v in pairs(Config.Theory) do if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then isInMarker = true @@ -549,7 +537,7 @@ CreateThread(function() SetTextComponentFormat('STRING') AddTextComponentString(CurrentActionMsg) DisplayHelpTextFromStringLabel(0, 0, 1, -1) - + if IsControlJustReleased(0, 206) then if CurrentAction == 'theory_menu' then OpenDMVSchoolMenu() @@ -561,7 +549,6 @@ CreateThread(function() if CurrentAction == 'driving_actions_menu' then OpenDrivingActionsMenu() end - if CurrentAction == 'delete_vehicle' then @@ -590,8 +577,6 @@ CreateThread(function() if IsControlJustReleased(0, Keys['F6']) and ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'driving' then OpenDrivingSchoolMenu() - else - --Citizen.Wait(100) - end + end end end) \ No newline at end of file From 37b8a63e9bcc78d684eba04aac97686788f84967 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Thu, 14 Sep 2023 19:57:57 +0200 Subject: [PATCH 2/4] chore: (esx_drivingschooljob\config.lua) improved formatting --- .../esx_drivingschooljob/config.lua | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/server-data/resources/[esx_addons]/esx_drivingschooljob/config.lua b/server-data/resources/[esx_addons]/esx_drivingschooljob/config.lua index f17877b83..4b7d68107 100644 --- a/server-data/resources/[esx_addons]/esx_drivingschooljob/config.lua +++ b/server-data/resources/[esx_addons]/esx_drivingschooljob/config.lua @@ -9,7 +9,7 @@ Config.TheoryPrice = 200 Config.Locale = 'en' Config.Zones = { - + DrivingActions = { Pos = {x = 212.584625, y = -1399.859375, z = 30.577271}, Size = {x = 1.0, y = 1.0, z = 1.0}, @@ -17,7 +17,6 @@ Config.Zones = { Type = 20 }, - VehicleDeleter = { Pos = {x = 216.87, y = -1381.1, z = 30.2}, Size = {x = 1.5, y = 1.5, z = 1.0}, @@ -35,7 +34,7 @@ Config.Zones = { } Config.Theory = { - DMVSchool = { + DMVSchool = { Pos = {x = 207.745056, y = -1384.219727, z = 30.577271}, Size = {x = 1.5, y = 1.5, z = 1.0}, Color = {r = 204, g = 204, b = 0}, @@ -44,11 +43,11 @@ Config.Theory = { } Config.Blip = { - Blip = { - Pos = {x = 212.38, y = -1397.26, z = 30.58}, - Sprite = 530, - Display = 4, - Scale = 1.2, - Colour = 29, - } + Blip = { + Pos = {x = 212.38, y = -1397.26, z = 30.58}, + Sprite = 530, + Display = 4, + Scale = 1.2, + Colour = 29, + } } \ No newline at end of file From 1abbce2400ff30d9e1a53d4c130567d521edde89 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Thu, 14 Sep 2023 19:58:33 +0200 Subject: [PATCH 3/4] fix: (esx_drivingschooljob\client\main.lua) fix lint error --- .../esx_drivingschooljob/client/main.lua | 95 +++++++++---------- 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/server-data/resources/[esx_addons]/esx_drivingschooljob/client/main.lua b/server-data/resources/[esx_addons]/esx_drivingschooljob/client/main.lua index 7f65e7fbd..21bd25dc1 100644 --- a/server-data/resources/[esx_addons]/esx_drivingschooljob/client/main.lua +++ b/server-data/resources/[esx_addons]/esx_drivingschooljob/client/main.lua @@ -19,7 +19,6 @@ local CurrentActionData = {} local Licenses = {} local CurrentTest = nil local GUI = {} -ESX = nil GUI.Time = 0 ESX = exports["es_extended"]:getSharedObject() @@ -34,29 +33,29 @@ function OpenDrivingSchoolMenu() {label = _U('give'), value = 'give'}, {label = _U('retrieve'), value = 'remove'}, {label = _U('billing'), value = 'bill'} -}}, function(data, menu) +}}, function(data) if data.current.value == 'give' then - local elements = { - {label = _U('traffic_give'), value = 'trg'}} + local elements = { + {label = _U('traffic_give'), value = 'trg'}} - if ESX.PlayerData.job.grade_name == 'examiner' then - table.insert(elements, {label = _U('car_give'), value = 'carg'}) - end + if ESX.PlayerData.job.grade_name == 'examiner' then + table.insert(elements, {label = _U('car_give'), value = 'carg'}) + end - if ESX.PlayerData.job.grade_name == 'examiner' then - table.insert(elements, {label = _U('motor_give'), value = 'motg'}) - end + if ESX.PlayerData.job.grade_name == 'examiner' then + table.insert(elements, {label = _U('motor_give'), value = 'motg'}) + end - if ESX.PlayerData.job.grade_name == 'examiner' then - table.insert(elements, {label = _U('truck_give'), value = 'truckg'}) - end + if ESX.PlayerData.job.grade_name == 'examiner' then + table.insert(elements, {label = _U('truck_give'), value = 'truckg'}) + end ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'give', { title = _U('give'), align = 'top-left', elements = elements - }, function(data2, menu2) + }, function(data2) local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() if closestPlayer ~= -1 and closestDistance <= 3.0 then local action = data2.current.value @@ -73,7 +72,7 @@ ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'give', { else ESX.ShowNotification(_U('no_players_nearby')) end - end, function(data2, menu2) + end, function(_, menu2) menu2.close() end) elseif data.current.value == 'remove' then @@ -96,7 +95,7 @@ ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'remove', { title = _U('retrieve'), align = 'top-left', elements = elements - }, function(data2, menu2) + }, function(data2) local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() if closestPlayer ~= -1 and closestDistance <= 3.0 then local action = data2.current.value @@ -111,21 +110,20 @@ ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'remove', { elseif action == 'truckr' then TriggerServerEvent('esx_license:removeLicense',GetPlayerServerId(closestplayer), 'drive_truck') end - else + else ESX.ShowNotification(_U('no_players_nearby')) - end + end end, function(_, menu2) menu2.close() end) elseif data.current.value == 'bill' then - OpenBillingMenu() + OpenBillingMenu() end end, function(_, menu) menu.close() end) end - function OpenBillingMenu() ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'bil', { title = 'billing_amount' @@ -138,15 +136,15 @@ function OpenBillingMenu() menu.close() if amount == nil then - ESX.ShowNotification(_U('amount_invalid')) + ESX.ShowNotification(_U('amount_invalid')) else - TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), 'society_driving', _U('billing'), amount) + TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), 'society_driving', _U('billing'), amount) end else ESX.ShowNotification(_U('no_players_nearby')) end end, function(_, menu) - menu.close() + menu.close() end) end @@ -286,7 +284,7 @@ function OpenDrivingActionsMenu() TriggerServerEvent('esx_society:removeVehicleFromGarage', 'driving', vehicleProps) end, - function(data, menu) + function(_, menu) menu.close() end ) @@ -294,7 +292,6 @@ function OpenDrivingActionsMenu() end, 'driving') else - local elements = { {label = 'Car', value = 'blista'}, {label = 'Motor', value = 'sanchez'}, @@ -322,7 +319,7 @@ function OpenDrivingActionsMenu() elements = elements }, function(data, menu) - for i=1, #elements, 1 do + for _ = 1, #elements, 1 do if Config.MaxInService == -1 then ESX.Game.SpawnVehicle(data.current.value, Config.Zones.VehicleSpawnPoint.Pos, 90.0, function(vehicle) local playerPed = GetPlayerPed(-1) @@ -345,7 +342,7 @@ function OpenDrivingActionsMenu() end menu.close() end, - function(data, menu) + function(_, menu) menu.close() OpenDrivingActionsMenu() end @@ -355,13 +352,13 @@ function OpenDrivingActionsMenu() end if data.current.value == 'boss_actions' then - TriggerEvent('esx_society:openBossMenu', 'driving', function(data, menu) + TriggerEvent('esx_society:openBossMenu', 'driving', function(_, menu) menu.close() end) end end, - function(data, menu) + function(_, menu) menu.close() CurrentAction = 'driving_actions_menu' CurrentActionMsg = _U('open_actions') @@ -410,7 +407,7 @@ AddEventHandler('esx_drivingschooljob:hasEnteredMarker', function(zone) end) -AddEventHandler('esx_drivingschooljob:hasExitedMarker', function(zone) +AddEventHandler('esx_drivingschooljob:hasExitedMarker', function() CurrentAction = nil ESX.UI.Menu.CloseAll() end) @@ -422,7 +419,7 @@ end) --Blip CreateThread(function() - for k,v in pairs(Config.Blip) do + for _,v in pairs(Config.Blip) do local blip = AddBlipForCoord(v.Pos.x, v.Pos.y, v.Pos.z) @@ -443,15 +440,15 @@ CreateThread(function() Wait(0) local coords = GetEntityCoords(GetPlayerPed(-1)) - for k,v in pairs(Config.Theory) do - if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then - DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false) - end + for _, v in pairs(Config.Theory) do + if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then + DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false) + end end if ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'driving' then local coords = GetEntityCoords(GetPlayerPed(-1)) - for k,v in pairs(Config.Zones) do + for _,v in pairs(Config.Zones) do if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false) end @@ -514,15 +511,15 @@ CreateThread(function() Wait(1) if CurrentTest == 'theory' then - local playerPed = PlayerPedId() + local playerPed = PlayerPedId() - DisableControlAction(0, 1, true) -- LookLeftRight - DisableControlAction(0, 2, true) -- LookUpDown - DisablePlayerFiring(playerPed, true) -- Disable weapon firing - DisableControlAction(0, 142, true) -- MeleeAttackAlternate - DisableControlAction(0, 106, true) -- VehicleMouseControlOverride + DisableControlAction(0, 1, true) -- LookLeftRight + DisableControlAction(0, 2, true) -- LookUpDown + DisablePlayerFiring(playerPed, true) -- Disable weapon firing + DisableControlAction(0, 142, true) -- MeleeAttackAlternate + DisableControlAction(0, 106, true) -- VehicleMouseControlOverride else - Wait(500) + Wait(500) end end end) @@ -530,13 +527,13 @@ end) -- Key Controls CreateThread(function() while true do - Wait(1) + Wait(1) - if CurrentAction ~= nil then + if CurrentAction ~= nil then - SetTextComponentFormat('STRING') - AddTextComponentString(CurrentActionMsg) - DisplayHelpTextFromStringLabel(0, 0, 1, -1) + SetTextComponentFormat('STRING') + AddTextComponentString(CurrentActionMsg) + DisplayHelpTextFromStringLabel(0, 0, 1, -1) if IsControlJustReleased(0, 206) then if CurrentAction == 'theory_menu' then @@ -547,7 +544,7 @@ CreateThread(function() if IsControlJustReleased(0, 38) and ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'driving' then if CurrentAction == 'driving_actions_menu' then - OpenDrivingActionsMenu() + OpenDrivingActionsMenu() end if CurrentAction == 'delete_vehicle' then From 2732c5ae50d8ad61dfb963b8c95990827cbc4604 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Thu, 14 Sep 2023 19:59:21 +0200 Subject: [PATCH 4/4] chore: (esx_drivingschooljob\server\main.lua) remove unused code --- .../resources/[esx_addons]/esx_drivingschooljob/server/main.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/server-data/resources/[esx_addons]/esx_drivingschooljob/server/main.lua b/server-data/resources/[esx_addons]/esx_drivingschooljob/server/main.lua index 02867fbed..646fe869f 100644 --- a/server-data/resources/[esx_addons]/esx_drivingschooljob/server/main.lua +++ b/server-data/resources/[esx_addons]/esx_drivingschooljob/server/main.lua @@ -1,11 +1,9 @@ -ESX = nil ESX = exports["es_extended"]:getSharedObject() if Config.MaxInService ~= -1 then TriggerEvent('esx_service:activateService', 'driving', Config.MaxInService) end --- TriggerEvent('esx_phone:registerNumber', 'driving', _U('alert_driving'), true, true) TriggerEvent('esx_society:registerSociety', 'driving', 'Driving', 'society_driving', 'society_driving', 'society_driving', {type = 'public'}) ESX.RegisterServerCallback('esx_drivingschooljob:getPlayerInventory', function(source, cb)