Creating a Smart NPC
Last updated
Last updated
To create a smart NPC, use the AIAgentManager's CreateAgent method. This method initializes an AI agent and binds it to an NPC model, enabling it to act based on AI decisions.
GetGameState():
A function that returns the current game state as a table when called. This is passed to the AI for contextual decision-making.
NPC Model:
The NPC model instance in the game. It must contain a Humanoid, HumanoidRootPart, and a valid PrimaryPart.
PersonalityId:
A string representing the selected personality profile for the AI agent (e.g., "clown", "fortune-teller", etc.).
ExecutableCommands:
A table that lists the commands the agent is allowed to execute. Each command can optionally include context or conditions under which it should be used. This will be sent to the AI server so the AI can determine appropriate actions.
:
An array of behavior modules to assign to the NPC. Each module defines recurring logic such as patrols, scanning, or idle checks.
Frequency:
A number that determines how often the continuous behavior scripts should be executed.
Sample Usage:
local replicatedStorage = game:GetService("ReplicatedStorage")
local aiAgentManager = require(replicatedStorage.AIAgentModule.AIAgentManager)
local customBehaviorScript = require(replicatedStorage.CustomScript)
local clownSmartNpc = aiAgentManager:CreateAgent(
gameState, -- Function that returns the game state
workspace.NPCs:WaitForChild("Clown"), -- NPC Model
"clown", -- Personality ID
{ "MoveTo", "FollowTarget" }, -- Executable commands
{ customBehaviorScript }, -- Behavior scripts
100 -- Behavior execution frequency
)