From f796dc6848355857321fddb720a95f4c8d792160 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Sat, 18 May 2024 20:11:40 +0200 Subject: [PATCH] feat: bpt_idcard/server/main.lua --- .../[bpt_addons]/bpt_idcard/server/main.lua | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 server-data/resources/[bpt_addons]/bpt_idcard/server/main.lua diff --git a/server-data/resources/[bpt_addons]/bpt_idcard/server/main.lua b/server-data/resources/[bpt_addons]/bpt_idcard/server/main.lua new file mode 100644 index 000000000..2aa55e8d3 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_idcard/server/main.lua @@ -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)