[FREE] NPC Control | Optimize NPC Control Script

NPC Control | Optimize NPC Control Script

Hello, I’m Emir. While creating my own FiveM package, I came across an NPC control script. However, this script had extremely high resmon values (ranging from 0.07 to 0.15), which negatively impacted server performance. When I examined the code, I noticed that some parts were performing unnecessary operations and could be optimized. Additionally, after searching online, I couldn’t find a properly optimized and well-functioning NPC control script.

For this reason, I restructured the script from scratch to achieve the best possible optimization. With the improvements I made, I managed to reduce the resmon values to 0.00-0.02. Besides optimization, I also made several enhancements and additions to ensure the script runs more stable and efficiently.

** :pushpin: Features and Improvements:**

  • FPS-based optimization → Dynamically adjusts vehicle and pedestrian density based on players’ FPS.
  • Invisible vehicle and NPC cleanup → NPCs and vehicles that have been off-screen for too long are automatically removed.
  • Maximum spawn limits → Prevents NPCs and vehicles from spawning beyond the specified limit.
  • Traffic congestion prevention → Stops vehicles from accumulating in specific areas, ensuring smoother traffic flow.
  • Smooth deletion effect → Vehicles and pedestrians do not disappear suddenly; instead, they are gradually removed from the scene in a realistic manner.
  • Low resmon usage → The script minimizes unnecessary loops and processes, keeping resmon values as low as possible.
  • Player vehicle protection → The cleanup process does not affect players’ own vehicles.
  • Smarter spawn distances → NPCs and vehicles are spawned at optimal distances based on players’ field of view, reducing unnecessary processing load.
  • Traffic Spawn Control → You can control the spawn of the vehicles you want.
  • Player Steady State Features → Player is considered to be stationary if they move under 5 units Intensity is reduced by 50% while in steady state Steady state check every 2 seconds More aggressive clearing while in steady state
  • Smart Spawn System → 30% chance to spawn when stationary 70% chance to spawn when moving Distance based spawn control FPS based spawn optimisation.
  • And many more features…

Let me know if you have any feedback or suggestions!

Code is accessible Yes
Subscription-based No
Lines (approximately) 200+
Requirements none
Support No

Download

github

Discord

Ekran görüntüsü 2025-03-15 090948

10 Likes

i will definy try it but can you maybe transate the text after the – to English? Does this also control aggresive peds?

1 Like

Will this also take care of police and ambulances spawning ?

1 Like

Nice job bro, “Eline Sağlık” (a Turkish saying meaning well done or cooked)

1 Like

I explained what the generic code does on Github, you can see it in the readme section. Sorry, I added a description in my own language, I will fix it as soon as possible.

2 Likes

DisableCops and DisableDispatch disable police and emergency units. You can organise them according to your wishes.

1 Like

Thank you, bro. ‘Eyvallah’ :heart:

2 Likes

Any idea what would cause the same car and ped to spawn over and over and no other ped

I just brought a new update. Can you update and try again

I am also having an issue now where other peoples cars are not visable. Pretty sure the script is deleting them locally for the person not seeing them.

2 Likes