Npc Enemies

Package Name: (Vilva) NPC Enemies
Creator: Vilva#9953
Itch Page: NPC Enemies Package by Vilva for Crayta - $50,000 Build Jam - Theme: "Treasure Hunt" -

NPC Enemies is a package created for the “Treasure Hunt” Build Jam. It’s designed to help you add any type of enemy into your game.


I prepared a showcase game with some examples of what can be done with NPC Enemies. The showcase is remixable, so I advise you to open it in the Editor and take a look how everything is configured.

Showcase link: Crayta


This package can be used in a variety of ways. For a “Treasure Hunt” you could have enemies that guard a treasure or ambush the player. Another idea would be to use it in RPG games to spawn different enemies across the world.

It includes a NPC Enemy template, which will attack any player or NPC they encounter. There are a lot of properties to allow you to configure the NPC to your needs. It supports melee or ranged attacks, and you can also use projectiles for attacks. Projectiles can be dodged by the player and could be used for example in action parkour games.

The package includes 3 ready to use weapon templates for NPCs. A Cutlass for melee attacks, an Assault Rifle for ranged attacks, and a Rocket Launcher as an example of a projectile weapon.

I also included scripts for NPC Health, Inventory, and Patrolling. They have been pre-configured to work seamlessly together.

  • Install the package: (Vilva) NPC Enemies
  • Drag the “NpcEnemy” template into your game
  • The NpcEnemy can only damage players if they have the official “Health” package installed and configured
  • To kill the NpcEnemy you can use other packages, like the official “Axe” or “Gun” packages


NpcEnemyCore is the main script

  • The property tooltips should give you a rough idea how to use each property

In the following I will give you some basic configurations to help you get started

Configuration: Weapons

NPC weapons don’t need the default Crayta scripts for attacking. If you use packaged weapons, you should remove every script except “InventoryItemSpecScript”.

Weapon: Cutlass
  • The Cutlass is the default weapon
  • Melee weapons must set the attackActionName property to “Melee”
  • They should use a low attackRange
Weapon: Assault Rifle
  • Open the NpcEnemyConfig and set heldTemplate to “NpcEnemyWeaponAssaultRifle”
  • Ranged weapons must set the attackActionName property to “Fire”
  • They should use a high attackRange and a low attackCooldown
Weapon: Rocket Launcher
  • Open the NpcEnemyConfig and set heldTemplate to “NpcEnemyWeaponRocketLauncher”
  • Ranged weapons must set the attackActionName property to “Fire”
  • The Rocket Launcher should use a high attackRange and a very high attackCooldown
  • Install the official Crayta “Rocket Launcher” package to get the “Rocket” projectile template
  • Check the useAttackProjectile property and select “Rocket” for the projectile template

Configuration: VisionTrigger
  • Every NPC Enemy needs to reference a VisionTrigger
  • Triggers should be set to “Players Only”, since that also works for NPCs
  • Multiple NPCs can share one VisionTrigger
  • You can either place a VisionTrigger in the world, or set it as child of an NPC to move it with the NPC
Configuration: ChaseAreaTrigger
  • Setting this parameter is optional
  • The NPC will start retreating once it exits the trigger. If you leave the parameter empty, the NPC will only retreat after killing every target
  • This should be a big trigger, for example a room the NPC is guarding
  • The NPC has to start inside the trigger
  • If the NPC is patrolling, the trigger has to cover the whole patrolling area
  • ChaseAreaTrigger can not be a child of the NPC
Configuration: Patrolling
  • NPCs can patrol randomly or between waypoints (Path)
  • Enable the property isPatrolling
  • For the Path option you need to reference at least one locator entity as pathNode
  • PathNodes can have the “NpcEnemyPathNodeScript” attached to perform additional actions, like stopping and playing emotes. Configuration is similar to Russ “NPC System”, detailed guide here: NPC System
