#Spawn Selector

1 messages · Page 1 of 1 (latest)

torn rose
#

So you'd like only to see "last location" , or you want to skip that selection at all ?

gaunt temple
#

i don´t need to see "last location"

torn rose
#

Alright let me check the script

#

qb-spawn server.lua copy and paste this (assumingly you are using default qb core)

local QBCore = exports['qb-core']:GetCoreObject()

QBCore.Functions.CreateCallback('qb-spawn:server:getOwnedHouses', function(_, cb, cid)
    if cid ~= nil then
        local houses = MySQL.query.await('SELECT * FROM player_houses WHERE citizenid = ?', {cid})
        if houses[1] ~= nil then
            cb(houses)
        else
            cb({})
        end
    else
        cb({})
    end
end)

RegisterServerEvent('qb-spawn:server:loadPlayerData', function()
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    if not Player then return end

    local pos = Player.PlayerData.position

    if pos and pos.x ~= 0 and pos.y ~= 0 and pos.z ~= 0 then
        TriggerClientEvent('qb-spawn:client:setSpawnPos', src, pos)
    else
        TriggerClientEvent('qb-spawn:client:setupSpawns', src, false, false)
    end
end)

#

and in client.lua

Add this at the bottom :

RegisterNetEvent('qb-spawn:client:setSpawnPos', function(position)
    local ped = PlayerPedId()
    DoScreenFadeOut(500)
    Wait(1000)
    SetEntityCoords(ped, position.x, position.y, position.z)
    SetEntityHeading(ped, position.a or 0.0)
    ShutdownLoadingScreenNui()
    ShutdownLoadingScreen()
    Wait(500)
    DoScreenFadeIn(1000)
    TriggerServerEvent('QBCore:Server:OnPlayerLoaded')
    TriggerEvent('QBCore:Client:OnPlayerLoaded')
end)

#

Let me know if this works

torn rose
#

Insane have you tried this ?

gaunt temple
#

i do not use qb-spawn right now

#

and the code is not the same

torn rose
#

What is the name of that spawn resource

gaunt temple
#

is qb-spawn too

torn rose
#

I'm little confused, this is not the default spawn selector

gaunt temple
#

is not is another one

#

qb-spawn server.lua

local QBCore = exports['qb-core']:GetCoreObject()
QBCore.Functions.CreateCallback('qb-spawn:server:getOwnedHouses', function(source, cb, cid)
    if cid ~= nil then
        local houses = exports.oxmysql:executeSync("SELECT * FROM player_houses WHERE identifier = ? OR JSON_CONTAINS(keyholders, JSON_ARRAY(?))", {cid, cid})
        if houses[1] ~= nil then
            cb(houses)
        else
            cb(nil)
        end
    else
        cb(nil)
    end
end)

RegisterNetEvent("orangutan:spawn:getHouseCoords", function(houseName)
    local src = source
    if houseName then
        local house = exports.oxmysql:executeSync("SELECT * FROM houselocations WHERE name = ?", {houseName})
        if house[1] then
            local ped = GetPlayerPed(src)
            local data = json.decode(house[1].coords)
            local x, y, z = data.enter.x, data.enter.y, data.enter.z
            -- print(x, y, z)
            SetEntityCoords(ped, x, y, z, false, false, false, true)
        end
    end
end)

QBCore.Commands.Add("addloc", "Add location for spawn (God Only)", {}, false, function(source)
    local src = source
    TriggerClientEvent('qb-spawn:client:OpenUIForSelectCoord', src)
end, "god")

torn rose
#

So I assume, for "returning" player, or the player which has already an account on your server, you don't want them to get this interface upon logging into server?

gaunt temple
gaunt temple
#

i don´t want for exemple if the player dies in 1 place he can´t "quit" and login and change is location with spawn selector

#

so only works the interface in server restart

#

if don´t have server restart auto spawn in last location

torn rose
#

Can you send me server.lua

gaunt temple
#

@torn rose

torn rose
#

Will contact you a little later. Busy atm

torn rose
#

Checking out your support post now

#

SERVER.LUA

local QBCore = exports['qb-core']:GetCoreObject()
local serverSession = os.time()

QBCore.Functions.CreateCallback('qb-spawn:server:getOwnedHouses', function(source, cb, cid)
    if cid ~= nil then
        local houses = exports.oxmysql:executeSync("SELECT * FROM player_houses WHERE identifier = ? OR JSON_CONTAINS(keyholders, JSON_ARRAY(?))", {cid, cid})
        if houses[1] ~= nil then
            cb(houses)
        else
            cb(nil)
        end
    else
        cb(nil)
    end
end)

RegisterNetEvent("orangutan:spawn:getHouseCoords", function(houseName)
    local src = source
    if houseName then
        local house = exports.oxmysql:executeSync("SELECT * FROM houselocations WHERE name = ?", {houseName})
        if house[1] then
            local ped = GetPlayerPed(src)
            local data = json.decode(house[1].coords)
            local x, y, z = data.enter.x, data.enter.y, data.enter.z
            SetEntityCoords(ped, x, y, z, false, false, false, true)
        end
    end
end)

QBCore.Commands.Add("addloc", "Add location for spawn (God Only)", {}, false, function(source)
    TriggerClientEvent('qb-spawn:client:OpenUIForSelectCoord', source)
end, "god")

RegisterNetEvent("qb-core:playerJoined", function()
    local src = source
    local player = QBCore.Functions.GetPlayer(src)
    if player then
        local lastSession = player.PlayerData.metadata["last_session"] or 0
        if lastSession == serverSession then
            TriggerClientEvent("spawn:lastlocation", src)
        else
            TriggerClientEvent("qb-spawn:client:openUI", src, true)
        end
    end
end)

AddEventHandler("playerDropped", function()
    local src = source
    local player = QBCore.Functions.GetPlayer(src)
    if player then
        player.Functions.SetMetaData("last_session", serverSession)
    end
end)
gaunt temple
#

is not working

#

i have ui

torn rose
#

Did you clear your cache before testing ?

gaunt temple
#

no

#

i will try again

gaunt temple
#

yes now i clear my cache and steel appearing the ui

torn rose
#

Find out the exact resource name that you presented here and I might be able to help you. There is a NUI trigger somewhere which I can't figure out, if this was default qb-core it would already be solved.

gaunt temple
#

i can send you the script if you want, this nui is like nopixel inspired

torn rose
#

send me the resource

twin lagoon
#

I want this too but for the basic spawn of qbcore

torn rose
#

Woefrey there are already resolved topics about this for default spawn of qbcore , try searching around the support

twin lagoon
#

Okey

gaunt temple
#

Check! PM

torn rose
#

Do you want to skip the selection at all , or leave "last location" to be chosen in these scenarios

#

server.lua

local QBCore = exports['qb-core']:GetCoreObject()
local firstSpawnMenu = true

QBCore.Functions.CreateCallback('qb-spawn:server:getOwnedHouses', function(source, cb, cid)
    if cid ~= nil then
        local houses = exports.oxmysql:executeSync(
            "SELECT * FROM player_houses WHERE identifier = ? OR JSON_CONTAINS(keyholders, JSON_ARRAY(?))",
            { cid, cid }
        )
        if houses[1] ~= nil then
            cb(houses)
        else
            cb(nil)
        end
    else
        cb(nil)
    end
end)

RegisterNetEvent("orangutan:spawn:getHouseCoords", function(houseName)
    local src = source
    if houseName then
        local house = exports.oxmysql:executeSync(
            "SELECT * FROM houselocations WHERE name = ?",
            { houseName }
        )
        if house[1] then
            local ped = GetPlayerPed(src)
            local data = json.decode(house[1].coords)
            local x, y, z = data.enter.x, data.enter.y, data.enter.z
            SetEntityCoords(ped, x, y, z, false, false, false, true)
        end
    end
end)

QBCore.Commands.Add("addloc", "Add location for spawn (God Only)", {}, false, function(source)
    TriggerClientEvent('qb-spawn:client:OpenUIForSelectCoord', source)
end, "god")

AddEventHandler('QBCore:Server:OnPlayerLoaded', function(src)
    local isFresh = firstSpawnMenu
    firstSpawnMenu = false
    TriggerClientEvent('qb-spawn:client:openUI', src, isFresh)
    local Player = QBCore.Functions.GetPlayer(src)
    TriggerClientEvent('qb-spawn:client:setupSpawns', src, Player.PlayerData.citizenid, isFresh, {})
end)
#

After restart , everyone gets to choose where to spawn.

If disconnected player has an option to choose "last location"

torn rose
#

server.lua

local QBCore = exports['qb-core']:GetCoreObject()
local firstSpawnMenu = true

QBCore.Functions.CreateCallback('qb-spawn:server:getOwnedHouses', function(source, cb, cid)
    if cid then
        local houses = exports.oxmysql:executeSync(
            "SELECT * FROM player_houses WHERE identifier = ? OR JSON_CONTAINS(keyholders, JSON_ARRAY(?))",
            { cid, cid }
        )
        cb(houses[1] ~= nil and houses or nil)
    else
        cb(nil)
    end
end)

RegisterNetEvent("orangutan:spawn:getHouseCoords", function(houseName)
    local src = source
    if houseName then
        local house = exports.oxmysql:executeSync(
            "SELECT * FROM houselocations WHERE name = ?",
            { houseName }
        )
        if house[1] then
            local ped = GetPlayerPed(src)
            local data = json.decode(house[1].coords)
            SetEntityCoords(ped, data.enter.x, data.enter.y, data.enter.z, false, false, false, true)
        end
    end
end)

QBCore.Commands.Add("addloc", "Add location for spawn (God Only)", {}, false, function(source)
    TriggerClientEvent('qb-spawn:client:OpenUIForSelectCoord', source)
end, "god")

AddEventHandler('QBCore:Server:OnPlayerLoaded', function(src)
    local isFresh = firstSpawnMenu
    firstSpawnMenu = false
    if isFresh then
        TriggerClientEvent('qb-spawn:client:openUI', src, isFresh)
        local Player = QBCore.Functions.GetPlayer(src)
        TriggerClientEvent('qb-spawn:client:setupSpawns', src, Player.PlayerData.citizenid, isFresh, {})
    else
        TriggerClientEvent('qb-spawn:client:autoSpawn', src)
    end
end)
gaunt temple
#

client is to add this or replace?

torn rose
#

replace client lua with this 1

#

I'll be back later

gaunt temple
#

i get error when opens the ui

cursive ginkgo
#

We don't provide support for paid resources. You can contact the authors.

abstract wasp
# gaunt temple

Please for the love of god tell me you didn’t buy a server from nchub

gaunt temple
abstract wasp
#

Send link

gaunt temple
#

i dont find more

real yoke