Skip to content

Commit

Permalink
Merge pull request #691 from bitpredator/dev
Browse files Browse the repository at this point in the history
fix: (BasicItem\client & server) accessing undefined variable
  • Loading branch information
bitpredator authored Apr 7, 2024
2 parents e61a816 + d41cd7a commit fdc7c73
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 72 deletions.
120 changes: 63 additions & 57 deletions server-data/resources/[esx_addons]/BasicItem/client/main.lua
Original file line number Diff line number Diff line change
@@ -1,76 +1,82 @@
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(_U("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)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ game("gta5")
name("LItemBasic")
description("fivem resource")
author("LQuatre")
version("1.0.0")
version("1.0.1")
lua54("yes")

shared_scripts({
Expand Down
35 changes: 21 additions & 14 deletions server-data/resources/[esx_addons]/BasicItem/server/main.lua
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
ESX = exports["es_extended"]:getSharedObject()

ESX.RegisterUsableItem("idcard", function(source)
local _source = source
TriggerClientEvent("IDCARD:USE", _source)
local _source = source
TriggerClientEvent("IDCARD:USE", _source)
end)

ESX.RegisterUsableItem("dmvcard", function(source)
local _source = source
TriggerClientEvent("DMVCARD:USE", _source)
local _source = source
TriggerClientEvent("DMVCARD:USE", _source)
end)

ESX.RegisterUsableItem("licensecard", function(source)
local _source = source
TriggerClientEvent("WCARD:USE", _source)
local _source = source
TriggerClientEvent("WCARD:USE", _source)
end)

ESX.RegisterUsableItem("jobcard", function(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local identifier = ESX.GetPlayerFromId(_source).identifier
local name = xPlayer.getName()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local identifier = ESX.GetPlayerFromId(_source).identifier
local _ = xPlayer.getName()
local firstname, lastname = {}, {}

MySQL.Async.fetchAll("SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = @identifier", { ["@identifier"] = identifier }, function(user)
TriggerClientEvent("JOBCARD:USE", _source, user, firstname, lastname)
end)
MySQL.Async.fetchAll(
"SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = @identifier",
{ ["@identifier"] = identifier },
function(user)
TriggerClientEvent("JOBCARD:USE", _source, user, firstname, lastname)
end
)
end)

RegisterNetEvent("JOBCARD:MSG")
AddEventHandler("JOBCARD:MSG", function(closestPlayer, msg, name, name2, DataPlayer)
TriggerClientEvent("esx:showNotification", closestPlayer, (msg):format(name, name2, DataPlayer.job, DataPlayer.job_grade))
TriggerClientEvent("esx:showNotification", closestPlayer,
(msg):format(name, name2, DataPlayer.job, DataPlayer.job_grade)
)
end)

0 comments on commit fdc7c73

Please sign in to comment.