Configuration: Loot Drops
  • Includes a modified version of the “Loot Tables” package by Cereal, detailed guide here: Loot Tables
  • Loot is configured on the LootCrate template
  • I added some code to the LootCrate to roll multiple item drops when you open the crate (default: 3 rolls)

If you want to have different Loot Drops for different kinds of NPCs you can configure that without scripting

  • Duplicate the loot crate template and make a new template (e.g. “LootCrateBoss”)
  • Adjust the loot drops in there and link the new template in the LootCrate property of your Boss NPC


Below is some information for advanced users. But my advice is to try out the package first

Info: Targeting and Chasing
  • NPC Enemies will only target someone if they enter the VisionTrigger, or if they damage the NPC
  • They do not constantly search for targets because that would have a big impact on performance
  • If the NPC has a target, it will start chasing the target
  • When the NPC is close enough to the target, it will execute an attack
  • NPCs will prioritize the closest target
  • The NPC will stop chasing if you defined a “chaseAreaTrigger”, and if the NPC itself moved out of that trigger. It will also stop chasing if every target died
  • After chasing, the NPC will return to the previous position
Info: Team system
  • NPCs will ignore players or NPCs if they have the same team id
  • If you want to assign a player or NPC to a team add a script to the template root and use a script property named “team”
  • If the player doesn’t have a team property, the user is checked instead
  • If the team property is not set, it will default to “0”
Info: Cosmetic Meshes & Custom Costumes
  • This package supports adding Cosmetic Meshes to NPCs (optional)
  • You can use them by adding locators or meshes below the CosmeticMeshes locator
  • Use the “NpcEnemyAttachToSocketScript” to attach meshes to the correct character sockets. If the package comes with a different “attachToSocketScript” you might be able to use that script by replacing its content with the one that comes with NPC Enemies
  • See the Showcase Game Skeletons as an example of how to configure it
  • You can also use packages like “NPC Robots Pack” by LittleCreator. Ideally these packages should already specify the correct sockets, so you can just copy + paste the sockets under Cosmetic Meshes
Info: Script Hooks

NpcEnemyCore sends the following Events. You can use them to add extra functionality

  • OnStateChanged(npcEntity, previousState, newState)
  • OnVisibilityChanged(npcEntity, isVisible)
  • OnTargetChanged(npcEntity, previousTarget, newTarget)
  • OnNpcAttack(npcEntity, targetEntity) - This is used by “NpcEnemyWeaponAssaultRifleManager” to play a muzzleFlashEffect
  • OnNpcDied(npcEntity, killerEntity)

The following script calls are also send

  • projectile:InitProjectile(rayStart, rayDirection, projectileExitVelocity, weaponEntity, npcEntity) - This is used by the Rocket Launcher “ProjectileScript” to init the projectile
  • user:SendChallengeEvent("killed-npc")
  • user:SendXPEvent("killed-npc-xp")


Special thanks to the original authors.

Included Packages (Dependencies)

  • Crayta Inventory package
  • “NUI - Entity Health Bar” by Nomaki

Modified Scripts
This package includes scripts from other packages that have been modified to work seamlessly together.

  • NpcEnemyInventoryViewScript, NpcEnemyPatrollingScript, NpcEnemyPathNodeScript - modified versions of scripts from “NPC System” by Russ
  • NpcEnemyHealthScript - merged from “NPC System” by Russ and “NUI - Entity Health Bar” by Nomaki
  • NpcEnemyAttachToSocketScript - modified version of attachToSocketScript from “Skeleton Outfits Npc” by Tumbak7
  • Some loot scripts from “Loot Tables” by Cereal

Packages used in Showcase

  • “NPC_Robots_Pack_LC” by LittleCreator
  • “Skeleton Outfits Npc” by Tumbak7
  • “NUI - XP and Levelling” by Nomaki
  • “Damage Vignette” by Cereal
  • “Show Trigger” by Plasma
  • “Tutorial Modded” by Sinjin

If you have any questions or feedback, reach out to me (Vilva#5980) in the Crayta Discord :slight_smile:



I’ve been waiting for this package for so long :smiley:

1 Like