[QBCore] Changing Spawn Dimension for Players

Essentially, I have new players spawn at a specific location to dress their character and adjust their look before jumping into the server for the first time; the issue is, I want every new player to spawn in this one custom interior to adjust their character, and the interior is rather small, so I’d prefer to have each player in there individually, regardless of whether 1 person is customizing, or 50 at a time. I was looking into the QB-Apartment and housing system, as multiple houses can use the same interior and everyone spawns in their own specific shell. I was planning on using this QBCore virtual dimension script to maybe set each individual dimension upon a new player teleporting there for the first time, but I was worried about performance impact on the server, so is there an alternative, or should the dimensions be fine?

QBCore Virtual Dimensions: https://github.com/LittleFishyy/apx-dimensions-qb

1 Like

Sending entering players to a dimension of their PlayerPedId() sounds interesting and when they go to exit the apartment changing area it goes back to a dimension 0 launch point, I like the idea.

2 Likes

That resource should be fine. I was going to suggest setting the player’s routing bucket on the server side, which is what that resource is doing. There should be no performance impact on the server…

I would not send them to a dimension of their client-side ped id. In rare instances, on different clients, a player’s ped id could be the same as another’s. Instead, set the player to a routing bucket based on their server id.

SetPlayerRoutingBucket(playerServerId, playerServerId)

And when you want them to be visible again to all other players:

SetPlayerRoutingBucket(playerServerId, 0)

Also, please note this is server side code.

2 Likes

So if these actions are taking place in my client side clothing script, the action of teleporting and etc, would I set my server main.lua with registers like

RegisterNetEvent('clothes:setBucket, function())
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    SetPlayerRoutingBucket(Player, Player)

and then something similar for the return, and they would execute right before the clothing script saves the ped after confirmation; is this correct?

1 Like

You’re very close. In that context,

SetPlayerRoutingBucket(Player, Player)

Player is a QBCore Player Data object. Not what you need. You need the player server id. That is also known as “source” or “src”. Your code should look like this:

RegisterNetEvent('clothes:setBucket', function(enabled)
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)
    if Player then
        if enabled then
            SetPlayerRoutingBucket(src, src)
        else
            SetPlayerRoutingBucket(src, 0)
        end
    end
end)

I added functionality for a toggle so you can call the same event to enter or leave a routing bucket. Simply pass a boolean argument telling the event whether it should instance the player or not.

1 Like

Seems to be working, thanks!

However, I am running into a separate issue now, not sure how considering I commented out the bucket routing and it still persists, but if you know anything about QBCore, maybe you could help?

So I have starting apartments disabled for the qb-multicharacter config file, so what happens is a player spawns in for the first time, multicharacter calls qb-clothing’s firstTime Character Register event or whatever, then within that, they’re teleported to the customization room, routing bucket is set, and they’re teleported out to spawn after the player saves their character, and the routing bucket is reset to 0, and boom, they spawn and can see players, works fine. However, when the player rejoins the server and selects their character, it makes them then select a starting apartment, which teleports them in and forces another clothing menu which resets their character that they already customized prior to logging off?

I assume somewhere in the clothing client that the firstTimeCharacter isn’t being set to false after executing the save and teleport, and qb-spawn is reading it as a new player when they rejoin the server; if you know the case, your answer is appreciated, if not, that’s fine, I’ll just post it as a formal question or keep looking, as I really haven’t spent any time searching for it yet.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.