[Routing Buckets && General] Entity Management

Hey yall!

Looking at the concept of a mission manager script within FiveM using the lovely routing buckets, routing buckets, routing buckets, and routing buckets, and it has me curious.

Are routing buckets somehow ‘initialized’ when you first send players and entities to them?

Or do they always exist waiting for players to and entities to be sent to them ?

This leads me to my main question - Other than tracking the entities spawned via database or some table, is there an effective way to clear out any (non-zero) routing buckets and revert it back to it’s default state.

The reason I ask is because it can be really easy to lose track of what you put where (if you’re not careful), and I doubt leaving things laying around is resource efficient for the server (but I may be wrong here).

I’m envisioning maybe some (reset-routing bucket) function that deletes any entities therein, and places players BACK to the default routing bucket set, but IDK if that’s possible, realistic, or even necessary.

What do you guys think?

There are natives SetRoutingBucketPopulationEnabled and SetRoutingBucketEntityLockdownMode for handling population / entities in specific bucket.

I don’t know if I understand correctly your problem, but my solution would be simple. If you want one bucket to keep the state when all entities are deleted and then return it, just use another bucket. You’ll have one with the content you want to keep and use the other for your use case. For the empty bucket you can use the natives I wrote above.

But no, you can’t keep non-script-generated entities unless someone is still near those entities in the bucket and they are no longer networked. Once you reconnect from another bucket, the entities don’t exist for you, and the moment you reconnect back, they get different entity IDs or no longer exist at all.

The only thing you keep are your persistent entities (for example created on coordinates from the database) and networked ones created for that particular bucket while you are in it or created from the server and set to specific bucket via SetEntityRoutingBucket.

1 Like

Hmm, so does this mean I don’t have to worry about anally strict entity management?

For example, picture a server with minigames that have rounds, or missions (as another example).

In either of these cases, there’ll be entities that the client may spawn, (they may cheat and force spawn entities / they may generate legit entities such as traffic), and there are server-generated entities.

Are you saying that these entities will just go away?

Context, I’m using Vmenu on my test server, and I spawned a vehicle in Routingbucket 1, teleported back to routing bucket 0, and then back to routing bucket 1, set the lockdown mode to “No entites” and low and behold my vehicle was still there.

This made me realize that there are going to be instances in which I store players and entities and may forget them (if I’m not careful). I know the obvious answer is: “Well, duh, don’t!”

But that’s not my point. My point is that I’m planning to operate at scale, and tracking every possible instance of every entity is going to be a bit of an…annoyingly pedantic task…

Just wondering if anyone who uses routing buckets deals with this or has had a solution, or if what you’re saying is correct from a resource management perspective…

They do not, because they are networked. They are able to create networked entities with cheat as same as you can do with your resource. Stuff like peds on the street / cars or non-networked (client sided) entities will be gone and not same as before switching bucket.

Lockdown mode strict means that clients are not able to create entities through client side resource AND also any pedestrians and GTA stuff out of resource. But we are talking just about client side and script created entities. If you created entity on server side or created entity on client side BEFORE setting lockdown, and it’s networked, it’s gonna be inthere after switching buckets from and back.

Well, my answer is maybe unexpected but yes. :smiley:
You should really handle script-created entity by yourself in your resource. Basically, you should NOT rely on automatically deleting those entities in any case in any resource. This is not good solution and you should always have some sort of “garbage collector” in case of any failure.

1 Like

Hmm! That’s interesting - I thought the complete opposite, LOL, I figured it’d be bad to try to track and map eeeevery instance of every single possible entity (planned or otherwise) so that I can safely delete it later.

Automatically deleting all entities within routing bucket n seems like the best way to delete and clean up resources without pulling my hair out, LOL.

Is there at least a way to track all networked-entities?
In THAT case, I can do a poll everytime I need to wipe and reset a routing bucket by doing something like:

RegisterNetEvent("cleanup", function(bucket_name, )
   tableofents = {}
   --Magical Unexisting native below:
   tableofents = GetNetworkedEntities()
   for  i=1,#tableofents do
      curr_ent_rt = GetEntityRoutingBucket(tableofents(i))
      if curr_ent_rt == bucket_name then
         --Delete entity
      end
   end
end)

And so on, and so forth…
Otherwise, I’m REALLY REALLY nervous about tracking entities from players that I can’t control…(cheaters especially)…

I don’t see any problem with that. Just save entity IDs when creating an entity in some mission table and then loop them on the server and call DeleteEntity on them? Nothing why you should pull your hair out, it’s few lines of code.

You can get all the entities, solutions are for example GetGamePool native on client side. But remember, if you are not the entity owner of the networked entity you can’t control it, so you can’t delete it.

Sorry, I was asking - do you know of any natives that track all instances of network instances?

My fear is just that leaving the tracking and management of the network entities to the resource creator is more error prone than having a universal native that took care of this, but if I gotta brain storm ideas for networked ent management, I guess that’s okei!

Anyways, let me know of the above and I’ll solution you (assuming something shocking doesn’t come in within the coming hours…)