🎉 Driving School is released. Read more →
Paid Scripts
Housing
Integrations
Spawn Selector Scripts
Wd Spawnselector

Wendigo Spawnselector

client.lua
cam = nil
cam2 = nil
currents = {}
isApartment = false
 
function SendReactMessage(action, data)
    SendNUIMessage({
        action = action,
        data = data
    })
end
 
function open(cData, new, apps)
    SetEntityVisible(pPed, false)
    DoScreenFadeOut(250)
    Wait(1000)
    DoScreenFadeIn(250)
 
    if not DoesCamExist(cam) then
        local camCoords = vector4(95.8534, 108.1032, 826.6528, 114.6077)
        cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", camCoords.x, camCoords.y, camCoords.z, 1.76, 0.0, 178.5,
            60.0, true, 0)
        SetCamActive(cam, true)
        RenderScriptCams(true, false, 0, true, true)
    end
    Wait(500)
 
    SetNuiFocus(true, true)
    SendReactMessage("setLang", cfg.locales[cfg.locale])
    SendReactMessage("HandleDisplay", true)
    if not new or cfg.useQBApartments == false then
        local formatLocations = function()
            local locations = {}
 
            for k, v in pairs(cfg.locations) do
                if not v.jobs then
                    table.insert(locations, v)
                else
                    for _, job in pairs(v.jobs) do
                        if job == getPlayerJobName(getPlayerData()) then
                            table.insert(locations, v)
                        end
                    end
                end
            end
 
            local homes = exports.bcs_housing:GetOwnedHomeKeys()
            for k, v in pairs(homes) do
                table.insert(locations, {
                    name = v.properties.name,
                    coords = v.properties.complex == 'Flat' and v.properties.data.flat.coords or v.properties.entry,
                    id = k,
                })
            end
 
            return locations
        end
        currents = formatLocations()
    else
        local _apps = {}
        local formatApartment = function(k, data)
            data.tmpName = data.name
            data.name = data.label
            data.identifier = k
            return data
        end
        for k, v in pairs(apps) do
            table.insert(_apps, formatApartment(k, v))
        end
        Apartments = _apps
        isApartment = true
        currents = _apps
    end
    updateCamera(1)
end
 
exports("open", open)
RegisterNetEvent("wd-spawnselector:open", open)
RegisterNetEvent("qb-spawn:client:openUI", open)
RegisterNetEvent("qb-spawn:client:setupSpawns", open)
RegisterCommand("wdspawn", open)
 
RegisterNUICallback("getLocations", function(data, cb)
    cb(currents)
end)
 
RegisterNUICallback("spawn", function(data, cb)
    local pPed = PlayerPedId()
    local locations = {}
    local id = data + 1
    if framework == "qb" and cfg.useQBApartments and Apartments then
        if Apartments.locations then
            for k, v in pairs(Apartments.Locations) do
                table.insert(locations, v)
            end
        else
            for i = 1, #Apartments, 1 do
                Apartments[i].id = #locations + 1
                table.insert(locations, Apartments[i])
            end
        end
    else
        for k, v in pairs(cfg.locations) do
            if not v.jobs then
                v.id = #locations + 1
                table.insert(locations, v)
            else
                for _, job in pairs(v.jobs) do
                    if job == getPlayerJobName(getPlayerData()) then
                        v.id = #locations + 1
                        table.insert(locations, v)
                    end
                end
            end
        end
    end
 
    local homes = exports.bcs_housing:GetOwnedHomeKeys()
    for k, v in pairs(homes) do
        local entry = v.properties.complex == 'Flat' and v.properties.data.flat.coords or v.properties.entry
        table.insert(locations, {
            name = v.properties.name,
            identifier = v.identifier,
            type = v.properties.type,
            coords = vec3(entry.x, entry.y, entry.z),
            id = #locations + 1,
        })
    end
 
    if framework == "qb" then
        --data = isApartment and locations[id] or cfg.locations[id]
 
        local found = false
        for i = 1, #locations do
            if locations[i].id == id then
                data = locations[i]
                found = true
                break
            end
        end
        if not found then
            data = cfg.locations[id]
        end
    else
        local locations = {}
 
        for k, v in pairs(cfg.locations) do
            if not v.jobs then
                table.insert(locations, v)
            else
                for _, job in pairs(v.jobs) do
                    if job == getPlayerJobName(getPlayerData()) then
                        table.insert(locations, v)
                    end
                end
            end
        end
 
        local homes = exports.bcs_housing:GetOwnedHomeKeys()
        for k, v in pairs(homes) do
            table.insert(locations, {
                name = v.properties.name,
                coords = v.properties.complex == 'Flat' and v.properties.data.flat.coords or v.properties.entry,
                id = k,
            })
        end
        data = locations[id]
    end
    if data.id == "lastLocation" then
        local pData = nil
        pData = getPlayerData()
        local pos = getPlayerLastLocation(pData)
        data.coords = vector4(pos.x, pos.y, pos.z, 0.0)
    end
 
    SendReactMessage("HandleDisplay", false)
    SetNuiFocus(false, false)
 
    SetEntityVisible(PlayerPedId(), true)
    if not isApartment or cfg.useQBApartments == false then
        local identifier = data.identifier
        if identifier and data.type ~= 'mlo' then
            SetTimeout(3500, function()
                TriggerEvent("Housing:client:EnterHome", identifier)
            end)
        else
            ---@diagnostic disable-next-line
            SetEntityCoords(pPed, data.coords.x, data.coords.y, data.coords.z)
        end
        doCamera(data.coords.x, data.coords.y, data.coords.z, data.coords.w)
        Wait(200)
    else
        SetTimeout(3500, function()
            ---@diagnostic disable-next-line
            SetEntityCoords(pPed, vec3(data.coords.x, data.coords.y, data.coords.z))
            Wait(1000)
            local identifier = data.identifier
            TriggerServerEvent('Housing:server:CreateApartment', identifier)
            Apartments = nil
            isApartment = false
        end)
    end
    endEvent()
 
    cb("ok")
end)
 
