Justice, the awesome NPC system

This is very useful I have tried it out on one of my test projects. Keep up the good work!

I just keep it in the ServerStorage and havenā€™t had an issue since.

Can you please send the file as a .rbxl instead of an .rbmx please?

How would i throw in a way for NPC to ignore regions, an example being this


Red is where they can walk to, yellow is parts id rather them not pathfind in, since it is a road, crossing areas are fine of course.

1 Like

Thatā€™s actually a really great question, I need an answer to this too. Thx for bringing it up!

Howā€™d you comfortably handle 200 and 500 NPCā€™s at once with so much pathfinding going on? What method did you use to optimize like that

Hi, I plan to use the justice system for an upcoming game. However i have 4 questions:

  1. How can i make it so that the NPCs spawn at the sidewalks of the city map?

  2. Can i add behaviour which makes the NPCs either run away or approche something? if so, how?

  3. How can i optimize the npc system via LOD?

  4. Do NPCs walk in zones (Parts that arent completely visible or collidable) tagged with pathfindable?

I only know the answer for the 4th question, yes NPCs can detect invisible parts that are tagged with pathfindable.

1 Like

Is there any way to make some npcs attack you when they get close, or is this something we need to implement on our own?

Hi all,

I know itā€™s been a long time since Iā€™ve updated this properly (itā€™s been a year since this resource came out!) and I believe itā€™s time for a rewrite.

Justice will be rewritten from the ground up at some point with a new programming ideology. It will be written in the same drop-in framework style, but with much more extensibility via a plugin-style system or some form of API. Iā€™m not quite sure yet how I want it to work since itā€™s a big undertaking and I have other projects to work on at the minute.

It probably wonā€™t be this month, it might not even be within the next couple months, but it will be rewritten at some point.

See you then.

11 Likes

own implementation would be needed

Anyway to make the ā€œPrepping NPC assetsā€ faster? also remove the ball when he caculating new path?

Looks epic, is there a function so when the player stands on an NPCā€™s way, the NPC waits a bit for the player to walk somewhere else, or if theyā€™re just standing there, walk in the opposite way? (Similar to PokĆ©mon Sun and Moon NPCs in Hauā€™oli City and some other areas)

I gave this a try but for some reason, path:GetWaypoints() is returning an empty table and path.Status is NoPath.

I can get it to work on a new baseplate but not in my game.

Iā€™ll report back when I figure out the source of this problem.

Iā€™ve looked around and found some answers saying it might be an issue with the navigation mesh but it looks fine to me.

I got it to work.

Iā€™m making a tycoon where I serialize each part and then move their position to Vector3.new(math.huge, math.huge, math.huge)

I turned that off and it worked.

Maybe this is affecting the navigation mesh somehow.

Edit: Hiding the parts in ReplicatedStorage instead of moving them really far away fixed this problem. Another way to solve this would be to not use math.huge and a ā€œsmallerā€ number instead like 10,000

What a system, this is very nice!

So this is basically a system where NPCs roam around and walk to random positions, right?

I know where you got the name and the lady in the banner image from lol

Wow! Itā€™s been a long time since Iā€™ve said this, but Iā€™m very proud to presentā€¦

(finally)

By popular demand I have rewritten the script with BRAND NEW FEATURES! (because people still DM me about this and I thought it was finally time to add the big requests.)

  • Total rewrite! There was a lot of jank, but the script has been rewritten into modern Luau and scripting standards. Iā€™ve tried to preserve compatibility but there are some breaking changes, so you should take a look at the default scripts before committing.
  • Updated debugger that only works in Studio, but also has a toggle option in case it gets annoying. It includes an overhead UI that tells you what the NPCs are thinking (yes, they have a brain now implemented as a state machine).
  • There is now a bundled R15 rig. Whilst the script did work fine with R15 before technically, it required some fiddling in making a rig, so now it is part of the download. On top of this, you can now swap between rigs using a configuration option instead of replacing the rig.
  • Like I promised, there are now ways to extend Justice without modifying the main script: cogs! Cogs are simple scripts that return a little bit of data and an executor. Check out the RandomPather cog which is the default (and the standard Justice functionality, now updated)! For now, you can only hook into the pathfinder (which has been a popular demand), but this will be extended as Justice inevitably grows with more features.
  • Player collision group name is now a configuration option, and not a hardcoded value.
  • Deadzones/unpathfindable areas have been added. Add a PathfindingModifier to your parts you wish to deadzone, then set the label to Justice:Deadzone.
  • Certain assets (like accessories) are now prepared by the system itself instead of needing to be done in the assets file.
  • Faces now support morscore style faces (i.e., faces made up of multiple decals).
  • Names are now just picked from a list, like assets, instead of using a name generator function as this was the primary usecase anyway.

THIS REWRITE IS STILL EXPERIMENTAL!! As always, things are bound to change and this has literally been the culmination of about 3 hours of caffeine-induced work, ending at 1AM. This also means documentation might be a bit awkward at times, and may require some source code investigation to work out. Please notify me of any issues and Iā€™ll release builds to update them.

Justice.rbxm (46.8 KB)

Anyway, Iā€™m going to bed. Oyasumi.

14 Likes

Very nice update, and your system is the best one I know! I hope you keep growing this and I love your work so far!

1 Like

Anyone knows how to stop the statemachine when an npc died? I tried to Destroy and Disable brain, but its not possibleā€¦ its like an instance of a module script I think?..