diff --git a/server-data/resources/[esx_addons]/BasicItem/client/main.lua b/server-data/resources/[esx_addons]/BasicItem/client/main.lua index 841b99590..fc75c580f 100644 --- a/server-data/resources/[esx_addons]/BasicItem/client/main.lua +++ b/server-data/resources/[esx_addons]/BasicItem/client/main.lua @@ -1,78 +1,82 @@ -local closestDistance, closestPlayer = {}, {} +local closestDistance, closestPlayer, playerReceiveCard = {}, {}, {} ESX = exports["es_extended"]:getSharedObject() RegisterNetEvent("IDCARD:USE") AddEventHandler("IDCARD:USE", function() - closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() - if closestDistance ~= -1 and closestDistance <= 2.0 then - ESX.ShowNotification((_LConfig.playerReceiveCard):format(GetPlayerName(closestPlayer))) - TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(closestPlayer)) - else - ESX.ShowNotification(_LConfig.nobodyFound) - TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId())) - end - Wait(1) + closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() + if closestDistance ~= -1 and closestDistance <= 2.0 then + ESX.ShowNotification((_LConfig.playerReceiveCard):format(GetPlayerName(closestPlayer))) + TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(closestPlayer)) + else + ESX.ShowNotification(_LConfig.nobodyFound) + TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId())) + end + Wait(1) end) RegisterNetEvent("DMVCARD:USE") AddEventHandler("DMVCARD:USE", function() - closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() - if closestDistance ~= -1 and closestDistance <= 2.0 then - ESX.ShowNotification((playerReceiveCard):format(GetPlayerName(closestPlayer))) - TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(closestPlayer), "driver") - else - ESX.ShowNotification(_LConfig.nobodyFound) - TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId()), "driver") - end - Wait(1) + closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() + if closestDistance ~= -1 and closestDistance <= 2.0 then + ESX.ShowNotification((playerReceiveCard):format(GetPlayerName(closestPlayer))) + TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(closestPlayer), "driver") + else + ESX.ShowNotification(_LConfig.nobodyFound) + TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId()), "driver") + end + Wait(1) end) RegisterNetEvent("WCARD:USE") AddEventHandler("WCARD:USE", function() - closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() - if closestDistance ~= -1 and closestDistance <= 2.0 then - ESX.ShowNotification((playerReceiveCard):format(GetPlayerName(closestPlayer))) - TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(closestPlayer), "weapon") - else - ESX.ShowNotification(_LConfig.nobodyFound) - TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId()), "weapon") - end - Wait(1) + closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() + if closestDistance ~= -1 and closestDistance <= 2.0 then + ESX.ShowNotification((playerReceiveCard):format(GetPlayerName(closestPlayer))) + TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(closestPlayer), "weapon") + else + ESX.ShowNotification(_LConfig.nobodyFound) + TriggerServerEvent("jsfour-idcard:open", GetPlayerServerId(PlayerId()), GetPlayerServerId(PlayerId()), "weapon") + end + Wait(1) end) RegisterNetEvent("JOBCARD:USE") AddEventHandler("JOBCARD:USE", function(user) - closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() - ESX = exports["es_extended"]:getSharedObject() - ESX.PlayerData = ESX.GetPlayerData() + closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() + ESX = exports["es_extended"]:getSharedObject() + ESX.PlayerData = ESX.GetPlayerData() - local userData = user[1] - local name = userData.firstname - local name2 = userData.lastname + local userData = user[1] + local name = userData.firstname + local name2 = userData.lastname - if closestDistance ~= -1 and closestDistance <= 2.0 then - ESX.ShowNotification(TranslateCap("you_have_licensed"):format(GetPlayerName(closestPlayer))) - for job, info in pairs(_LConfig.jobs) do - if ESX.PlayerData.job.name == job then - local msg = info.message - local DataPlayer = ESX.PlayerData - TriggerServerEvent("JOBCARD:MSG", GetPlayerServerId(closestPlayer), msg, name, name2, DataPlayer) - return - end - end - local msg = _LConfig.defaultJobMessage - local DataPlayer = ESX.PlayerData - TriggerServerEvent("JOBCARD:MSG", GetPlayerServerId(closestPlayer), msg, name, name2, DataPlayer) - else - ESX.ShowNotification(_LConfig.nobodyFound) - for job, info in pairs(_LConfig.jobs) do - if ESX.PlayerData.job.name == job then - ESX.ShowNotification((info.message):format(name, name2, ESX.PlayerData.job.label, ESX.PlayerData.job.grade_label)) - return - end - end - ESX.ShowNotification((_LConfig.defaultJobMessage):format(name, name2, ESX.PlayerData.job.label, ESX.PlayerData.job.grade_label)) - end - Wait(1) + if closestDistance ~= -1 and closestDistance <= 2.0 then + ESX.ShowNotification(TranslateCap("you_have_licensed"):format(GetPlayerName(closestPlayer))) + for job, info in pairs(_LConfig.jobs) do + if ESX.PlayerData.job.name == job then + local msg = info.message + local DataPlayer = ESX.PlayerData + TriggerServerEvent("JOBCARD:MSG", GetPlayerServerId(closestPlayer), msg, name, name2, DataPlayer) + return + end + end + local msg = _LConfig.defaultJobMessage + local DataPlayer = ESX.PlayerData + TriggerServerEvent("JOBCARD:MSG", GetPlayerServerId(closestPlayer), msg, name, name2, DataPlayer) + else + ESX.ShowNotification(_LConfig.nobodyFound) + for job, info in pairs(_LConfig.jobs) do + if ESX.PlayerData.job.name == job then + ESX.ShowNotification( + (info.message):format(name, name2, ESX.PlayerData.job.label, ESX.PlayerData.job.grade_label) + ) + return + end + end + ESX.ShowNotification( + (_LConfig.defaultJobMessage):format(name, name2, ESX.PlayerData.job.label, ESX.PlayerData.job.grade_label) + ) + end + Wait(1) end)