RegisterNUICallback("updateSelected", function(data, cb)
    updateCamera(data + 1)
    cb({ "ok" })
end)
 
function updateCamera(id)
    local data = nil
    local locations = {}
    if framework == "qb" and isApartment and cfg.useQBApartments and Apartments then
        if Apartments.locations then
            for k, v in pairs(Apartments.Locations) do
                table.insert(locations, v)
            end
        else
            for i = 1, #Apartments, 1 do
                Apartments[i].id = #locations + 1
                table.insert(locations, Apartments[i])
            end
        end
    else
        for k, v in pairs(cfg.locations) do
            if not v.jobs then
                -- v.id = #locations + 1
                table.insert(locations, v)
            else
                for _, job in pairs(v.jobs) do
                    if job == getPlayerJobName(getPlayerData()) then
                        v.id = #locations + 1
                        table.insert(locations, v)
                    end
                end
            end
        end
    end
 
 
    local homes = exports.bcs_housing:GetOwnedHomeKeys()
    for k, v in pairs(homes) do
        table.insert(locations, {
            name = v.properties.name,
            coords = v.properties.complex == 'Flat' and v.properties.data.flat.coords or v.properties.entry,
            id = #locations + 1,
        })
    end
    if framework == "qb" then
        --data = isApartment and locations[id] or cfg.locations[id]
        local found = false
        for i = 1, #locations do
            if locations[i].id == id then
                data = locations[i]
                found = true
                break
            end
        end
        if not found then
            data = cfg.locations[id]
        end
    else
        local locations = {}
 
        for k, v in pairs(cfg.locations) do
            if not v.jobs then
                table.insert(locations, v)
            else
                for _, job in pairs(v.jobs) do
                    if job == getPlayerJobName(getPlayerData()) then
                        table.insert(locations, v)
                    end
                end
            end
        end
 
        local homes = exports.bcs_housing:GetOwnedHomeKeys()
        for k, v in pairs(homes) do
            table.insert(locations, {
                name = v.properties.name,
                coords = v.properties.complex == 'Flat' and v.properties.data.flat.coords or v.properties.entry,
                id = k + 1,
            })
        end
        data = locations[id]
    end
    if isApartment then
        data.coords = locations[id].coords?.enter and locations[id].coords.enter or locations[id].enter
    end
 
    if data.id == "lastLocation" then
        data.coords = vector4(getPlayerLastLocation(getPlayerData()).x, getPlayerLastLocation(getPlayerData()).y,
            getPlayerLastLocation(getPlayerData()).z, 0.0)
    end
    doCamera(data.coords.x, data.coords.y, data.coords.z, data.coords.w)
end
 
function endEvent()
    ClearFocus()
    DestroyAllCams(true)
    RenderScriptCams(false, true, 1, true, true)
 
    cfg.afterPlayerSpawned()
end
 
function doCamera(x, y, z, w)
    CreateThread(function()
        DoScreenFadeOut(1)
        if (not DoesCamExist(cam)) then
            cam = CreateCam('DEFAULT_SCRIPTED_CAMERA', true)
        end
 
        i = 3200
        SetFocusArea(x, y, z, 0.0, 0.0, 0.0)
        SetCamActive(cam, true)
        RenderScriptCams(true, false, 0, true, true)
        DoScreenFadeIn(1500)
        local camAngle = -90.0
        while i > 1 do
            local factor = i / 50
            if i < 1 then i = 1 end
            i = i - factor
            SetCamCoord(cam, x + cfg.camPosition.x, y + cfg.camPosition.y, (z + cfg.camPosition.z) + i)
            if i < 1200 then
                DoScreenFadeIn(600)
            end
            if i < 90.0 then
                camAngle = i - i - i
            end
            SetCamRot(cam, camAngle, 0.0, w)
            Citizen.Wait(2 / i)
        end
    end)
end