Advertisement
Guest User

SERVER UTILS

a guest
Aug 7th, 2022
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.18 KB | None | 0 0
  1. lib.locale()
  2.  
  3. local ver = '1.0.0'
  4.  
  5. CreateThread(function()
  6.     if GetResourceState(GetCurrentResourceName()) == 'started' then
  7.         print('DRC_DRUGS STARTED ON VERSION: ' .. ver)
  8.     end
  9. end)
  10.  
  11. if Config.Framework == "ESX" then
  12.     ESX = nil
  13.     TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  14. elseif Config.Framework == "qbcore" then
  15.     QBCore = nil
  16.     QBCore = exports['qb-core']:GetCoreObject()
  17. elseif Config.Framework == "standalone" then
  18.     -- ADD YOU FRAMEWORK
  19. end
  20.  
  21. function BanPlayer(source, message)
  22.     if Config.AnticheatBan then
  23.         --Example of usage for SQZ ANTICHEAT (Higly recommended Anticheat!)
  24.         exports['sqz_anticheat']:BanPlayer(source, message)
  25.     end
  26. end
  27.  
  28. local webhook = "YOUR_WEBHOOK"
  29. function Logs(source, message)
  30.     if message ~= nil then
  31.         if Config.Logs.enabled then
  32.             local license = nil
  33.             for k,v in pairs(GetPlayerIdentifiers(source))do
  34.                 if string.sub(v, 1, string.len("license:")) == "license:" then
  35.                     license = v
  36.                 end
  37.             end
  38.             if Config.Logs.type == "ox_lib" then
  39.                 lib.logger(source, "Drugs", message)
  40.             elseif Config.Logs.type == "webhook" then
  41.                 local embed = {
  42.                     {
  43.                         ["color"] = 2600155,
  44.                         ["title"] = "Player: **".. GetPlayerName(source) .." | License: " .. license .. " **",
  45.                         ["description"] = message,
  46.                         ["footer"] = {
  47.                             ["text"] = "Logs by DRC SCRIPTS for DRC DRUGS!",
  48.                         },
  49.                     }
  50.                 }
  51.                 PerformHttpRequest(webhook, function(err, text, headers) end, 'POST', json.encode({username = "DRC DRUGS", embeds = embed, avatar_url = "https://i.imgur.com/RclET8O.png"}), { ['Content-Type'] = 'application/json' })
  52.             end
  53.         end
  54.     end
  55. end
  56.  
  57. function GetMoney(count, source)
  58.     if Config.Framework == "ESX" then
  59.         local xPlayer = ESX.GetPlayerFromId(source)
  60.         if xPlayer.getMoney() >= count then
  61.             return true
  62.         else
  63.             return false
  64.         end
  65.     elseif Config.Framework == "qbcore" then
  66.         local xPlayer = QBCore.Functions.GetPlayer(source)
  67.         if xPlayer.Functions.GetMoney('cash') then
  68.             return true
  69.         else
  70.             return false
  71.         end
  72.     elseif Config.Framework == "standalone" then
  73.         -- ADD YOUR FRAMEWORK
  74.     end
  75. end
  76.  
  77. function RemoveMoney(count, source)
  78.     if Config.Framework == "ESX" then
  79.         local xPlayer = ESX.GetPlayerFromId(source)
  80.         xPlayer.removeMoney(count)
  81.     elseif Config.Framework == "qbcore" then
  82.         local xPlayer = QBCore.Functions.GetPlayer(source)
  83.         xPlayer.Functions.RemoveMoney('cash', count)
  84.     elseif Config.Framework == "standalone" then
  85.         -- ADD YOUR FRAMEWORK
  86.     end
  87. end
  88.  
  89. function AddMoney(count, source)
  90.     if Config.Framework == "ESX" then
  91.         local xPlayer = ESX.GetPlayerFromId(source)
  92.         xPlayer.addMoney(count)
  93.     elseif Config.Framework == "qbcore" then
  94.         local xPlayer = QBCore.Functions.GetPlayer(source)
  95.         xPlayer.Functions.AddMoney('cash', count)
  96.     elseif Config.Framework == "standalone" then
  97.         -- ADD YOUR FRAMEWORK
  98.     end
  99. end
  100.  
  101. function GetItem(name, count, source)
  102.     if Config.Framework == "ESX" then
  103.         local xPlayer = ESX.GetPlayerFromId(source)
  104.         if xPlayer.getInventoryItem(name).count >= count then
  105.             return true
  106.         else
  107.             return false
  108.         end
  109.     elseif Config.Framework == "qbcore" then
  110.         local xPlayer = QBCore.Functions.GetPlayer(source)
  111.         if xPlayer.Functions.GetItemByName(name) ~= nil then
  112.             if xPlayer.Functions.GetItemByName(name).amount >= count then
  113.                 return true
  114.             else
  115.                 return false
  116.             end
  117.         else
  118.             return false
  119.         end
  120.     elseif Config.Framework == "standalone" then
  121.         -- ADD YOUR FRAMEWORK
  122.     end
  123. end
  124.  
  125. function AddItem(name, count, source)
  126.     if Config.Framework == "ESX" then
  127.         local xPlayer = ESX.GetPlayerFromId(source)
  128.         xPlayer.addInventoryItem(name, count)
  129.     elseif Config.Framework == "qbcore" then
  130.         local xPlayer = QBCore.Functions.GetPlayer(source)
  131.         xPlayer.Functions.AddItem(name, count, nil, nil)
  132.         TriggerClientEvent("inventory:client:ItemBox", source, QBCore.Shared.Items[name], "add", count)
  133.  
  134.     elseif Config.Framework == "standalone" then
  135.         -- ADD YOUR FRAMEWORK
  136.     end
  137. end
  138.  
  139. function RemoveItem(name, count, source)
  140.     if Config.Framework == "ESX" then
  141.         local xPlayer = ESX.GetPlayerFromId(source)
  142.         xPlayer.removeInventoryItem(name, count)
  143.     elseif Config.Framework == "qbcore" then
  144.         local xPlayer = QBCore.Functions.GetPlayer(source)
  145.         xPlayer.Functions.RemoveItem(name, count, nil, nil)
  146.         TriggerClientEvent("inventory:client:ItemBox", source, QBCore.Shared.Items[name], "remove", count)
  147.     elseif Config.Framework == "standalone" then
  148.         -- ADD YOUR FRAMEWORK
  149.     end
  150. end
  151.  
  152. lib.callback.register('drc_drugs:getpolice', function(source)
  153.     local policeCount = 0
  154.     if Config.Framework == "ESX" then
  155.         local xPlayers = ESX.GetPlayers()
  156.         for i = 1, #xPlayers do
  157.             local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
  158.             for _, job in pairs(Config.PoliceJobs) do
  159.                 if xPlayer.job.name == job then
  160.                     policeCount = policeCount + 1
  161.                 end
  162.             end
  163.         end
  164.         return policeCount
  165.     elseif Config.Framework == "qbcore" then
  166.         local xPlayers = QBCore.Functions.GetPlayers()
  167.         for i = 1, #xPlayers do
  168.             local xPlayer = QBCore.Functions.GetPlayer(xPlayers[i])
  169.             for _, job in pairs(Config.PoliceJobs) do
  170.                 if xPlayer.PlayerData.job.name == job then
  171.                     policeCount = policeCount + 1
  172.                 end
  173.             end
  174.         end
  175.         return policeCount
  176.     elseif Config.Framework == "standalone" then
  177.         -- ADD YOU FRAMEWORK
  178.     end
  179. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement