-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #691 from bitpredator/dev
fix: (BasicItem\client & server) accessing undefined variable
- Loading branch information
Showing
3 changed files
with
85 additions
and
72 deletions.
There are no files selected for viewing
120 changes: 63 additions & 57 deletions
120
server-data/resources/[esx_addons]/BasicItem/client/main.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 21 additions & 14 deletions
35
server-data/resources/[esx_addons]/BasicItem/server/main.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |