From 2fba7febfdee2a8d60517b54f20eb45d9e4eaef1 Mon Sep 17 00:00:00 2001 From: Muhaddil <151466679+Muhaddil@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:37:03 +0200 Subject: [PATCH] Update 1.0.2 - Added a command for specific jobs to be able to sell insurances far from the NPC. --- client.lua | 47 ++++++++++++++++++++++++++++++++++++++++++++++- config.lua | 1 + fxmanifest.lua | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/client.lua b/client.lua index 18e0b51..e0337f0 100644 --- a/client.lua +++ b/client.lua @@ -162,6 +162,51 @@ AddEventHandler('muhaddil_insurances:insurance:buy', function(data) TriggerServerEvent('muhaddil_insurances:insurance:buy', data, accountType) end) +RegisterCommand('checkInsurance', function() + local playerId = GetPlayerServerId(PlayerId()) + local jobName = nil + + local allowedJobs = Config.CheckInsuranceCommandJob + + if Config.FrameWork == "esx" then + ESX.TriggerServerCallback('esx:getPlayerData', function(playerData) + jobName = playerData.job.name + local hasAccess = false + + for _, job in ipairs(allowedJobs) do + if job == jobName then + hasAccess = true + break + end + end + + if hasAccess then + TriggerEvent('muhaddil_insurances:checkInsurance') + else + Notify("Acceso denegado", "No tienes el trabajo adecuado para acceder a esta función.", 5000, "error") + end + end, playerId) + elseif Config.FrameWork == "qb" then + local PlayerData = QBCore.Functions.GetPlayerData() + jobName = PlayerData.job.name + local hasAccess = false + + for _, job in ipairs(allowedJobs) do + if job == jobName then + hasAccess = true + break + end + end + + if hasAccess then + TriggerEvent('muhaddil_insurances:checkInsurance') + else + Notify("Acceso denegado", "No tienes el trabajo adecuado para acceder a esta función.", 5000, "error") + end + end +end) + + RegisterNetEvent('muhaddil_insurances:checkInsurance') AddEventHandler('muhaddil_insurances:checkInsurance', function() if CanAccessInsurance() then @@ -201,7 +246,7 @@ function CanSellDiscountInsurance() return true end end - + return false end end diff --git a/config.lua b/config.lua index a462e1d..bb8c5e7 100644 --- a/config.lua +++ b/config.lua @@ -15,6 +15,7 @@ Config.OnlyAllowedJobs = false -- Enable or disable restricted access to the ins Config.AllowedJobs = {"ambulance", "police", "safd"} -- List of allowed jobs. Only these jobs can access the insurance menu when 'OnlyAllowedJobs' is set to true. Config.DiscountJobs = { "ambulance" } -- List of jobs that are allowed to sell insurance at a discounted rate. Config.UseDiscounts = true -- Setting this to true allows players (with specified jobs) to sell insurance at a discounted rate. +Config.CheckInsuranceCommandJob = {"ambulance" } Config.BlipLabel = 'Seguros Médicos' -- The label displayed for the blip on the map, indicating the location of medical insurance services. Config.ShowBlip = true -- Enable or disable the display of the blip on the map. If 'true', the blip will be shown; if 'false', it will be hidden. diff --git a/fxmanifest.lua b/fxmanifest.lua index bcc12e3..a923e5f 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ lua54 'yes' author 'Muhaddil' description 'Simple Medical Insurance Script' -version 'v1.0.1' +version 'v1.0.2' shared_script 'config.lua' client_script 'client.lua'