Routing buckets: split game state

Originally published at: https://cookbook.fivem.net/2020/11/27/routing-buckets-split-game-state/

Server versions from pipeline ID 3245 and above have added a ‘routing bucket’ functionality, which is similar in concept to the ‘dimension’ or ‘virtual world’ functionality seen in prior non-Rockstar ■■■■■■■■■■■ implementations. For those unaware or lazy to search, one can assign a player or entity to a routing bucket, and they will only…

13 Likes

Any reason why bucket ID is limited to 63 only? Would you consider changing that in the future?

World grid allocation currently isn’t dynamic, this might be changed somewhen.

1 Like

Perhaps increasing kNumRoutingBuckets to higher number than 64 (like 256/512) would fit needs of everyone, at least for now - let’s take as an example a 1024 slot server that is a simple deathmatch 2v2 server. With 1024 players, 2 players per dimension giving us 512 dimensions.
Of course if an extra 112MB (if I calculated properly) of memory to allocate won’t be an overkill.

1 Like

It’s actually closer to 400mb of overhead

1 Like

Does this mean that events like the explosions and such will have a function extensions to handle the bucket it’s happening in or will it know in which bucket you are and only trigger it in there ?

Anyway to use more than 63 dimensions

I don’t understand how routing buckets work, however, in SA-MP we had “Virtual Worlds”, and they were unlimited (or better, limited to the max int32 value).
This allowed scripters to define constant offsets, and then add variable parts like player or house ids to them.
The following is an example of how I would use routing buckets if they were unlimited:

readonly int BUCKET_OFFSET_CHAR_CREATOR = 10000;
readonly int BUCKET_OFFSET_HOUSES = 20000;

// when sending a player to character creator/selector
void SendToCharacterCreator(Player player)
{
    player.TriggerEvent("goToCharacterCreator");
    SetPlayerRoutingBucket(player.Handle, BUCKET_OFFSET_CHAR_CREATOR + int.Parse(player.Handle));
}

// when entering a house
void EnterHouse(Player player, House house)
{
    player.TriggerEvent("enterHouse", house.Id);
    SetPlayerRoutingBucket(player.Handle, BUCKET_OFFSET_HOUSES + house.Id);
}

They are, however, since a while now, minus the memory used for world grid allocation per used ID.

How much memory and id’s are we talking about?

What’s the default dimension ID?
If I never used it before, and I make a new dimension (like house interior, or garage interior) how can I send the player back to the “normal” dimension? 0 ID is the default?

Set it back to 0

2 Likes

What is World grid allocation?