Skip to content

Commit

Permalink
Update 1.0.7 - Replaced old cleanExpiredInsurances logic to implement…
Browse files Browse the repository at this point in the history
… a ox_lib cron function.

- Added extra configs for the sell insurance command.
  • Loading branch information
Muhaddil committed Dec 14, 2024
1 parent cce2bc7 commit 8fd79cf
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 44 deletions.
54 changes: 27 additions & 27 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -378,47 +378,47 @@ end)
if Config.EnableSellCommand then
RegisterCommand('sellinsurances', function()
local playerId = GetPlayerServerId(PlayerId())
local jobName = nil

local allowedJobs = Config.CheckInsuranceCommandJob
local jobName, jobGrade = nil, nil
local allowedJobs = Config.SellCommandJobs

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
openSellInsurance()
else
Notify(Config.AccessDeniedTitle, Config.AccessDeniedMessage, Config.NotificationDuration, "error")
end
jobGrade = playerData.job.grade
validateSellAccess(jobName, jobGrade)
end, playerId)
elseif Config.FrameWork == "qb" then
local PlayerData = QBCore.Functions.GetPlayerData()
jobName = PlayerData.job.name
local hasAccess = false
jobGrade = PlayerData.job.grade.level
validateSellAccess(jobName, jobGrade)
end
end)
end

for _, job in ipairs(allowedJobs) do
if job == jobName then
function validateSellAccess(jobName, jobGrade)
local hasAccess = false

if Config.EnableSellCommandToAllGrades then
hasAccess = Config.SellCommandJobs[jobName] ~= nil
else
local allowedGrades = Config.SellCommandJobs[jobName]

if allowedGrades then
for _, grade in ipairs(allowedGrades) do
if grade == -1 or grade == jobGrade then
hasAccess = true
break
end
end

if hasAccess then
openSellInsurance()
else
Notify(Config.AccessDeniedTitle, Config.AccessDeniedMessage, Config.NotificationDuration, "error")
end
end
end)
end

if hasAccess then
openSellInsurance()
else
Notify(Config.AccessDeniedTitle, Config.AccessDeniedMessage, Config.NotificationDuration, "error")
end
end

