Skip to content

K.NPC ​

Functions ​

K.NPC.Brain ​

lua
K.NPC.Brain(definition: { [string]: any }): Brain

Builds a brain: a set of states, each with optional Enter, Update and Exit. Update runs a few times per second; return a state name from it to switch. Always (optional) runs before every Update and can also return a state.

K.NPC.Spawn ​

lua
K.NPC.Spawn(template: Model, at: any, options: { [string]: any }?): NPC

Clones template (a Model with a Humanoid, e.g. in ServerStorage) at at and makes it an NPC.

K.NPC.Control ​

lua
K.NPC.Control(model: Model, options: { [string]: any }?): NPC

Makes a Model already in the game (placed in Studio) an NPC.

K.NPC.Get ​

lua
K.NPC.Get(model: Instance): NPC?

The NPC for a model, or nil.

K.NPC.All ​

lua
K.NPC.All(): { NPC }

Every living NPC.

K.NPC.Spawner ​

lua
K.NPC.Spawner(template: Model, options: { [string]: any }): Spawner

Keeps up to Max NPCs alive, spawning a replacement every Every seconds while below Max. Takes every K.NPC.Spawn option too (Brain, Reward, Stats...).

K.NPC.Behaviors ​

lua
K.NPC.Behaviors.Hostile(options: { [string]: any }?): Brain

Wanders near home, chases players it sees, attacks them, then walks back home. Options: Attack ("Punch"), SightRange (40), AttackRange (5), LoseRange (SightRange × 1.5), Wander (12 studs, 0 to stand still), NeedsSight (true).

K.NPC.Behaviors ​

lua
K.NPC.Behaviors.Wander(options: { [string]: any }?): Brain

Strolls around home, pausing between walks. Options: Radius (15), Pause (3 seconds).

K.NPC.Behaviors ​

lua
K.NPC.Behaviors.Patrol(options: { [string]: any }): Brain

Walks between points in order, forever. Options: Points (parts, models or Vector3s), Pause (1 second).

Events ​

K.NPC.Died ​

Fires with (npc, killer?) when any NPC dies.

K.NPC.Spawned ​

Fires with (npc) for every new NPC, before its brain starts: adjust it from any script.

Methods on npc ​

npc:MoveTo ​

lua
npc:MoveTo(target: any)

Walks to a Vector3, part, model or player, using pathfinding when needed. Calling it again with a nearby goal (like a moving player) is cheap.

npc:Stop ​

lua
npc:Stop()

npc:Wander ​

lua
npc:Wander(radius: number?)

Walks to a random spot within radius studs of Home (if not already walking).

npc:Face ​

lua
npc:Face(target: any)

Turns to look at a position, part, model or player (only around the vertical axis).

npc:Attack ​

lua
npc:Attack(name: string, target: any?): { Instance }

Uses a K.Combat attack, facing target first if given. Returns the targets hit.

npc:NearestPlayer ​

lua
npc:NearestPlayer(range: number, needsSight: boolean?): (Player?, number?)

The closest living, loaded player within range studs (and in sight, if needsSight). Returns the player and their distance, or nil.

npc:CanSee ​

lua
npc:CanSee(target: any): boolean

True if nothing (other than characters) blocks the NPC's view of target.

npc:DistanceTo ​

lua
npc:DistanceTo(target: any): number

Studs to target, or math.huge if it has no position.

npc:SetState ​

lua
npc:SetState(name: string)

npc:StateTime ​

lua
npc:StateTime(): number

Seconds since the NPC entered its current state.

npc:OnDeath ​

lua
npc:OnDeath(callback: (any, Instance?) -> ())

Runs callback(npc, killer?) when this NPC dies.

npc:Destroy ​

lua
npc:Destroy()

Generated from src/Corode/NPC.luau.

Corode 0.13.0 · MIT License