Open Source Server
Webhook = ""
 
if Config.Framework == "qb-core" then
    local QBCore = exports[Config.Core.resource]:GetCoreObject()
 
    function AddItem(source, item, amount, info)
        if info == nil then
            QBCore.Functions.GetPlayer(source).Functions.AddItem(item, amount)
        else
            QBCore.Functions.GetPlayer(source).Functions.AddItem(item, amount, false, info)
        end
    end
 
    function RemoveItem(source, item, amount)
        return QBCore.Functions.GetPlayer(source).Functions.RemoveItem(item, amount)
    end
 
    function ItemBox(source, item, addRemove, amount)
        TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[item], addRemove, amount)
    end
 
    function AddMoney(source, cash, amount)
        QBCore.Functions.GetPlayer(source).Functions.AddMoney(cash, amount)
    end
 
    function NotificationServer(source, notification, notificationType, duration)
        TriggerClientEvent(Config.Core.name..':Notify', source, notification, notificationType, duration)
    end
 
    lib.callback.register("projectx-fleecabankrobbery:getOnlinePoliceCountQB", function(source)
        local jobs = {"police", "statepolice", "fib"}
        local CurrentCops = 0
        for k, v in pairs(jobs) do
            local players = QBCore.Functions.GetPlayers()
            for i = 1, #players do
                local Player = QBCore.Functions.GetPlayer(players[i])
                if Player ~= nil then
                    if Player.PlayerData.job.name == v then
                        CurrentCops = CurrentCops + 1
                    end
                end
            end
        end
        return (CurrentCops >= Config.MinimumFleecaPolice)
    end)
 
    function DiscordLogCash(source, amount)
        if Config.DiscordLogStatus then
            local player = QBCore.Functions.GetPlayer(source)
            DiscordLog("**Name:** **"..player.PlayerData.charinfo.firstname.."** **"..player.PlayerData.charinfo.lastname.."**".."\n".."**Server ID:** "..player.PlayerData.cid.."\n".."**Citizen ID:** "..player.PlayerData.citizenid.."\n".."**License:** "..player.PlayerData.license.." \n \n".."Log info: ".." **+** **"..amount.."**")
        end
    end
 
    function DiscordLogItem(source, item, amount, info)
        if Config.DiscordLogStatus then
            local player = QBCore.Functions.GetPlayer(source)
            if not info then 
                DiscordLog("**Name:** **"..player.PlayerData.charinfo.firstname.."** **"..player.PlayerData.charinfo.lastname.."**".."\n".."**Server ID:** "..player.PlayerData.cid.."\n".."**Citizen ID:** "..player.PlayerData.citizenid.."\n".."**License:** "..player.PlayerData.license.." \n \n".."Log info: ".." **+** **"..amount.."** **"..item.."**")
            else
                DiscordLog("**Name:** **"..player.PlayerData.charinfo.firstname.."** **"..player.PlayerData.charinfo.lastname.."**".."\n".."**Server ID:** "..player.PlayerData.cid.."\n".."**Citizen ID:** "..player.PlayerData.citizenid.."\n".."**License:** "..player.PlayerData.license.." \n \n".."Log info: ".." **+** **"..amount.."** **"..item.."**".."**:"..info.."**")
            end
        end
    end
 
    function checkPerms(source)
        return QBCore.Functions.HasPermission(source, 'god') or QBCore.Functions.HasPermission(source, 'admin')
    end
