CodeStudio = CodeStudio or {} if CodeStudio.ServerType == "QB" then QBCore = exports['qb-core']:GetCoreObject() elseif CodeStudio.ServerType == "ESX" then ESX = exports['es_extended']:getSharedObject() end --[SAVE STUDIO IMAGES] If you are using Fivemanage, Fivemerr or Discord then put api key here otherwise put discord webhook *[PROTECTED] lib.callback.register('cs:identity:fetchWebhookAPI', function(source) local WebhookAPI = 'https://discord.com/api/webhooks/1378331858743459851/H1JY-QCOstRZhziqp011HdIn4oNOnVtBVgXBLqlTow2fWMYugJSixtxBgBoT3NsU4wmK' return WebhookAPI end) function GetPlayer(source) if CodeStudio.ServerType == 'QB' then return QBCore.Functions.GetPlayer(source) elseif CodeStudio.ServerType == 'ESX' then return ESX.GetPlayerFromId(source) end end function GetIdentifier(source) local Player = GetPlayer(source) if not Player then return end if CodeStudio.ServerType == 'QB' then return Player.PlayerData.citizenid elseif CodeStudio.ServerType == 'ESX' then return Player.identifier end end function GetPlayerName(source) local Player = GetPlayer(source) if not Player then return end if CodeStudio.ServerType == 'QB' then return Player.PlayerData.charinfo.firstname, Player.PlayerData.charinfo.lastname elseif CodeStudio.ServerType == 'ESX' then return Player.get('firstName'), Player.get('lastName') end end function GetNationality(source) local Player = GetPlayer(source) if not Player then return end if CodeStudio.ServerType == 'QB' then return Player.PlayerData.charinfo.nationality elseif CodeStudio.ServerType == 'ESX' then return 'Roleplay' -- Default value since ESX doesn’t have a nationality field end end function GetGender(source) local Player = GetPlayer(source) if not Player then return end if CodeStudio.ServerType == 'QB' then return Player.PlayerData.charinfo.gender == 0 and 'Male' or 'Female' elseif CodeStudio.ServerType == 'ESX' then return Player.get('sex') == 'm' and 'Male' or 'Female' end end function GetBirthdate(source) local Player = GetPlayer(source) if not Player then return end if CodeStudio.ServerType == 'QB' then return Player.PlayerData.charinfo.birthdate elseif CodeStudio.ServerType == 'ESX' then return Player.get('dateofbirth') end end function GetPlayerJob(source) local Player = GetPlayer(source) if not Player then return end if CodeStudio.ServerType == 'QB' then return Player.PlayerData.job.name, Player.PlayerData.job.grade.level, Player.PlayerData.job.grade.name elseif CodeStudio.ServerType == 'ESX' then return Player.job.name, Player.job.grade, Player.job.grade_label end end function GetPlayerHeight(source) if CodeStudio.ServerType == 'ESX' then local Player = GetPlayer(source) if not Player then return end return Player.get('height') end end lib.callback.register('cs:identity:getNearbyPlayer', function(source) local players = {} local PlayerPed = GetPlayerPed(source) local pCoords = GetEntityCoords(PlayerPed) if CodeStudio.ServerType == 'QB' then for _, v in pairs(QBCore.Functions.GetPlayers()) do local targetPed = GetPlayerPed(v) if targetPed and PlayerPed ~= targetPed then local tCoords = GetEntityCoords(targetPed) local dist = #(pCoords - tCoords) if dist < 10 then local ped = GetPlayer(v) if ped then players[#players + 1] = { id = v, name = ped.PlayerData.charinfo.firstname .. " " .. ped.PlayerData.charinfo.lastname } end end end end elseif CodeStudio.ServerType == 'ESX' then for _, v in pairs(ESX.GetPlayers()) do local targetPed = GetPlayerPed(v) if targetPed and PlayerPed ~= targetPed then local tCoords = GetEntityCoords(targetPed) local dist = #(pCoords - tCoords) if dist < 10 then local ped = GetPlayer(v) if ped then players[#players + 1] = { id = v, name = ped.getName() } end end end end end return players end) lib.callback.register('cs:identity:deductMoney', function(source, amount) local Player = GetPlayer(source) if CodeStudio.ServerType == 'QB' then local money = Player.PlayerData.money['cash'] if money >= amount then Player.Functions.RemoveMoney("cash", amount) return true end elseif CodeStudio.ServerType == 'ESX' then local money = Player.getAccount('money').money if money >= amount then Player.removeAccountMoney('money', amount) return true end end return false end) RegisterNetEvent('cs:identity:refundStudio', function(refund) local Player = GetPlayer(source) if CodeStudio.ServerType == 'QB' then Player.Functions.AddMoney("cash", refund) elseif CodeStudio.ServerType == 'ESX' then Player.addAccountMoney('money', refund) end end) function addItem(source, item, metadata) if metadata and metadata.firstname and metadata.lastname then metadata.description = ('Name: %s'):format(metadata.firstname .. ' ' .. metadata.lastname) end if GetResourceState('ox_inventory') == 'started' then exports['ox_inventory']:AddItem(source, item, 1, metadata) elseif GetResourceState('qs-inventory') == 'started' then exports['qs-inventory']:AddItem(source, item, 1, false, metadata) elseif GetResourceState('tgiann-inventory') == 'started' then exports["tgiann-inventory"]:AddItem(source, item, 1, nil, metadata, false) elseif GetResourceState('origen_inventory') == 'started' then exports['origen_inventory']:addItem(source, item, 1, metadata, false) else local Player = GetPlayer(source) if CodeStudio.ServerType == 'QB' then Player.Functions.AddItem(item, 1, nil, metadata) elseif CodeStudio.ServerType == 'ESX' then Player.addInventoryItem(item, 1, metadata) end end end function issueLicense(playerSrc, license, issue) --This Function triggers when license gets issued or revoked --Supports qb-core Metadata License update + esx_license support local Player = GetPlayer(playerSrc) if CodeStudio.ServerType == 'QB' then local licenseTable = Player.PlayerData.metadata['licences'] if issue then if licenseTable[license] then return end licenseTable[license] = true else licenseTable[license] = false end Player.Functions.SetMetaData('licences', licenseTable) elseif CodeStudio.ServerType == 'ESX' then local identifier = Player.identifier if issue then TriggerEvent('esx_license:addLicense', playerSrc, license) else MySQL.query.await('DELETE FROM user_licenses WHERE type = ? AND owner = ?', {license, identifier}) end end end function createIDItems() -- Register Public Licenses -- for itemName, v in pairs(allLicense) do local function handleCardUse(source, data, itemKey) lib.callback('cs:identity:getClosestPlayer', source, function(nearby) local itemInfo = {} if CodeStudio.IDSettings.useMetaData then itemInfo = (data and data.metadata) or (data and data.info) or {} itemInfo.card = allLicense[itemKey] end for k, playerID in pairs(nearby) do if itemInfo.checkCard == 'codestudio' then TriggerClientEvent('cs:identity:useCard', playerID, itemInfo, itemKey, source) else useCard(source, playerID, itemKey) end end end) end if GetResourceState('qs-inventory') == 'started' then exports['qs-inventory']:CreateUsableItem(itemName, function(source, item) handleCardUse(source, item, itemName) end) elseif CodeStudio.ServerType == "QB" then QBCore.Functions.CreateUseableItem(itemName, function(source, item) handleCardUse(source, item, itemName) end) elseif CodeStudio.ServerType == "ESX" then ESX.RegisterUsableItem(itemName, function(source, item, data) if GetResourceState('ox_inventory') == 'started' then handleCardUse(source, data, itemName) else handleCardUse(source, item, itemName) end end) end end end function createItems() -- Register Job Badges Items -- for job, config in pairs(CodeStudio.Management) do if config.JobBadge.Enable and config.JobBadge.ItemName then local itemName = config.JobBadge.ItemName local function handleBadgeUse(source, data, itemKey) lib.callback('cs:identity:getClosestPlayer', source, function(nearby) local itemInfo = {} if CodeStudio.IDSettings.useMetaData then itemInfo = (data and data.metadata) or (data and data.info) or {} end for k, playerID in pairs(nearby) do if itemInfo.checkCard == 'codestudio' then TriggerClientEvent('cs:identity:useBadge', playerID, itemInfo, itemKey, source) else useBadge(source, playerID, itemKey) end end end) end if GetResourceState('qs-inventory') == 'started' then exports['qs-inventory']:CreateUsableItem(itemName, function(source, item) handleBadgeUse(source, item, itemName) end) elseif CodeStudio.ServerType == "QB" then QBCore.Functions.CreateUseableItem(itemName, function(source, item) handleBadgeUse(source, item, itemName) end) elseif CodeStudio.ServerType == "ESX" then ESX.RegisterUsableItem(itemName, function(source, item, data) if GetResourceState('ox_inventory') == 'started' then handleBadgeUse(source, data, itemName) else handleBadgeUse(source, item, itemName) end end) end end end -- Register Worker IDs Items -- for k, config in pairs(CodeStudio.WorkerID) do if config.ItemName then local itemName = config.ItemName local function handleWorkerIDUse(source, data, itemKey) lib.callback('cs:identity:getClosestPlayer', source, function(nearby) local itemInfo = {} if CodeStudio.IDSettings.useMetaData then itemInfo = (data and data.metadata) or (data and data.info) or {} end for k, playerID in pairs(nearby) do if itemInfo.checkCard == 'codestudio' then TriggerClientEvent('cs:identity:useWorkerID', playerID, itemInfo, itemKey, source) else useWorkerID(source, playerID, itemKey) end end end) end if GetResourceState('qs-inventory') == 'started' then exports['qs-inventory']:CreateUsableItem(itemName, function(source, item) handleWorkerIDUse(source, item, itemName) end) elseif CodeStudio.ServerType == "QB" then QBCore.Functions.CreateUseableItem(itemName, function(source, item) handleWorkerIDUse(source, item, itemName) end) elseif CodeStudio.ServerType == "ESX" then ESX.RegisterUsableItem(itemName, function(source, item, data) if GetResourceState('ox_inventory') == 'started' then handleWorkerIDUse(source, data, itemName) else handleWorkerIDUse(source, item, itemName) end end) end end end -- Register Forge/Fake IDs -- local function handleForgeIDUse(source, data, itemKey) if not CodeStudio.IDSettings.useMetaData then return end lib.callback('cs:identity:getClosestPlayer', source, function(nearby) local itemInfo = (data and data.metadata) or (data and data.info) or {} for k, playerID in pairs(nearby) do if itemInfo.checkCard == 'codestudio' then TriggerClientEvent('cs:identity:useCard', playerID, itemInfo, itemKey, source) end end end) end if GetResourceState('qs-inventory') == 'started' then exports['qs-inventory']:CreateUsableItem(CodeStudio.FakeID.itemName, function(source, item) handleForgeIDUse(source, item, CodeStudio.FakeID.itemName) end) elseif CodeStudio.ServerType == "QB" then QBCore.Functions.CreateUseableItem(CodeStudio.FakeID.itemName, function(source, item) handleForgeIDUse(source, item, CodeStudio.FakeID.itemName) end) elseif CodeStudio.ServerType == "ESX" then ESX.RegisterUsableItem(CodeStudio.FakeID.itemName, function(source, item, data) if GetResourceState('ox_inventory') == 'started' then handleForgeIDUse(source, data, CodeStudio.FakeID.itemName) else handleForgeIDUse(source, item, CodeStudio.FakeID.itemName) end end) end end lib.addCommand(CodeStudio.LicenseCreator.creatorCommand, { help = 'Create Licenses [Restricted]', }, function(source, args, raw) if isPlayerAllowed(source, CodeStudio.LicenseCreator.Restrict) then TriggerClientEvent('cs:identity:creatorUI', source) end end) if CodeStudio.LicenseChecker.Enable then lib.addCommand(CodeStudio.LicenseChecker.checkCommand, { help = 'Check Licenses [Restricted]', }, function(source, args, raw) if isPlayerAllowed(source, CodeStudio.LicenseChecker.Restrict) then TriggerClientEvent('cs:identity:idCheck', source) end end) end