positions with actions

Hi all,

I’m trying to make several positions which on enter execute functions.

Like I’m driving up a parking spot, my vehicle got parked.

For now I’m doing this with a timer which checks every second. However this is much load for the server.
Isn’t there a better way to do this?

You could use one of the PHX round disc-like props as a parking pad. I used one for inside the car-dealer I made, didn’t look great in the menu, but in the world its fine. OnTouch , if it is a vehicle then park… Or if spawned, allow them to drive off. If car left for 30 seconds, despawn it.

I wouldn’t recommend checking all entities and getting vehicles; if you do anything like that, keep a record of the vehicles that are spawned and only check for those. You really don’t need to check super frequently and you could use a simple Distance check instead of ents.FindInXXXXX as those are expensive.

You should try benchmarking your code; calculate how much time it takes to execute, and also calculate how much time it takes to execute 100, 1,000, 10,000, 100,000 etc iterations of it. Make improvements :slight_smile:

So, I have to create an entity with those properties to make it work?

No; you could do location checks without using ents.FindInXXX; you can use Distance checks, you could compare x,y,z Vector elements, etc… There are many different ways to solve this “problem”, an Entity would be slightly quicker because you have a Touch function whereas the others you’d have to monitor with timers or think or tick or whatever.

SO there is no specific hook to increase the speed and decrease the memory usage?

It all depends on how things are implemented. Example: My old lighting system used ents.FindInCone to see which cars the player was looking at, in addition to going behind the player for splash lighting ( DynamicLight ). When I switched from that to looping through just the spawned cars ( managed list ), it gave me a 100% increase in fps ( ents.FindInCone reduced my fps by half ).