config.server.lua

Preview File Updated: v1.0.9 - 08/07/2025

SV = {}

SV.getPlayer = function(src)
    if Config.Core == "ESX" then
        return ESX.GetPlayerFromId(src)
    elseif Config.Core == "QB-Core" then
        return QBCore.Functions.GetPlayer(src)
    end
end

SV.getIdentifier = function(xPlayer)
    if Config.Core == "ESX" then
        return xPlayer.identifier
    elseif Config.Core == "QB-Core" then
        return xPlayer.PlayerData.citizenid
    end
    return nil
end


SV.checkToCancel = function(source, cb)
    local source = source
    local xPlayer = SV.getPlayer(source)
    local myIdentifier = SV.getIdentifier(xPlayer)

    if GetResourceState('vms_housing') == 'started' then
        if Config.Core == 'ESX' then
            local db = MySQL.query.await('SELECT last_property FROM users WHERE identifier = ?', {myIdentifier})
            local lastProperty = json.decode(db[1].last_property)
            if lastProperty and lastProperty.id then
                return cb(true)
            end
        else
            local db = MySQL.query.await('SELECT last_property FROM players WHERE citizenid = ?', {myIdentifier})
            local lastProperty = json.decode(db[1].last_property)
            if lastProperty and lastProperty.id then
                return cb(true)
            end
        end
    end

    cb(false)
end

SV.getJailStatus = function(source, cb)
    local source = source
    local xPlayer = SV.getPlayer(source)
    local myIdentifier = SV.getIdentifier(xPlayer)

    

    if GetResourceState('esx_jail') == 'started' then
        local myJail = MySQL.query.await('SELECT jail_time FROM users WHERE identifier = ?', {myIdentifier})
        if myJail[1] and myJail[1].jail_time >= 1 then
            TriggerEvent('esx_jail:sendToJail', xPlayer.source, myJail[1].jail_time, true)
            cb(true)
        else
            cb(false)
        end
        
    elseif GetResourceState('esx-qalle-jail') == 'started' then
        local myJail = MySQL.query.await('SELECT jail FROM users WHERE identifier = ?', {myIdentifier})
        if myJail[1] and myJail[1].jail >= 1 then
            cb(true)
        else
            cb(false)
        end
        
    elseif GetResourceState('mx_jail') == 'started' then
        local myJail = MySQL.query.await('SELECT jail_time FROM users WHERE identifier = ?', {myIdentifier})
        if myJail[1] and myJail[1].jail_time ~= 0 then
            cb(true)
        else
            cb(false)
        end
        
    elseif GetResourceState('qb-prison') == 'started' then
        if xPlayer and xPlayer.PlayerData and xPlayer.PlayerData.metadata.injail and xPlayer.PlayerData.metadata.injail >= 1 then
            cb(true)
        else
            cb(false)
        end

    elseif GetResourceState('pickle_prisons') == 'started' then
        local myJail = MySQL.query.await('SELECT * FROM pickle_prisons WHERE identifier = ?', {myIdentifier})
        if myJail then
            cb(true)
        else
            cb(false)
        end

    elseif GetResourceState('rcore_prison') == 'started' then
        local state, statusCode = exports.rcore_prison:IsPrisoner(source)
        if state then
            cb(true)
        else
            cb(false)
        end
        
    else
        cb(false)

    end
end

SV.getHousings = function(source, cb)
    local xPlayer = SV.getPlayer(source)
    local myIdentifier = SV.getIdentifier(xPlayer)

    if GetResourceState('vms_housing') == 'started' then
        local properties = exports['vms_housing']:GetPlayerProperties(myIdentifier)
        if properties and next(properties) then
            local myHouses = {}
            for k, v in pairs(properties) do
                if (v.type == 'shell' or v.type == 'ipl') and v.object_id and not v.metadata.exit then
                    local buildingData = exports['vms_housing']:GetProperty(v.object_id)
                    if buildingData then
                        myHouses[#myHouses + 1] = {
                            label = v.name,
                            address = v.address,
                            coords = buildingData.metadata.exit
                        }
                    end
                elseif v.type == 'mlo' then
                    myHouses[#myHouses + 1] = {
                        label = v.name,
                        address = v.address,
                        coords = v.metadata.menu
                    }
                else
                    myHouses[#myHouses + 1] = {
                        label = v.name,
                        address = v.address,
                        coords = v.metadata.exit
                    }
                end
            end
            cb(true, myHouses)
        else
            cb(nil)
        end

    elseif GetResourceState('esx_property') == 'started' then
        local propertiesList = LoadResourceFile('esx_property', 'properties.json')
        if propertiesList then
            local allHouses = json.decode(propertiesList)
            local myHouses = {}
            for k, v in pairs(allHouses) do
                if v.Owner == myIdentifier then
                    myHouses[#myHouses + 1] = {
                        label = v.Name,
                        coords = v.Entrance
                    }
                end
            end
            if myHouses[1] then
                cb(true, myHouses)
            else
                cb(nil)
            end
        end
    elseif GetResourceState('qs-housing') == 'started' then
        local allHouses = MySQL.query.await('SELECT * FROM houselocations')
        if allHouses[1] then
            local listedHouses = {}
            for k, v in pairs(allHouses) do
                listedHouses[v.name] = {
                    label = v.label,
                    coords = json.decode(v.coords).enter
                }
            end
            local myHouses = MySQL.query.await('SELECT * FROM player_houses WHERE citizenid = ?', {myIdentifier})
            if myHouses and myHouses[1] ~= nil then
                cb(listedHouses, myHouses)
            else
                cb(nil)
            end
        else
            cb(nil)
        end
    elseif GetResourceState('qb-houses') == 'started' then
        local allHouses = MySQL.query.await('SELECT * FROM houselocations')
        if allHouses[1] then
            local listedHouses = {}
            for k, v in pairs(allHouses) do
                listedHouses[v.name] = {
                    label = v.label,
                    coords = json.decode(v.coords).enter
                }
            end
            local myHouses = MySQL.query.await('SELECT * FROM player_houses WHERE citizenid = ?', {myIdentifier})
            if myHouses and myHouses[1] ~= nil then
                cb(listedHouses, myHouses)
            else
                cb(nil)
            end
        else
            cb(nil)
        end
    elseif GetResourceState('ps-housing') == 'started' then
        local myHouses = MySQL.query.await('SELECT * FROM properties WHERE owner_citizenid = ?', {myIdentifier})
        if myHouses and myHouses[1] ~= nil then
            cb(true, myHouses)
        else
            cb(nil)
        end
    elseif GetResourceState('bcs_housing') == 'started' then
        local myHouses = exports['bcs_housing']:GetOwnedHomes(myIdentifier)
        if myHouses and myHouses[1] ~= nil then
            cb(true, myHouses)
        else
            cb(nil)
        end
    else
        cb(false, false)
    end
end

Last updated

Was this helpful?