client/editable.lua

function loadPedClothing(skinData, charPed)
    if not skinData?.skin then return end
    if config.tgiann_clothing then return TriggerEvent('tgiann-clothing:client:loadPedClothing', skinData.skin, charPed) end
    if config.framework == "qb" then return TriggerEvent('qb-clothing:client:loadPlayerClothing', skinData.skin, charPed) end
end

function networkSessionStarted() -- Triggered when entering the game
    exports["spawnmanager"]:setAutoSpawn(false)
end

function multiCharMenuOpened()
    MumbleSetVolumeOverride(PlayerId(), 0.0)
    ShutdownLoadingScreen()
    ShutdownLoadingScreenNui()
    if config.framework == "esx" then
        TriggerEvent("esx:loadingScreenOff")
    end
end

function spawnChar(isNewChar, selectedCharData, spawnCoords, spawnData)
    MumbleSetVolumeOverride(PlayerId(), -1.0)
    FreezeEntityPosition(PlayerPedId(), false)
    SetEntityVisible(PlayerPedId(), true)
    if config.framework == "esx" then
        local skinData = selectedCharData?.skinData
        tgiCore.cbFunction("tgiann-multichar:spawnselector:CharacterChosen", function()
            exports.spawnmanager:spawnPlayer({
                x = spawnCoords.x,
                y = spawnCoords.y,
                z = spawnCoords.z,
                heading = spawnCoords.w,
                model = skinData.model or `mp_m_freemode_01`,
                skipFade = true,
            }, function()
                if config.tgiann_clothing then
                    return
                end
                if skinData then
                    if not skinData.model then
                        if skinData.sex == "female" then
                            skin.sex = 1
                        else
                            skin.sex = 0
                        end
                    end
                    TriggerEvent("skinchanger:loadSkin", skin)
                end
            end)
        end, selectedCharData.playerData.identifier)
    elseif config.framework == "qb" then
        teleportPlayer(spawnCoords)
        if isNewChar then
            if spawnData?.isApartment then
                TriggerServerEvent("apartments:server:CreateApartment", spawnData.apartType, spawnData.apartLabel)
            end
        else
            tgiCore.cbFunction("tgiann-multichar:spawnselector:CharacterChosen", function()
                local PlayerData = tgiCore.core.Functions.GetPlayerData()
                local insideMeta = PlayerData.metadata?.inside
                if spawnData?.isLast then -- last location
                    if insideMeta.house ~= nil then
                        local houseId = insideMeta.house
                        TriggerEvent('qb-houses:client:LastLocationHouse', houseId)
                    elseif insideMeta.apartment.apartmentType ~= nil or insideMeta.apartment.apartmentId ~= nil then
                        local apartmentType = insideMeta.apartment.apartmentType
                        local apartmentId = insideMeta.apartment.apartmentId
                        TriggerEvent('qb-apartments:client:LastLocationHouse', apartmentType, apartmentId)
                    end
                elseif spawnData?.isHouse then
                    TriggerEvent('qb-houses:client:enterOwnedHouse', spawnCoords)
                    TriggerServerEvent('qb-houses:server:SetInsideMeta', 0, false)
                    TriggerServerEvent('qb-apartments:server:SetInsideMeta', 0, 0, false)
                else
                    TriggerServerEvent('qb-houses:server:SetInsideMeta', 0, false)
                    TriggerServerEvent('qb-apartments:server:SetInsideMeta', 0, 0, false)
                end
                TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
                TriggerEvent('QBCore:Client:OnPlayerLoaded')
            end, selectedCharData.playerData.citizenid)
        end
    end
end

function teleportPlayer(coords)
    SetEntityCoords(PlayerPedId(), coords.x, coords.y, coords.z)
end

function takeScreenShoot()
    if GetResourceState("screenshot-basic") ~= "started" then
        print("You need screenshot-basic script")
        return false
    end
    local screenShotData = nil
    tgiCore.cbFunction("tgiann-multichar:multichar:getScreenshotWebHook", function(hook)
        if hook and hook ~= "" then
            exports['screenshot-basic']:requestScreenshotUpload(tostring(hook), "files[]", function(data)
                local image = json.decode(data)
                if image then
                    screenShotData = image.attachments[1].proxy_url
                    TriggerClientEvent("tgiann-multichar:notif", lang.photoUrlCopied, "success", 2500)
                else
                    screenShotData = false
                end
            end)
        else
            screenShotData = false
        end
    end)
    while screenShotData == nil do Wait(10) end
    return screenShotData
end

function getExtraSpawnLocations(selectedCharData)
    local data = {}
    if config.framework == "qb" then
        local waitCb = true
        tgiCore.cbFunction('tgiann-multichar:spawnselector:getOwnedHouses', function(houses)
            for i = 1, #houses do
                data[#data + 1] = {
                    label = Houses[houses[i].house].adress,
                    desc = "House",
                    icon = "house.svg",
                    coords = nil,
                    data = {
                        isHouse = true,
                    }
                }
            end
            waitCb = false
        end, selectedCharData.playerData.citizenid)
        while waitCb do Wait(10) end

        if config.qb_apartments then
            local waitCb2 = true
            tgiCore.cbFunction('apartments:GetOwnedApartment', function(result)
                if result then
                    local apartData = Apartments.Locations[result.type]
                    data[#data + 1] = {
                        label = result.label,
                        desc = "Apartment",
                        icon = "apartment.svg",
                        coords = apartData.coords.enter,
                        data = {
                            isApartment = true,
                            apartLabel = result.label,
                            apartType = result.type,
                            apartId = result.name
                        }
                    }
                    TriggerEvent('apartments:client:SetHomeBlip', result.type)
                end
                waitCb2 = false
            end, selectedCharData.playerData.citizenid)
            while waitCb2 do Wait(10) end
        end
    end
    return data
end

RegisterNetEvent("esx:playerLoaded")
AddEventHandler("esx:playerLoaded", function()
    while not tgiCore.core.GetPlayerData()?.loadout do Wait(100) end -- Wait for esx loadout
    TriggerServerEvent("esx:onPlayerSpawn")
    TriggerEvent("esx:onPlayerSpawn")
    TriggerEvent("playerSpawned")
    TriggerEvent("esx:restoreLoadout")
end)

RegisterNetEvent("tgiann-multichar:multichar:qbCharCreated")
AddEventHandler("tgiann-multichar:multichar:qbCharCreated", function()
    if config.qb_apartments and Apartments?.Starting then
        local apartSpawnmLocations = {}
        for apartType, data in pairs(Apartments.Locations) do
            apartSpawnmLocations[#apartSpawnmLocations + 1] = {
                label = data.label,
                desc = "Apartment",
                icon = "apartment.svg",
                coords = data.coords.enter,
                data = {
                    isApartment = true,
                    apartLabel = data.label,
                    apartType = apartType
                }
            }
        end
        setupSpawns(apartSpawnmLocations, false)
    else
        TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
        TriggerEvent('QBCore:Client:OnPlayerLoaded')
        TriggerServerEvent('qb-houses:server:SetInsideMeta', 0, false)
        TriggerServerEvent('qb-apartments:server:SetInsideMeta', 0, 0, false)
        TriggerEvent('qb-weathersync:client:EnableSync')
        TriggerEvent('qb-clothes:client:CreateFirstCharacter')
    end
end)

Last updated