Full View config.server.lua

Preview File Updated: v1.0.4 - 25.08.2024

SV = {}

SV.Database = {
    ['table:owned_vehicles'] = 'owned_vehicles', -- In default qb-core it will be 'player_vehicles'

    ['column:owner'] = 'owner', -- In default qb-core it will be 'citizenid'
    ['column:company'] = 'company',
    ['column:plate'] = 'plate',
    ['column:vehicle'] = 'vehicle', -- In default qb-core it will be 'mods'
    ['column:type'] = 'type',
}

SV.Webhooks = {
    ['PAY_FOR_IMPOUND'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",
    ['GET_FROM_IMPOUND'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",
    ['PAID_IMPOUND_BILL'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",

    ['PURCHASED_PARKING'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",

    ['PAY_STATION'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",

    ['RENTED_PARKING_SPACE'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",

    ['PURCHASED_COMPANY_VEH'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",
    ['GET_COMPANY_VEH'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",

    ['WITHDRAW'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",
    ['DEPOSIT'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",
    ['SELL_PARKING'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",
    ['RESELL_PARKING'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",

    ['VEHICLE_SELL'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",

    ['TOW_VEHICLE'] = "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX",
}

SV.WebhookText = {
    ['TITLE.PAY_FOR_IMPOUND'] = "",
    ['DESCRIPTION.PAY_FOR_IMPOUND'] = [[
        Player %s [%s] paid $%s with %s for impound %s vehicle (%s).
        Fine Title: "%s"
    ]],
    
    ['TITLE.GET_FROM_IMPOUND'] = "",
    ['DESCRIPTION.GET_FROM_IMPOUND'] = [[
        Player %s [%s] picked up vehicle %s from impound.
        Fine Title: "%s"
    ]],

    ['TITLE.PAID_IMPOUND_BILL'] = "",
    ['DESCRIPTION.PAID_IMPOUND_BILL'] = [[
        Player %s [%s] paid a bill of $%s with %s for impound (%s) vehicle %s - Issuer %s [%s]
    ]],

    ['TITLE.PURCHASED_PARKING'] = "",
    ['DESCRIPTION.PURCHASED_PARKING'] = [[
        Player %s [%s] purchased parking %s for $%s
    ]],

    ['TITLE.PAY_STATION'] = "",
    ['DESCRIPTION.PAY_STATION'] = [[
        Player %s [%s] paid %s with %s for a parking meter for %s vehicle at %s location - %s
    ]],

    ['TITLE.RENTED_PARKING_SPACE'] = "",
    ['DESCRIPTION.RENTED_PARKING_SPACE'] = [[
        Player %s [%s] rented a parking space %s in parking %s for %s days for $%s.
    ]],

    ['TITLE.PURCHASED_COMPANY_VEH'] = "",
    ['DESCRIPTION.PURCHASED_COMPANY_VEH'] = [[
        Player %s [%s] bought vehicle %s %s for $%s to company %s.
    ]],

    ['TITLE.GET_COMPANY_VEH'] = "",
    ['DESCRIPTION.GET_COMPANY_VEH'] = [[
        Player %s [%s] get vehicle %s %s to company %s.
    ]],
    
    ['TITLE.WITHDRAW'] = "",
    ['DESCRIPTION.WITHDRAW'] = [[
        Player %s [%s] withdrew $%s from %s parking account.
    ]],

    ['TITLE.DEPOSIT'] = "",
    ['DESCRIPTION.DEPOSIT'] = [[
        Player %s [%s] deposit $%s to %s parking account.
    ]],
    
    ['TITLE.SELL_PARKING'] = "",
    ['DESCRIPTION.SELL_PARKING'] = [[
        Player %s [%s] sold his parking %s automatically for $%s.
    ]],
    
    ['TITLE.RESELL_PARKING'] = "",
    ['DESCRIPTION.RESELL_PARKING'] = [[
        Player %s [%s] sold his parking %s (%s) to player %s [%s] for $%s.
    ]],

    ['TITLE.VEHICLE_SELL'] = "",
    ['DESCRIPTION.VEHICLE_SELL'] = [[
        Player %s [%s] sold vehicle %s to player %s [%s] for $%s.
    ]],
    
    ['TITLE.TOW_VEHICLE'] = "",
    ['DESCRIPTION.TOW_VEHICLE'] = [[
        Player %s [%s] towed vehicle %s to impound %s.

        Impouded By: %s
        Fine Title: %s
        Fine Amount: $%s
    ]],
}

SV.Webhook = function(webhook_id, title, description, color, footer)
    local DiscordWebHook = SV.Webhooks[webhook_id]
    local embeds = {{
        ["title"] = title,
        ["type"] = "rich",
        ["description"] = description,
        ["color"] = color,
        ["footer"] = {
            ["text"] = footer..' - '..os.date(),
        },
    }}
    PerformHttpRequest(DiscordWebHook, function(err, text, headers) end, 'POST', json.encode({embeds = embeds}), {['Content-Type'] = 'application/json'})
end

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

SV.getPlayerByIdentifier = function(identifier)
    if Config.Core == "ESX" then
        return Core.GetPlayerFromIdentifier(identifier)
    elseif Config.Core == "QB-Core" then
        return Core.Functions.GetPlayerByCitizenId(identifier)
    end
end

SV.getPlayersFromDatabase = function(jobName, cb)
    if Config.Core == "ESX" then
        MySQL.query("SELECT identifier, firstname, lastname FROM `users` WHERE `job`= ?", {jobName}, function(result)
            cb(result)
        end)
    elseif Config.Core == "QB-Core" then
        local players = MySQL.query.await("SELECT citizenid, charinfo FROM `players` WHERE `job` LIKE '%" .. jobName .. "%'", {})
        for k, v in pairs(players) do
            v.charinfo = json.decode(v.charinfo)
        end
        cb(players)
    end
end

SV.getCharacterName = function(xPlayer)
    if Config.Core == "ESX" then
        return xPlayer.getName()
    elseif Config.Core == "QB-Core" then
        return xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname
    end
end

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

SV.getPlayerJob = function(xPlayer)
    if Config.Core == "ESX" then
        return xPlayer.job.name
    elseif Config.Core == "QB-Core" then
        return xPlayer.PlayerData.job.name
    end
end

SV.getPlayerJobGrade = function(xPlayer)
    if Config.Core == "ESX" then
        return xPlayer.job.grade
    elseif Config.Core == "QB-Core" then
        return xPlayer.PlayerData.job.grade.level
    end
end

SV.getMoney = function(xPlayer, moneyType)
    if Config.Core == "ESX" then
        local moneyType = moneyType == 'cash' and 'money' or moneyType
        return xPlayer.getAccount(moneyType).money
    elseif Config.Core == "QB-Core" then
        return xPlayer.Functions.GetMoney(moneyType)
    end
end

SV.addMoney = function(xPlayer, moneyType, count)
    if Config.Core == "ESX" then
        local moneyType = moneyType == 'cash' and 'money' or moneyType == 'dirty' and 'black_money' or moneyType
        xPlayer.addAccountMoney(moneyType, count)
    elseif Config.Core == "QB-Core" then
        xPlayer.Functions.AddMoney(moneyType, count)
    end
end

SV.removeMoney = function(xPlayer, moneyType, count)
    if Config.Core == "ESX" then
        local moneyType = moneyType == 'cash' and 'money' or moneyType
        xPlayer.removeAccountMoney(moneyType, count)
    elseif Config.Core == "QB-Core" then
        xPlayer.Functions.RemoveMoney(moneyType, count)
    end
end

SV.getSocietyMoney = function(societyName, cb)
    if GetResourceState('cs_bossmenu') == "started" then
        local society = exports['cs_bossmenu']:GetAccount(societyName)
        cb(society)
        
    elseif GetResourceState('okokBanking') == "started" then
        local society = exports['okokBanking']:GetAccount(societyName)
        cb(society)

    elseif GetResourceState('qb-banking') == "started" then
        local society = exports['qb-banking']:GetAccountBalance(societyName)
        cb(society)

    elseif GetResourceState('qb-management') == "started" then
        local society = exports['qb-management']:GetAccount(societyName)
        cb(society)

    elseif GetResourceState('esx_society') == "started" then
        TriggerEvent('esx_addonaccount:getSharedAccount', societyName, function(account)
            cb(account.money)
        end)

    else
        print('^5[INFO] ^7No society found for your server, go to vms_garagesv2/config/config.server.lua and adjust ^2SV.getSocietyMoney^7!')
        
    end
    
end

SV.addSocietyMoney = function(societyName, amount)
    if GetResourceState('cs_bossmenu') == "started" then
        exports['cs_bossmenu']:AddMoney(societyName, amount)
        
    elseif GetResourceState('okokBanking') == "started" then
        exports['okokBanking']:AddMoney(societyName, amount)

    elseif GetResourceState('qb-banking') == "started" then
        exports['qb-banking']:AddMoney(societyName, amount)

    elseif GetResourceState('qb-management') == "started" then
        exports['qb-management']:AddMoney(societyName, amount)

    elseif GetResourceState('esx_society') == "started" then
        TriggerEvent('esx_addonaccount:getSharedAccount', societyName, function(account)
            account.addMoney(amount)
        end)
        
    else
        print('^5[INFO] ^7No society found for your server, go to vms_garagesv2/config/config.server.lua and adjust ^2SV.addSocietyMoney^7!')
        
    end
end

SV.removeSocietyMoney = function(societyName, amount)
    if GetResourceState('cs_bossmenu') == "started" then
        exports['cs_bossmenu']:RemoveMoney(societyName, amount)
        
    elseif GetResourceState('okokBanking') == "started" then
        exports['okokBanking']:RemoveMoney(societyName, amount)

    elseif GetResourceState('qb-banking') == "started" then
        exports['qb-banking']:RemoveMoney(societyName, amount)

    elseif GetResourceState('qb-management') == "started" then
        exports['qb-management']:RemoveMoney(societyName, amount)

    elseif GetResourceState('esx_society') == "started" then
        TriggerEvent('esx_addonaccount:getSharedAccount', societyName, function(account)
            account.removeMoney(amount)
        end)
        
    else
        print('^5[INFO] ^7No society found for your server, go to vms_garagesv2/config/config.server.lua and adjust ^2SV.removeSocietyMoney^7!')
        
    end
end

SV.getItemCount = function(xPlayer, name)
    if Config.Core == "ESX" then
        return xPlayer.getInventoryItem(name).count
    elseif Config.Core == "QB-Core" then
        return xPlayer.Functions.GetItemByName(name) and xPlayer.Functions.GetItemByName(name).amount or 0
    end
end

SV.addItem = function(xPlayer, name, count)
    if Config.Core == "ESX" then
        xPlayer.addInventoryItem(name, count)
    elseif Config.Core == "QB-Core" then
        xPlayer.Functions.AddItem(name, count)
    end
end

SV.removeItem = function(xPlayer, name, count)
    if Config.Core == "ESX" then
        xPlayer.removeInventoryItem(name, count)
    elseif Config.Core == "QB-Core" then
        xPlayer.Functions.RemoveItem(name, count)
    end
end

SV.GiveCar = function(Player, owner, model, plate, type)
    MySQL.Async.execute(('INSERT INTO `%s` (`%s`, `%s`, `%s`, `%s`, `%s`, `garage`, `impound_date`) VALUES (@owner, @company, @plate, @vehicle, @type, @garage, @impound_date)'):format(
        SV.Database['table:owned_vehicles'],
        SV.Database['column:owner'],
        SV.Database['column:company'],
        SV.Database['column:plate'],
        SV.Database['column:vehicle'],
        SV.Database['column:type']
    ), {
        ['@owner'] = Player and SV.getIdentifier(Player) or nil,
        ['@company'] = not tonumber(owner) and owner or nil,
        ['@plate'] = plate,
        ['@vehicle'] = json.encode({['model'] = GetHashKey(model), ['plate'] = plate}),
        ['@type'] = Config.VehicleTypes[type].name,
        ['@garage'] = Config.VehicleTypes[type].defaultImpound,
        ['@impound_date'] = os.time(),
    })
end

Last updated