elseif Config.Framework == "esx" then
 
    CreateThread(function()
        while ESX == nil do Wait(1000) end
    end)
    
    function AddItem(source, item, amount, info)
        ESX.GetPlayerFromId(source).addInventoryItem(item, amount)
    end
 
    function RemoveItem(source, item, amount)
        ESX.GetPlayerFromId(source).removeInventoryItem(item, amount)
    end
 
    function ItemBox(source, item, addRemove, amount)
 
    end
 
    function AddMoney(source, cash, amount)
        ESX.GetPlayerFromId(source).addMoney(amount)
    end
 
    function NotificationServer(source, notification, notificationType, duration)
        TriggerClientEvent('esx:showNotification', source, notification, notificationType, duration)
    end
 
    lib.callback.register('projectx-fleecabankrobbery:server:hasitem', function(source, item)
        if Config.Inventory == "ox" then
            local check = exports.ox_inventory:GetItemCount(source, item)
            return check >= 1
        elseif Config.Inventory == "qs" then
            local check = exports['qs-inventory']:GetItemTotalAmount(source, item)
            return check >= 1
        else
            local check = ESX.GetPlayerFromId(source).hasItem(item)
            return check.count >= 1
        end
    end)
 
    lib.callback.register("projectx-fleecabankrobbery:getOnlinePoliceCount", function(source)
        local Players = ESX.GetPlayers()
        local policeOnline = 0
        for i = 1, #Players do
            local xPlayer = ESX.GetPlayerFromId(Players[i])
            if xPlayer["job"]["name"] == "police" then
                policeOnline = policeOnline + 1
            end
        end
        if policeOnline >= Config.MinimumFleecaPolice then
            return true
        else
            return false
        end
    end)
 
    RegisterServerEvent('projectx-fleecabankrobbery:server:PdNotify', function()
        local xPlayer = ESX.GetPlayerFromId(source)
        local Players = ESX.GetPlayers()
        for i = 1, #Players do
            local xPlayer = ESX.GetPlayerFromId(Players[i])
            if xPlayer["job"]["name"] == "police" then
                TriggerClientEvent('esx:showNotification', source, 'A Fleeca bank is being robbed!')
            end
        end
        local coords = xPlayer.getCoords(true)
        TriggerClientEvent('projectx-fleecabankrobbery:client:PdNotify', coords)
    end)
 
    function DiscordLogCash(source, amount)
        if Config.DiscordLogStatus then
            local player = ESX.GetPlayerFromId(source)
            DiscordLog(player.getName().. ' - '..player.getIdentifier().."\n".."Log info: ".." **+** **"..amount.."**")
        end
    end
 
    function DiscordLogItem(source, item, amount, info)
        if Config.DiscordLogStatus then
            local player = ESX.GetPlayerFromId(source)
            if not info then
                DiscordLog(player.getName().. ' - '..player.getIdentifier().."\n".."Log info: ".." **+** **"..amount.."** **"..item.."**")
            else
                DiscordLog(player.getName().. ' - '..player.getIdentifier().."\n".."Log info: ".." **+** **"..amount.."** **"..item.."**".."**:"..info.."**")
            end
        end
    end
 
    function checkPerms(source)
        return IsPlayerAceAllowed(source, "group.admin") or IsPlayerAceAllowed(source, "group.god")
    end
else
 
end
 
function AddExperience(source, exp)
    if Config.ServerSideEvents then
        exports[""]:addExp("criminal", source, exp)
    else
        TriggerClientEvent("projectx-fleecabankrobbery:client:AddExperience", source, exp)
    end
end
 
function CheckExpLevel(source)
    if Config.ServerSideEvents then
        local level = exports[""]:GetSkillLevel('criminal', source)
        return level.level
    else
        TriggerClientEvent("projectx-fleecabankrobbery:client:CheckExpLevel", source)
    end
end
 
RegisterCommand('projectxfleeca', function(source)
	if not checkPerms(source) then return NotificationServer(source, Loc[Config.Lan].error["permission"], 'error', Config.NotificationDuration) end
    local pos = GetEntityCoords(GetPlayerPed(source))
    for k, v in pairs(Config.Fleecas) do
        if #(pos - vector3(v["AlarmCoords"]["x"], v["AlarmCoords"]["y"], v["AlarmCoords"]["z"])) <= 50.0 then
            ResetHeist(k)
            break
        end
        Wait(50)
    end
end, false)