editable.lua

local intCharset, charset = {}, {}

editableFunctions = {}

for i = 48, 57 do intCharset[#intCharset + 1] = string.char(i) end
for i = 65, 90 do charset[#charset + 1] = string.char(i) end

local function GetRandomInt(length)
    Wait(0)
    math.randomseed(GetGameTimer())
    if length > 0 then
        return GetRandomInt(length - 1) .. intCharset[math.random(1, #intCharset)]
    else
        return ''
    end
end

local function GetRandomLetter(length)
    Wait(0)
    math.randomseed(GetGameTimer())
    if length > 0 then
        return GetRandomLetter(length - 1) .. charset[math.random(1, #charset)]
    else
        return ''
    end
end

editableFunctions.DeletePlayerVehicle = function(plate)
    local result = MySQL.query.await('DELETE FROM  ' .. config.vehicleTableName .. ' WHERE plate = ?', { plate })
    return result.affectedRows > 0
end

editableFunctions.IsPlayerVehicle = function(plate, src)
    local xPlayer = tgiCore.getPlayer(src)
    if not xPlayer then return end
    if config.framework == "qb" then
        return MySQL.single.await('SELECT plate FROM ' .. config.vehicleTableName .. ' WHERE plate = ? AND citizenid = ? LIMIT 1', { plate, tgiCore.getCid(xPlayer) })
    elseif config.framework == "esx" then
        return MySQL.single.await('SELECT plate FROM ' .. config.vehicleTableName .. ' WHERE plate = ? AND owner = ? LIMIT 1', { plate, tgiCore.getCid(xPlayer) })
    end
end

editableFunctions.GeneratePlate = function()
    local newPlate = nil
    while true do
        math.randomseed(GetGameTimer())
        local generatedPlate = string.upper(GetRandomInt(3) .. GetRandomLetter(3) .. GetRandomInt(2))
        local result = MySQL.single.await('SELECT plate FROM ' .. config.vehicleTableName .. ' WHERE plate = ? LIMIT 1', { generatedPlate })
        if not result then
            newPlate = generatedPlate
            break
        else
            Wait(100)
        end
        Wait(0)
    end
    return newPlate
end
exports("GeneratePlate", editableFunctions.GeneratePlate)

editableFunctions.RemoveJobMoney = function(amount, job)
    if config.framework == "qb" then
        if not pcall(function()
                exports['qb-banking']:RemoveMoney(job, amount)
            end) then
            return exports['qb-management']:RemoveMoney(job, amount)
        end
    elseif config.framework == "esx" then
        if not pcall(function()
                local sharedAccount = exports["esx_addonaccount"]:getSharedAccount("society_" .. job)
                if not sharedAccount then return print("society_" .. job .. " Not Found On Database addon_account and addon_account_data table") end
                if sharedAccount.money < amount then return false end
                sharedAccount.removeMoney(amount)
                return true
            end) then
            for _ = 1, 10 do
                print("getSharedAccount export not found! Please Update your esx_addonaccount script")
            end
            return false
        end
    end
end

editableFunctions.AddJobMoney = function(amount, job)
    if config.framework == "qb" then
        if not pcall(function()
                exports['qb-banking']:AddMoney(job, amount)
            end) then
            return exports['qb-management']:AddMoney(job, amount)
        end
    elseif config.framework == "esx" then
        if not pcall(function()
                local sharedAccount = exports["esx_addonaccount"]:getSharedAccount("society_" .. job)
                if not sharedAccount then return print("society_" .. job .. " Not Found On Database addon_account and addon_account_data table") end
                account.addMoney(amount)
            end) then
            for _ = 1, 10 do
                print("getSharedAccount export not found! Please Update your esx_addonaccount script")
            end
        end
    end
end

editableFunctions.AddVehicleToDB = function(xPlayer, vehicleData)
    vehicleData.properties.plate = editableFunctions.GeneratePlate()
    if config.tgiannServer then
        MySQL.insert('INSERT INTO player_vehicles (citizenid, plate, vehicle) VALUES (?, ?, ?)', {
            xPlayer.PlayerData.citizenid,
            vehicleData.properties.plate,
            json.encode(vehicleData.properties),
        })
    elseif config.framework == "qb" then
        MySQL.insert('INSERT INTO ' .. config.vehicleTableName .. ' (license, citizenid, vehicle, hash, mods, plate, state) VALUES (?, ?, ?, ?, ?, ?, ?)', {
            xPlayer.PlayerData.license,
            xPlayer.PlayerData.citizenid,
            vehicleData.model,
            joaat(vehicleData.model),
            json.encode(vehicleData.properties),
            vehicleData.properties.plate,
            0
        })
    elseif config.framework == "esx" then
        MySQL.insert('INSERT INTO ' .. config.vehicleTableName .. ' (owner, plate, vehicle) VALUES (?, ?, ?)', {
            xPlayer.identifier,
            vehicleData.properties.plate,
            json.encode(vehicleData.properties),
        })
    end

    return vehicleData.properties.plate
end

function editableFunctions.SendLog(src, webhook, msg)
    TriggerEvent("tgiann-core:discordLog", webhooks[webhook], msg, src)
end

function editableFunctions.RegisterEsxSociety(jobName)
    TriggerEvent('esx_society:registerSociety', jobName, jobName, 'society_' .. jobName, 'society_' .. jobName, 'society_' .. jobName, { type = 'private' })
end

Last updated