exports("hasValidInsurance", function()
Expand Down
26 changes: 15 additions & 11 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Config.UseDiscounts = true -- Setting this to true allows players (with specifie
Config.CheckInsuranceCommandJob = { "ambulance" } -- List of jobs allowed to use the command to check insurance status.
Config.DiscountInteractionDistance = '3.0' -- The maximum distance at which players can interact with another player to apply discounts.

Config.PeriodicallyDeleteInsurance = 3600000 -- The interval (in milliseconds) at which expired insurances will be cleaned from the database.
Config.PeriodicallyDeleteInsurance = 120 -- The interval (in minutes) at which expired insurances will be cleaned from the database.

Config.TargetIcon = 'fa fa-clipboard' -- The icon used for the targeting box when interacting with insurance locations.
Config.ZoneLabel = 'Seguros Médicos' -- The label displayed for the insurance interaction zone.
Expand Down Expand Up @@ -55,48 +55,48 @@ function openInsuranceMenu(insuranceData)
local options = {}

if insuranceData then
-- Si el jugador tiene un seguro, mostrar los detalles del seguro actual.
-- If the player has insurance, display the current insurance details.
table.insert(options, {
title = locale('current_insurance'),
description = locale('insurance_type') .. ': ' .. insuranceData.type .. '\n' .. locale('time_left') .. ': ' .. insuranceData.timeLeft,
icon = 'info-circle',
disabled = false -- La opción está habilitada ya que el jugador tiene seguro.
disabled = false --The option is enabled since the player has insurance.
})
else -- Si el jugador no tiene seguro.
-- Notificar al jugador que actualmente no tiene seguro.
else -- If the player does not have insurance.
-- Notify the player that he or she currently has no insurance.
table.insert(options, {
title = locale('no_current_insurance'),
icon = 'info-circle',
disabled = true -- La opción está deshabilitada ya que el jugador no tiene seguro.
disabled = true --The option is disabled since the player does not have insurance.
})

table.insert(options, {
title = locale('basic_insurance'),
description = locale('duration') .. ': 3 ' .. locale('days') .. '\n' .. locale('price') .. ': $10000',
icon = 'circle',
event = 'muhaddil_insurances:insurance:buy',
args = { type = "basico", duration = 3, price = 10000 } -- Argumentos para el evento.
args = { type = "basico", duration = 3, price = 10000 } -- Arguments for the event.
})
table.insert(options, {
title = locale('weekly_insurance'),
description = locale('duration') .. ': 7 ' .. locale('days') .. '\n' .. locale('price') .. ': $25000',
icon = 'circle',
event = 'muhaddil_insurances:insurance:buy',
args = { type = "semanal", duration = 7, price = 25000 } -- Argumentos para el evento.
args = { type = "semanal", duration = 7, price = 25000 } -- Arguments for the event.
})
table.insert(options, {
title = locale('full_insurance'),
description = locale('duration') .. ': 15 ' .. locale('days') .. '\n' .. locale('price') .. ': $50000',
icon = 'circle',
event = 'muhaddil_insurances:insurance:buy',
args = { type = "completo", duration = 15, price = 50000 } -- Argumentos para el evento.
args = { type = "completo", duration = 15, price = 50000 } -- Arguments for the event.
})
table.insert(options, {
title = locale('premium_insurance'),
description = locale('duration') .. ': 30 ' .. locale('days') .. '\n' .. locale('price') .. ': $100000',
icon = 'circle',
event = 'muhaddil_insurances:insurance:buy',
args = { type = "premium", duration = 30, price = 100000 } -- Argumentos para el evento.
args = { type = "premium", duration = 30, price = 100000 } -- Arguments for the event.
})
if CanSellDiscountInsurance() then
table.insert(options, {
Expand Down Expand Up @@ -140,4 +140,8 @@ end
Config.EnableSellCommand = true
Config.CanSellInsuraceToHimself = true
Config.SellInsuraceRange = 5.0
Config.SellInsuraceMaxDays = 30
Config.SellInsuraceMaxDays = 30
Config.EnableSellCommandToAllGrades = false
Config.SellCommandJobs = {
["ambulance"] = { 17, 18, 19 }, -- A -1 value would let every grade to access the command
}
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lua54 'yes'

author 'Muhaddil'
description 'Simple Medical Insurance Script'
version 'v1.0.6'
version 'v1.0.7'

shared_script 'config.lua'
client_script 'client.lua'
Expand Down
22 changes: 17 additions & 5 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,26 @@ function cleanExpiredInsurances()
end)
end

Citizen.CreateThread(function()
while true do
Wait(Config.PeriodicallyDeleteInsurance)
print('Limpieza de seguros expirados.')
cleanExpiredInsurances()
local function getCronExpression(intervalInMinutes)
if intervalInMinutes < 1 then
error('El intervalo debe ser un valor positivo.')
elseif intervalInMinutes <= 59 then
return string.format("*/%d * * * *", intervalInMinutes)
elseif intervalInMinutes % 60 == 0 then
local intervalInHours = intervalInMinutes / 60
return string.format("0 */%d * * *", intervalInHours)
else
error('Intervalos mayores a una hora deben ser múltiplos de 60.')
end
end

local cronExpression = getCronExpression(Config.PeriodicallyDeleteInsurance)
lib.cron.new(cronExpression, function()
print('Limpieza de seguros expirados.')
cleanExpiredInsurances()
end)


if Config.AutoRunSQL then
if not pcall(function()
local fileName = "InstallSQL.sql"
Expand Down

0 comments on commit 8fd79cf

Please sign in to comment.