[Tutorial] How to use Routing Buckets easily :) / The correct way to instance people

Server Side Code:

     
local instances = {}
 
RegisterServerEvent("instance:set")
AddEventHandler("instance:set", function(set)
 
    print('[INSTANCES] Instances now looked like this: ', json.encode(instances))
    local src = source
 
    TriggerClientEvent('DoTheBigRefreshYmaps', src)
    local instanceSource = 0
    if set then
        if set == 0 then
            for k,v in pairs(instances) do
                for k2,v2 in pairs(v) do
                    if v2 == src then
                        table.remove(v, k2)
                        if #v == 0 then
                            instances[k] = nil
                        end
                    end
                end
            end
        end
        instanceSource = set
    else
 
        instanceSource = math.random(1, 63)
 
        while instances[instanceSource] and #instances[instanceSource] >= 1 do
            instanceSource = math.random(1, 63)
            Citizen.Wait(1)
        end
    end
 
    print(instanceSource)
 
    if instanceSource ~= 0 then
        if not instances[instanceSource] then
            instances[instanceSource] = {}
        end
 
        table.insert(instances[instanceSource], src)
    end
 
    SetPlayerRoutingBucket(
        src --[[ string ]], 
        instanceSource
    )
    print('[INSTANCES] Instances now looks like this: ', json.encode(instances))
end)
 
Namedinstances = {}
 
 
RegisterServerEvent("instance:setNamed")
AddEventHandler("instance:setNamed", function(setName)
 
    print('[INSTANCES] Named Instances looked like this: ', json.encode(Namedinstances))
    local src = source
    local instanceSource = nil
 
    TriggerClientEvent('DoTheBigRefreshYmaps', src)
 
    if setName == 0 then
            for k,v in pairs(Namedinstances) do
                for k2,v2 in pairs(v.people) do
                    if v2 == src then
                        table.remove(v.people, k2)
                    end
                end
                if #v.people == 0 then
                    Namedinstances[k] = nil
                end
            end
        instanceSource = setName
 
    else
        for k,v in pairs(Namedinstances) do
            if v.name == setName then
                instanceSource = k
            end
        end
 
        if instanceSource == nil then
            instanceSource = math.random(1, 63)
 
            while Namedinstances[instanceSource] and #Namedinstances[instanceSource] >= 1 do
                instanceSource = math.random(1, 63)
                Citizen.Wait(1)
            end
        end
    end
 
    if instanceSource ~= 0 then
 
        if not Namedinstances[instanceSource] then
            Namedinstances[instanceSource] = {
                name = setName,
                people = {}
            }
        end
 
        table.insert(Namedinstances[instanceSource].people, src)
 
    end
 
    SetPlayerRoutingBucket(
        src --[[ string ]], 
        instanceSource
    )
    print('[INSTANCES] Named Instances now look like this: ', json.encode(Namedinstances))
end)

This can be used like so.

-- Add someone to any available instance. (use this when you dont need to add others to the same instance)

TriggerServerEvent('instance:set')

-- Then to put them back into the normal instance

TriggerServerEvent('instance:set', 0)

-- Use the follwing when you would like to add multiple people to the same instance.

TriggerServerEvent('instance:setNamed', 'InstanceName')  -- InstanceName can be any string, e.g Apartment-26

-- Then to put them back into the normal instance

TriggerServerEvent('instance:setNamed', 0)
10 Likes

Are instances still limited to 1~63?

1 Like

The real question is : why people still think it is limited to 1~63?

I believe that it no longer is :slight_smile:

1 Like

Much appreciated :slight_smile:

1 Like

Can I use this for interiors?

yeah :slight_smile:

1 Like

Good evening I come very late in the conversation but I have a fundamental question for a beginner like me. Once the person is in the instance we don’t see each other anymore and we don’t have collision with other players in the same place. It’s great but for the use of audio via Mumble as it uses a form of proximity we will hear the people around us and this will cause problem. how can i solve this problem please. I am asking this because I would like to use this instance system to create my interiors but I have this sound problem in my head. Thank you for the help

Im sure someones made a version of mumble that checks for instanceing. If they havent, im sure its easy enough to implement.

1 Like

Unfortunately I have never seen such a thing if you find anything please tell me I have been looking for this for some time :slight_smile:

Hi! I created a PolyZone and 2 events, entering en leaving.
In this zone there is a blip to tune your car. When i enter the zone my car disappears and the blip to start the tuning is gone.
I use SetPlayerRoutingBucket and SetEntityRoutingBucket, but im getting confused now.
Is there someone with experience online that can help me.
Here is my code:
Client Side

CustomsCarShop = PolyZone:Create({
    vector2(1013.352355957, -2340.9377441406),
    vector2(998.34094238281, -2339.3955078125),
    vector2(1000.4670410156, -2322.9577636719),
    vector2(1014.1751708984, -2324.3190917969)
}, {
    name="CustomsCarShop",
    minZ = 20,
    maxZ = 34,
    debugPoly = true
})

CustomsCarShop:onPlayerInOut(function(isPointInside)
    if isPointInside then
        inCustomsCarShop = true
        TriggerServerEvent('qb-customs:enterBucket', src)
    else
        inCustomsCarShop = false
        TriggerServerEvent('qb-customs:exitBucket', src)
    end
end)

Server Side

    local src = source
    local cplayerid = (GetPlayerPed(src))
    local GetEntityRouting = GetEntityRoutingBucket(cplayerid)
    SetPlayerRoutingBucket(src, 0)
    SetEntityRoutingBucket(GetEntityRouting, 0)
    print("[PlayerID:"  .. cplayerid .."] Inside:" .. GetEntityRouting)
end)

RegisterNetEvent('qb-customs:exitBucket', function()
    local src = source
    local cplayerid = (GetPlayerPed(src))
    local GetEntityRouting = GetEntityRoutingBucket(cplayerid)
    SetPlayerRoutingBucket(src, cplayerid)
    SetEntityRoutingBucket(GetEntityRouting, cplayerid)
    print("[PlayerID:"  .. cplayerid .."] Outside:" .. GetEntityRouting)
end)```

I can also share a little video to show you what happens.
Any thoughts?
1 Like

Probably because you ask for the entity routing bucket of the player when the players routing bucket hasn’t been set yet.

Try first setting the player in the correct routing, then do the GetEntityRoutingBucket and then setting the entity routing of the vehicle.

Thanks! But i got it working.
But i am setting it first, before asking lol xD My current code is working.

1 Like

This would work for creating custom lobbies inside of one server yeah?

For example, like a PvP lobby, a Chill lobby, and etc.?

Yes, take a look at how RSM Freeroam uses buckets to have different lobbies.

Hello,

I am trying to use this for when I want people to be inside of an interior and not have the sun shining through the ceiling. Has anyone made a mod like this?

Thank you!

I’m using a safezone script where I’m using SetPlayerRoutingBucket and GetEntityRoutingBucket for vehicles, however when a Player drives in and out of the safe zone he changes the size of the vehicle, everything is fine and without problems, what happens is if the vehicle has a driver and a passenger, then the driver stays in the previous dimension and does not change dimensions together, the vehicle and the 2 occupants of the game, can anyone help me with a solution?

Hey! I am having a super hard time trying to get people to see other people in my server. Not sure if these routing buckets got enabled by a script of some sort, but every time there is 1-2 people who can’t see others. How can I just disable this completely? Going to be introducing housing as a primary source of…well housing. Going to do away with apartment entirely since it is causing so many issues. Any help is appreciated! It is driving me crazy haha.

so idk if this is a dumb question but what if you need to GET the routing bucket a player is in?

Edit I figured it out