Skip to content

Commit

Permalink
Update 1.0.9 - Refactor insurance check export to allow player-specif…
Browse files Browse the repository at this point in the history
…ic checks.
  • Loading branch information
Muhaddil committed Dec 23, 2024
1 parent 462d33d commit 9c72b03
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,22 +335,18 @@ RegisterNetEvent('muhaddil_insurances:insurance:customPrice', function()

local playerOptions = {}

-- Iteramos por los jugadores cercanos
for _, player in ipairs(nearbyPlayers) do
local serverId = GetPlayerServerId(player.id)

-- Llamada para obtener el nombre del jugador
local playerNameData = lib.callback.await('getPlayerNameInGame', serverId)
local playerName = playerNameData.firstname .. " " .. playerNameData.lastname

-- Añadimos la opción con el nombre completo
table.insert(playerOptions, {
value = serverId,
label = locale('select_nearby_player_label') .. ': ' .. playerName .. ' (' ..serverId.. ')'
})
end

-- Mostramos el diálogo para seleccionar un jugador
local selectPlayer = lib.inputDialog(locale('select_nearby_player'), {
{type = 'select', label = locale('select_nearby_player_label'), options = playerOptions, required = true}
})
Expand Down Expand Up @@ -430,10 +426,14 @@ function validateSellAccess(jobName, jobGrade)
end
end

exports("hasValidInsurance", function()
exports("hasValidInsurance", function(playerId)
local promise = promise.new()

TriggerServerEvent('muhaddil_insurance:checkInsuranceExport')
if not playerId or playerId == PlayerId() then
playerId = GetPlayerServerId(PlayerId())
end

TriggerServerEvent('muhaddil_insurance:checkInsuranceExport', playerId)

RegisterNetEvent('muhaddil_insurance:insuranceResult', function(result)
promise:resolve(result)
Expand Down
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.8'
version 'v1.0.9'

shared_script 'config.lua'
client_script 'client.lua'
Expand Down
9 changes: 5 additions & 4 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,12 @@ RegisterNetEvent('muhaddil_insurance:syncInsuranceStatus', function(playerId)
TriggerClientEvent('muhaddil_insurance:updateInsuranceStatus', playerId, hasInsurance)
end)

RegisterNetEvent('muhaddil_insurance:checkInsuranceExport', function()
local playerId = source
local hasInsurance = exports['muhaddil_insurance']:hasValidInsurance(playerId)
RegisterNetEvent('muhaddil_insurance:checkInsuranceExport', function(playerId)
local requestingPlayer = source
local targetPlayerId = playerId or requestingPlayer
local hasInsurance = exports['muhaddil_insurance']:hasValidInsurance(targetPlayerId)

TriggerClientEvent('muhaddil_insurance:insuranceResult', playerId, hasInsurance)
TriggerClientEvent('muhaddil_insurance:insuranceResult', requestingPlayer, hasInsurance)
end)

lib.callback.register('getPlayerNameInGame', function(targetPlayerServerId)
Expand Down

0 comments on commit 9c72b03

Please sign in to comment.