Small Example Showcasing Use Of Routing Buckets

As of late, I’ve had quite a few people ask me about the routing bucket natives and about practical examples of the use of the routing bucket Natives (Such as: GetEntityRoutingBucket & SetPlayerRoutingBucket)

According to the FiveM cookbook:

For those unaware or lazy to search, one can assign a player or entity to a routing bucket, and they will only see entities (and players) that belong to the same routing bucket. In addition to that, each routing bucket will have its own ‘world grid’ for determining population owners, so even if you have population enabled, you’ll notice nothing unusual at all when using routing buckets.

As we can see from the official definition, routing buckets allow us to create a state were a player will only see players and entities (Such as spawned props) in the same routing bucket as them. By default, routing buckets start off at 0. Routing buckets are most particularly useful to in frameworks that make use of character selection screens - as a commonly reported problem with various scripts that have such a feature is the entities of other players being visible to the player in a scenario where they shouldn’t be.

Another great example can be found here - however, I wanted to keep my own example shorter and easier to understand for those who may not be tech savy. In the sample code too I decided to store some data in KVP rather than a table.

Routing Bucket Sample:

1 Like

Hey! Really appreciate the link! But i dont see why you would use the kvp native instead of your own kvp array? Doesnt this just add overhead?

That was very intentional from my part, a subtle way of showcasing the kvp natives. It’d probably be far more practical to use an array (Since the array would be wiped on server restart which is what we want of course because there’d be no players in any bucket) but the whole point of the showcase is to show some of those different methods :slight_smile:

Fair enough! Lovely example none the less :slight_smile: