Skip to content

Commit

Permalink
feat: bpt_idcard/server/main.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator authored May 18, 2024
1 parent 0fe4eb6 commit f796dc6
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_idcard/server/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- Open ID card
ESX = exports["es_extended"]:getSharedObject()

RegisterServerEvent("bpt_idcard:open")
AddEventHandler("bpt_idcard:open", function(ID, targetID, type)
local identifier = ESX.GetPlayerFromId(ID).identifier
local _source = ESX.GetPlayerFromId(targetID).source
local show = false

MySQL.Async.fetchAll(
"SELECT firstname, lastname, dateofbirth, sex, height FROM users WHERE identifier = @identifier",
{ ["@identifier"] = identifier }, function(user)
if user[1] ~= nil then
MySQL.Async.fetchAll("SELECT type FROM user_licenses WHERE owner = @identifier",
{ ["@identifier"] = identifier }, function(licenses)
if type ~= nil then
for i = 1, #licenses, 1 do
if type == "driver" then
if licenses[i].type == "drive" or licenses[i].type == "drive_bike" or licenses[i].type == "drive_truck" then
show = true
end
elseif type == "weapon" then
if licenses[i].type == "weapon" then
show = true
end
end
end
else
show = true
end

if show then
local array = {
user = user,
licenses = licenses,
}
TriggerClientEvent("bpt_idcard:open", _source, array, type)
else
TriggerClientEvent("esx:showNotification", _source, TranslateCap("no_license_type"))
end
end)
end
end)
end)

0 comments on commit f796dc6

Please sign in to comment.