Iterating 2 pools of entities doesn't work! Help!

Hello,

Is it possible to use 2 pools and iterate them at the same time (on the same or different Tick)? This is what I m doing:

PedsPool peds = new PedsPool();
VehiclesPool vehicles = new VehiclesPool();

foreach (Ped ped in peds)
{
       ... Code here...
}

foreach (Vehicle vehicle in vehicles)
{
       ... Code here...
}

But it doesn’t work! Does anyone can explain me why?

Thanks

Why would you want to do this? What are you trying to achieve?

Also, post in #development next time for this sort of question :wink:

Oh Sorry. I will… :face_with_hand_over_mouth:
What I am trying to do is to make the world apocalyptic. This means change peds behavior and appearance but also cars (wreck cars). For peds the job is done, but when I create the pool for the cars nothing seems working, even the peds back to normal.

I think that this question should be on “Technical Support” thread as I am wandering if that is not a limitation from Fivem. :thinking: Only them can answer I guess

i can’t believe that simple code isn’t working.

first tell me ,that code is client side right ?

second thing have you put this code in a async function ?

third things i dunno these class you are using PedsPool and VehiclesPool and i don’t know what you trying to do in this loop so it’s pretty hard to tell you what’s wrong. so try to bring a bit more information.

The code is client side. And yes, they are each of them in a async functions, basically:
public async Task OnTick()
I have tried execute both on the same time, none works.
But after some test, with 2 pools Peds and Objects, it works. So the problem is with the Vehicles pool, not a hard-coded limitation.
What I am trying to do is to catch all vehicles in an array and transform some on wreck cars, explode some etc… an apocalypse world.

first advice it certainly won’t change the problem but it will be a bit better in your case, to make async function for each pool , not let them in the async Task OnTick.

It’s about optimization, each pool will have different amount of object and different action on them, so you don’t want your code to wait each pool to finish for acting on the next , or you don’t want your different pool slowing to much the script.

so i would advice you to make 3 async function , you trigger them by the OnTick of course.

about your problem, first thing to check is size of the poolVehicle , is it fill with vehicles, are the vehicles inside not null and exist ?

second things to check is the action you make on the vehicle and for that i can’t help you wihout the code , be sure the code is executed , ( use Debug.WriteLine(“my debug text”); in your code for check in the consol if it executed or not )

Thanks I m gonna follow your advice and try…

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