From 3aa4e5f0135ba53ff7788c3125f826681ee38e0a Mon Sep 17 00:00:00 2001 From: shanruto Date: Mon, 18 Dec 2023 20:57:23 +0100 Subject: [PATCH 1/2] fix: add proper zones, remove bossmenu --- client/main.lua | 321 ++++++++++++++++++++-------------------------- config/client.lua | 13 +- locales/en.lua | 49 ++++--- 3 files changed, 170 insertions(+), 213 deletions(-) diff --git a/client/main.lua b/client/main.lua index 0498088..9d8d939 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,16 +1,16 @@ -- Variables local config = require 'config.client' local sharedConfig = require 'config.shared' +local isLoggedIn = LocalPlayer.state.isLoggedIn local meterIsOpen = false local meterActive = false local lastLocation = nil local mouseActive = false +local garageZone, taxiParkingZone = nil, nil -- used for polyzones local isInsidePickupZone = false local isInsideDropZone = false -local isPlayerInsideCabZone = false -local isPlayerInsideBossZone = false local meterData = { fareAmount = 6, @@ -34,27 +34,6 @@ local NpcData = { local taxiPed = nil -local function setupTarget() - CreateThread(function() - lib.requestModel(`a_m_m_indian_01`) - taxiPed = CreatePed(3, `a_m_m_indian_01`, 901.34, -170.06, 74.08 - 1.0, 228.81, false, true) - SetBlockingOfNonTemporaryEvents(taxiPed, true) - TaskPlayAnim(taxiPed, 'abigail_mcs_1_concat-0', 'csb_abigail_dual-0', 8.0, 8.0, -1, 1, 0, false, false, false) - TaskStartScenarioInPlace(taxiPed, 'WORLD_HUMAN_AA_COFFEE', 0, false) - FreezeEntityPosition(taxiPed, true) - SetEntityInvincible(taxiPed, true) - exports.ox_target:addLocalEntity(taxiPed, { - { - type = 'client', - event = 'qb-taxijob:client:requestcab', - icon = 'fas fa-sign-in-alt', - label = Lang:t('info.request_taxi'), - job = 'taxi', - } - }) - end) -end - local function resetNpcTask() NpcData = { Active = false, @@ -295,104 +274,6 @@ local function calculateFareAmount() end end -local function onEnterCabBossZone() - if QBX.PlayerData.job.name ~= 'taxi' and QBX.PlayerData.job.isboss and config.useTarget then return end - isPlayerInsideBossZone = true - CreateThread(function() - while isPlayerInsideBossZone do - local pos = GetEntityCoords(cache.ped) - if #(pos - config.bossMenu) < 2.0 then - DrawText3D(config.bossMenu.x, config.bossMenu.y, config.bossMenu.z, Lang:t('menu.boss_menu')) - if IsControlJustReleased(0, 38) then - TriggerEvent('qb-bossmenu:client:OpenMenu') - end - end - Wait(0) - end - end) -end - -local function onExitCabBossZone() - lib.hideTextUI() - isPlayerInsideBossZone = false -end - -local function setupCabBossLocation() - lib.zones.box({ - coords = vec3(config.bossMenu.x, config.bossMenu.y, config.bossMenu.z), - size = vec3(2.5, 2.5, 2.5), - rotation = 45, - debug = config.debugPoly, - onEnter = onEnterCabBossZone, - onExit = onExitCabBossZone - }) -end - -AddEventHandler('onResourceStop', function(resourceName) - if resourceName ~= GetCurrentResourceName() or table.type(QBX.PlayerData) == 'empty' or not config.useTarget then return end - if config.useTarget then - DeletePed(taxiPed) - end -end) - -AddEventHandler('onResourceStart', function(resourceName) - if resourceName ~= GetCurrentResourceName() or table.type(QBX.PlayerData) == 'empty' or not config.useTarget then return end - if LocalPlayer.state.isLoggedIn then - if QBX.PlayerData.job.name == 'taxi' then - setupCabParkingLocation() - if QBX.PlayerData.job.isboss then - setupCabBossLocation() - end - end - end - if config.useTarget then - setupTarget() - end -end) - -RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() - if config.useTarget then - setupTarget() - end - if QBX.PlayerData.job.name == 'taxi' then - - setupCabParkingLocation() - if QBX.PlayerData.job.isboss then - setupCabBossLocation() - end - end -end) - -local function taxiGarage() - local registeredMenu = { - id = 'garages_depotlist', - title = Lang:t('menu.taxi_menu_header'), - options = {} - } - local options = {} - for _, v in pairs(config.allowedVehicles) do - - options[#options + 1] = { - title = v.label, - description = Lang:t('info.take_vehicle', { model = v.label }), - event = 'qb-taxi:client:TakeVehicle', - args = {model = v.model} - } - end - if QBX.PlayerData.job.name == 'taxi' and QBX.PlayerData.job.isboss and config.useTarget then - - options[#options + 1] = { - title = Lang:t('menu.boss_menu'), - description = 'Boss Menu', - event = 'qb-bossmenu:client:forceMenu' - } - end - - registeredMenu['options'] = options - lib.registerContext(registeredMenu) - lib.showContext('garages_depotlist') -end - local function onEnterDropZone() if whitelistedVehicle() and not isInsideDropZone and NpcData.NpcTaken then isInsideDropZone = true @@ -461,76 +342,130 @@ function dropNpcPoly() end) end -local function nonTargetEnter() - CreateThread(function() - while isPlayerInsideCabZone do - DrawMarker(2, config.location.x, config.location.y, config.location.z, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.3, 0.5, 0.2, 200, 0, 0, 222, false, false, 0, true, nil, nil, false) - if whitelistedVehicle() then - DrawText3D(config.location.x, config.location.y, config.location.z + 0.3, Lang:t('info.vehicle_parking')) - if IsControlJustReleased(0, 38) then - if cache.vehicle then - DeleteVehicle(cache.vehicle) - end - end - else - DrawText3D(config.location.x, config.location.y, config.location.z + 0.3, Lang:t('info.job_vehicles')) - if IsControlJustReleased(0, 38) then - taxiGarage() - end +local function setLocationsBlip() + if not config.useBlips then return end + local taxiBlip = AddBlipForCoord(config.locations.main.coords.x, config.locations.main.coords.y, config.locations.main.coords.z) + SetBlipSprite(taxiBlip, 198) + SetBlipDisplay(taxiBlip, 4) + SetBlipScale(taxiBlip, 0.6) + SetBlipAsShortRange(taxiBlip, true) + SetBlipColour(taxiBlip, 5) + BeginTextCommandSetBlipName('STRING') + AddTextComponentSubstringPlayerName(Lang:t('info.blip_name')) + EndTextCommandSetBlipName(taxiBlip) +end + +local function taxiGarage() + local registeredMenu = { + id = 'garages_depotlist', + title = Lang:t('menu.taxi_menu_header'), + options = {} + } + local options = {} + for _, v in pairs(config.allowedVehicles) do + + options[#options + 1] = { + title = v.label, + event = 'qb-taxi:client:TakeVehicle', + args = {model = v.model}, + icon = 'fa-solid fa-taxi' + } + end + + registeredMenu['options'] = options + lib.registerContext(registeredMenu) + lib.showContext('garages_depotlist') +end + +local function setupGarageZone() + if config.useTarget then + lib.requestModel(`a_m_m_indian_01`) + taxiPed = CreatePed(3, `a_m_m_indian_01`, 894.93, -179.12, 74.7 - 1.0, 237.09, false, true) + SetBlockingOfNonTemporaryEvents(taxiPed, true) + FreezeEntityPosition(taxiPed, true) + SetEntityInvincible(taxiPed, true) + exports.ox_target:addLocalEntity(taxiPed, { + { + type = 'client', + event = 'qb-taxijob:client:requestcab', + icon = 'fa-solid fa-taxi', + label = Lang:t('info.request_taxi_target'), + job = 'taxi', + } + }) + else + local function onEnter() + if not cache.vehicle then + lib.showTextUI(Lang:t('info.request_taxi')) end - Wait(0) end - end) -end -local function onEnterCabZone() - if QBX.PlayerData.job.name ~= 'taxi' then return end - isPlayerInsideCabZone = true - CreateThread(function() - while isPlayerInsideCabZone do - if IsControlJustReleased(0, 38) then - local cab = cache.vehicle + local function onExit() + lib.hideTextUI() + end + + local function inside() + if IsControlJustPressed(0, 38) then lib.hideTextUI() - if whitelistedVehicle() then - if meterIsOpen then - TriggerEvent('qb-taxi:client:toggleMeter') - meterActive = false - end - TaskLeaveVehicle(cache.ped, cache.vehicle, 0) - Wait(2000) -- 2 second delay just to ensure the player is out of the vehicle - DeleteVehicle(cab) - exports.qbx_core:Notify(Lang:t('info.taxi_returned'), 'success') - end + taxiGarage() + return end - Wait(0) end - end) - if config.useTarget then - if whitelistedVehicle() then - lib.showTextUI(Lang:t('info.vehicle_parking'), {position = 'left-center'}) - end - else - nonTargetEnter() + garageZone = lib.zones.box({ + coords = config.locations.garage.coords, + size = vec3(1.6, 4.0, 2.8), + rotation = 328.5, + debug = config.debugPoly, + inside = inside, + onEnter = onEnter, + onExit = onExit + }) end end -local function onExitCabZone() - lib.hideTextUI() - isPlayerInsideCabZone = false +local function destroyGarageZone() + if not garageZone then return end + + garageZone:remove() + garageZone = nil end -function setupCabParkingLocation() - lib.zones.box({ - coords = vec3(config.location.x, config.location.y, config.location.z), +function setupTaxiParkingZone() + taxiParkingZone = lib.zones.box({ + coords = vec3(config.locations.main.coords.x, config.locations.main.coords.y, config.locations.main.coords.z), size = vec3(4.0, 4.0, 4.0), rotation = 55, debug = config.debugPoly, - onEnter = onEnterCabZone, - onExit = onExitCabZone + inside = function() + if QBX.PlayerData.job.name ~= 'taxi' then return end + if IsControlJustPressed(0, 38) then + if whitelistedVehicle() then + if meterIsOpen then + TriggerEvent('qb-taxi:client:toggleMeter') + meterActive = false + end + DeleteVehicle(cache.vehicle) + exports.qbx_core:Notify(Lang:t('info.taxi_returned'), 'success') + end + end + end, + onEnter = function() + lib.showTextUI(Lang:t('info.vehicle_parking')) + end, + onExit = function() + lib.hideTextUI() + end }) end +local function destroyTaxiParkingZone() + if not taxiParkingZone then return end + + taxiParkingZone:remove() + taxiParkingZone = nil +end + RegisterNetEvent('qb-taxi:client:TakeVehicle', function(data) local SpawnPoint = getVehicleSpawnPoint() if SpawnPoint then @@ -711,18 +646,6 @@ RegisterNUICallback('hideMouse', function(_, cb) end) -- Threads -CreateThread(function() - local taxiBlip = AddBlipForCoord(config.location.x, config.location.y, config.location.z) - SetBlipSprite (taxiBlip, 198) - SetBlipDisplay(taxiBlip, 4) - SetBlipScale (taxiBlip, 0.6) - SetBlipAsShortRange(taxiBlip, true) - SetBlipColour(taxiBlip, 5) - BeginTextCommandSetBlipName('STRING') - AddTextComponentSubstringPlayerName(Lang:t('info.blip_name')) - EndTextCommandSetBlipName(taxiBlip) -end) - CreateThread(function() while true do Wait(2000) @@ -744,3 +667,31 @@ CreateThread(function() Wait(200) end end) + +local function init() + if QBX.PlayerData.job.name == 'taxi' then + setupGarageZone() + setupTaxiParkingZone() + setLocationsBlip() + end +end + +RegisterNetEvent('QBCore:Client:OnJobUpdate', function() + destroyGarageZone() + destroyTaxiParkingZone() + init() +end) + +RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() + isLoggedIn = true + init() +end) + +RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() + isLoggedIn = false +end) + +CreateThread(function() + if not isLoggedIn then return end + init() +end) \ No newline at end of file diff --git a/config/client.lua b/config/client.lua index 9fd0e60..c680008 100644 --- a/config/client.lua +++ b/config/client.lua @@ -1,15 +1,22 @@ return { useTarget = GetConvar('UseTarget', 'false') == 'true', debugPoly = false, + useBlips = true, allowedVehicles = { - { model = 'taxi', label = Lang:t('info.taxi_label_1') }, + { model = 'taxi', label = Lang:t('info.taxi_label_1') } }, meter = { defaultPrice = 125.0, -- price per mile startingPrice = 0 -- static starting price }, - bossMenu = vec3(903.32, -170.55, 74.0), - location = vec4(909.5, -177.35, 74.22, 238.5), + locations = { + main = { + coords = vec4(909.5, -177.35, 74.22, 238.5), + }, + garage = { + coords = vec3(895.3, -179.35, 75.0), + } + }, pzLocations = { takeLocations = { { coord = vec3(258.98, -377.9, 44.7), height = 17.6, width = 4.2, heading = 69, minZ = 43.75, maxZ = 45.55 }, diff --git a/locales/en.lua b/locales/en.lua index 33a851d..42dbaad 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -1,36 +1,35 @@ local Translations = { error = { - ["already_mission"] = "You Are Already Doing An NPC Mission", - ["not_in_taxi"] = "You Are Not In A Taxi", - ["missing_meter"] = "This Vehicle Has No Taxi Meter", - ["no_vehicle"] = "You're not in a vehicle", - ["not_active_meter"] = "The Taxi Meter Is Not Active", - ["no_meter_sight"] = "No Taxi Meter In Sight", + already_mission = 'You Are Already Doing An NPC Mission', + not_in_taxi = 'You Are Not In A Taxi', + missing_meter = 'This Vehicle Has No Taxi Meter', + no_vehicle = 'You\'re not in a vehicle', + not_active_meter = 'The Taxi Meter Is Not Active', + no_meter_sight = 'No Taxi Meter In Sight', }, success = {}, info = { - ["person_was_dropped_off"] = "Person Was Dropped Off!", - ["npc_on_gps"] = "The NPC Is Indicated On Your GPS", - ["go_to_location"] = "Bring The NPC To The Specified Location", - ["vehicle_parking"] = "[E] Vehicle Parking", - ["job_vehicles"] = "[E] Job Vehicles", - ["drop_off_npc"] = "[E] Drop Off NPC", - ["call_npc"] = "[E] Call NPC", - ["blip_name"] = "Downtown Cab", - ["taxi_label_1"] = "Standard Cab", - ["no_spawn_point"] = "Unable to find a location to bring the cab", - ["taxi_returned"] = "Cab Parked", - ["request_taxi"] = "🚕 Request Taxi Cab", - ["take_vehicle"] = "Take our " + person_was_dropped_off = 'Person Was Dropped Off!', + npc_on_gps = 'The NPC Is Indicated On Your GPS', + go_to_location = 'Bring The NPC To The Specified Location', + vehicle_parking = '[E] - Vehicle Parking', + job_vehicles = '[E] - Job Vehicles', + drop_off_npc = '[E] - Drop Off NPC', + call_npc = '[E] - Call NPC', + blip_name = 'Downtown Cab', + taxi_label_1 = 'Standard Cab', + no_spawn_point = 'Unable to find a location to bring the cab', + taxi_returned = 'Cab Parked', + request_taxi = '[E] - Request Taxi Cab', + request_taxi_target = 'Request Taxi Cab', }, menu = { - ["taxi_menu_header"] = "Taxi Vehicles", - ["close_menu"] = "⬅ Close Menu", - ['boss_menu'] = "Boss Menu" + taxi_menu_header = 'Taxi Vehicles', + close_menu = '⬅ Close Menu', } } -Lang = Locale:new({ +Lang = Lang or Locale:new({ phrases = Translations, - warnOnMissing = true, -}) + warnOnMissing = true +}) \ No newline at end of file From b05bc8db62b60a153e091afc8cfb5e2691c216c0 Mon Sep 17 00:00:00 2001 From: shanruto Date: Wed, 20 Dec 2023 20:55:50 +0100 Subject: [PATCH 2/2] Update client.lua --- config/client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/client.lua b/config/client.lua index c680008..e0a86d1 100644 --- a/config/client.lua +++ b/config/client.lua @@ -1,5 +1,5 @@ return { - useTarget = GetConvar('UseTarget', 'false') == 'true', + useTarget = false, debugPoly = false, useBlips = true, allowedVehicles = {