Table of Contents

Class Npc

Namespace
SampSharp.Entities.SAMP
Assembly
SampSharp.OpenMp.Entities.dll

ECS-side wrapper around an open.mp INPC (a server-controlled bot built on top of an IPlayer).

public class Npc : IdProvider
Inheritance
Npc
Inherited Members

Remarks

Unlike WorldEntity-based components, Npc does NOT derive from IEntity — open.mp's INPC only implements IIDProvider, and its position/rotation setters take an extra "immediate update" boolean. Position / Rotation / VirtualWorld are exposed directly here.

Constructors

Npc(INPCComponent, INPC)

Initializes a new instance of the Npc class.

protected Npc(INPCComponent npcs, INPC npc)

Parameters

npcs INPCComponent
npc INPC

Properties

Ammo

Gets or sets the ammunition for the current weapon.

public virtual int Ammo { get; set; }

Property Value

int

AmmoInClip

Gets or sets the ammo count in the current weapon's clip.

public virtual int AmmoInClip { get; set; }

Property Value

int

Armour

Gets or sets the armor of this NPC.

public virtual float Armour { get; set; }

Property Value

float

CurrentPathId

Gets the ID of the path this NPC is currently following, or -1 if none.

public virtual int CurrentPathId { get; }

Property Value

int

CurrentPathPointIndex

Gets the index of the current waypoint within the active path.

public virtual int CurrentPathPointIndex { get; }

Property Value

int

EnteringVehicle

Gets the vehicle the NPC is in the process of entering, or a handle with no value if not entering one.

public virtual IVehicle EnteringVehicle { get; }

Property Value

IVehicle

EnteringVehicleSeat

Gets the seat index the NPC is targeting while entering a vehicle.

public virtual int EnteringVehicleSeat { get; }

Property Value

int

FightingStyle

Gets or sets the NPC's fighting style.

public virtual PlayerFightingStyle FightingStyle { get; set; }

Property Value

PlayerFightingStyle

Health

Gets or sets the health of this NPC.

public virtual float Health { get; set; }

Property Value

float

Interior

Gets or sets the interior ID this NPC is in (server-side only).

public virtual int Interior { get; set; }

Property Value

int

IsAiming

Gets a value indicating whether this NPC is currently aiming.

public virtual bool IsAiming { get; }

Property Value

bool

IsDead

Gets a value indicating whether this NPC has been killed and not yet respawned.

public virtual bool IsDead { get; }

Property Value

bool

IsInfiniteAmmoEnabled

Gets a value indicating whether infinite ammo is enabled for this NPC.

public virtual bool IsInfiniteAmmoEnabled { get; }

Property Value

bool

IsInvulnerable

Gets or sets a value indicating whether this NPC is invulnerable.

public virtual bool IsInvulnerable { get; set; }

Property Value

bool

IsMeleeAttacking

Gets a value indicating whether this NPC is currently performing a melee attack.

public virtual bool IsMeleeAttacking { get; }

Property Value

bool

IsMoving

Gets a value indicating whether this NPC is currently executing any movement command.

public virtual bool IsMoving { get; }

Property Value

bool

IsMovingByPath

Gets a value indicating whether this NPC is currently moving along a path.

public virtual bool IsMovingByPath { get; }

Property Value

bool

IsOmpEntityDestroyed

Gets a value indicating whether the open.mp entity counterpart has been destroyed.

protected bool IsOmpEntityDestroyed { get; }

Property Value

bool

IsPathPaused

Gets a value indicating whether path-based movement is currently paused.

public virtual bool IsPathPaused { get; }

Property Value

bool

IsPlaybackPaused

Gets a value indicating whether playback is currently paused.

public virtual bool IsPlaybackPaused { get; }

Property Value

bool

IsPlayingNode

Gets a value indicating whether this NPC is currently following a node path.

public virtual bool IsPlayingNode { get; }

Property Value

bool

IsPlayingNodePaused

Gets a value indicating whether node-based movement is currently paused.

public virtual bool IsPlayingNodePaused { get; }

Property Value

bool

IsPlayingPlayback

Gets a value indicating whether this NPC is currently playing a recording.

public virtual bool IsPlayingPlayback { get; }

Property Value

bool

IsReloadEnabled

Gets a value indicating whether weapon reloading is enabled for this NPC.

public virtual bool IsReloadEnabled { get; }

Property Value

bool

IsReloading

Gets a value indicating whether this NPC is currently reloading.

public virtual bool IsReloading { get; }

Property Value

bool

IsShooting

Gets a value indicating whether this NPC is currently shooting.

public virtual bool IsShooting { get; }

Property Value

bool

IsVehicleSirenUsed

Gets or sets a value indicating whether the siren on this NPC's vehicle is active.

public virtual bool IsVehicleSirenUsed { get; set; }

Property Value

bool

Player

Gets the underlying IPlayer handle that this NPC drives.

public virtual IPlayer Player { get; }

Property Value

IPlayer

PlayerAimingAt

Gets the player this NPC is currently aiming at, or a handle with no value if not aiming at any player.

public virtual IPlayer PlayerAimingAt { get; }

Property Value

IPlayer

PlayerMovingTo

Gets the player this NPC is currently moving towards, or a handle with no value if not following a player.

public virtual IPlayer PlayerMovingTo { get; }

Property Value

IPlayer

Position

Gets or sets the NPC's position in the world as a Vector3. Use SetPosition(Vector3, bool) for the immediate-update overload.

public virtual Vector3 Position { get; set; }

Property Value

Vector3

PositionMovingTo

Gets the world position this NPC is currently moving to.

public virtual Vector3 PositionMovingTo { get; }

Property Value

Vector3

Rotation

Gets or sets the NPC's rotation as a quaternion.

public virtual Quaternion Rotation { get; set; }

Property Value

Quaternion

Skin

Sets the NPC's skin model ID.

public virtual int Skin { set; }

Property Value

int

SpecialAction

Gets or sets the NPC's special action.

public virtual PlayerSpecialAction SpecialAction { get; set; }

Property Value

PlayerSpecialAction

SurfingData

Gets or sets the surfing data for this NPC.

public virtual PlayerSurfingData SurfingData { get; set; }

Property Value

PlayerSurfingData

Vehicle

Gets the vehicle this NPC is currently in, or a handle with no value if not in a vehicle.

public virtual IVehicle Vehicle { get; }

Property Value

IVehicle

VehicleGearState

Gets or sets the gear state for this NPC's vehicle.

public virtual int VehicleGearState { get; set; }

Property Value

int

VehicleHealth

Gets or sets the health of this NPC's current vehicle.

public virtual float VehicleHealth { get; set; }

Property Value

float

VehicleHydraThrusters

Gets or sets the hydra thruster direction for this NPC's vehicle.

public virtual int VehicleHydraThrusters { get; set; }

Property Value

int

VehicleSeat

Gets the seat index this NPC occupies in the current vehicle.

public virtual int VehicleSeat { get; }

Property Value

int

VehicleTrainSpeed

Gets or sets the train speed for this NPC's vehicle.

public virtual float VehicleTrainSpeed { get; set; }

Property Value

float

Velocity

Gets the velocity of this NPC as a Vector3.

public virtual Vector3 Velocity { get; }

Property Value

Vector3

VirtualWorld

Gets or sets the virtual world this NPC is in.

public virtual int VirtualWorld { get; set; }

Property Value

int

Weapon

Gets or sets the current weapon ID.

public virtual byte Weapon { get; set; }

Property Value

byte

WeaponState

Gets or sets the NPC's current weapon state.

public virtual PlayerWeaponState WeaponState { get; set; }

Property Value

PlayerWeaponState

Methods

AimAt(Vector3, bool, int, bool, Vector3, EntityCheckType)

Instructs this NPC to aim at a world position.

public virtual void AimAt(Vector3 point, bool shoot, int shootDelay, bool setAngle, Vector3 offsetFrom, EntityCheckType betweenCheckFlags)

Parameters

point Vector3
shoot bool
shootDelay int
setAngle bool
offsetFrom Vector3
betweenCheckFlags EntityCheckType

AimAtPlayer(Player, bool, int, bool, Vector3, Vector3, EntityCheckType)

Instructs this NPC to aim at a specific player.

public virtual void AimAtPlayer(Player player, bool shoot, int shootDelay, bool setAngle, Vector3 offset, Vector3 offsetFrom, EntityCheckType betweenCheckFlags)

Parameters

player Player
shoot bool
shootDelay int
setAngle bool
offset Vector3
offsetFrom Vector3
betweenCheckFlags EntityCheckType

ApplyAnimation(string, string, float, bool, bool, bool, bool, TimeSpan)

Applies an animation to this NPC.

public virtual void ApplyAnimation(string library, string name, float fDelta, bool loop, bool lockX, bool lockY, bool freeze, TimeSpan time)

Parameters

library string

The animation library.

name string

The animation name.

fDelta float

The speed to play the animation.

loop bool

A value indicating whether the animation should loop.

lockX bool

A value indicating whether to lock the NPC's x-coordinate during the animation.

lockY bool

A value indicating whether to lock the NPC's y-coordinate during the animation.

freeze bool

A value indicating whether to freeze the NPC at the end of the animation.

time TimeSpan

The duration for which to play the animation.

ChangeNode(int, ushort)

Changes the active node and seeks to a specific target point.

public virtual ushort ChangeNode(int nodeId, ushort targetPointId)

Parameters

nodeId int
targetPointId ushort

Returns

ushort

ClearAnimations()

Clears all animations applied to this NPC.

public virtual void ClearAnimations()

EnableInfiniteAmmo(bool)

Enables or disables infinite ammo for this NPC.

public virtual void EnableInfiniteAmmo(bool enable)

Parameters

enable bool

EnableReloading(bool)

Enables or disables weapon reloading for this NPC.

public virtual void EnableReloading(bool toggle)

Parameters

toggle bool

EnterVehicle(IVehicle, byte, NPCMoveType)

Instructs this NPC to enter a vehicle.

public virtual void EnterVehicle(IVehicle vehicle, byte seatId, NPCMoveType moveType)

Parameters

vehicle IVehicle
seatId byte
moveType NPCMoveType

ExitVehicle()

Instructs this NPC to exit the current vehicle.

public virtual void ExitVehicle()

GetAnimation(out int, out float, out bool, out bool, out bool, out bool, out int)

Gets the current foot-sync animation parameters for this NPC.

public virtual void GetAnimation(out int animationId, out float delta, out bool loop, out bool lockX, out bool lockY, out bool freeze, out int time)

Parameters

animationId int
delta float
loop bool
lockX bool
lockY bool
freeze bool
time int

GetKeys(out ushort, out ushort, out ushort)

Gets the NPC's current movement keys.

public virtual void GetKeys(out ushort upAndDown, out ushort leftAndRight, out ushort keys)

Parameters

upAndDown ushort
leftAndRight ushort
keys ushort

GetWeaponAccuracy(byte)

Gets the accuracy of this NPC for the specified weapon.

public virtual float GetWeaponAccuracy(byte weapon)

Parameters

weapon byte

Returns

float

GetWeaponActualClipSize(byte)

Gets the actual clip size accounting for skill level and infinite ammo.

public virtual int GetWeaponActualClipSize(byte weapon)

Parameters

weapon byte

Returns

int

GetWeaponActualReloadTime(byte)

Gets the actual reload time accounting for skill level and dual wield.

public virtual int GetWeaponActualReloadTime(byte weapon)

Parameters

weapon byte

Returns

int

GetWeaponClipSize(byte)

Gets the clip size for the specified weapon.

public virtual int GetWeaponClipSize(byte weapon)

Parameters

weapon byte

Returns

int

GetWeaponReloadTime(byte)

Gets the reload time (in milliseconds) for the specified weapon.

public virtual int GetWeaponReloadTime(byte weapon)

Parameters

weapon byte

Returns

int

GetWeaponShootTime(byte)

Gets the shoot time (in milliseconds) for the specified weapon.

public virtual int GetWeaponShootTime(byte weapon)

Parameters

weapon byte

Returns

int

GetWeaponSkillLevel(PlayerWeaponSkill)

Gets the weapon skill level for the specified weapon skill.

public virtual int GetWeaponSkillLevel(PlayerWeaponSkill weaponSkill)

Parameters

weaponSkill PlayerWeaponSkill

Returns

int

IsAimingAtPlayer(Player)

Gets a value indicating whether this NPC is currently aiming at the specified player.

public virtual bool IsAimingAtPlayer(Player player)

Parameters

player Player

Returns

bool

IsMovingToPlayer(Player)

Gets a value indicating whether this NPC is currently moving towards the specified player.

public virtual bool IsMovingToPlayer(Player player)

Parameters

player Player

Returns

bool

IsStreamedIn(Player)

Determines whether this NPC is streamed in for the specified player.

public virtual bool IsStreamedIn(Player player)

Parameters

player Player

The player to check.

Returns

bool

true if this NPC is streamed in for the player; false otherwise.

Kill(Player?, byte)

Simulates this NPC's death.

public virtual void Kill(Player? killer, byte weapon)

Parameters

killer Player

The player who killed the NPC, or null for no killer.

weapon byte

The weapon used to kill the NPC.

MeleeAttack(int, bool)

Starts a melee attack for the specified duration.

public virtual void MeleeAttack(int time, bool secondaryMeleeAttack = false)

Parameters

time int

Duration of the attack in milliseconds.

secondaryMeleeAttack bool

If true, performs the secondary melee attack.

MoveByPath(int, NPCMoveType, float, bool)

Instructs this NPC to move along a previously created path.

public virtual bool MoveByPath(int pathId, NPCMoveType moveType = NPCMoveType.Auto, float moveSpeed = -1, bool reverse = false)

Parameters

pathId int
moveType NPCMoveType
moveSpeed float
reverse bool

Returns

bool

MoveTo(Vector3, NPCMoveType, float, float)

Instructs this NPC to move to the specified position.

public virtual bool MoveTo(Vector3 position, NPCMoveType moveType, float moveSpeed = -1, float stopRange = 1)

Parameters

position Vector3

The position to move to.

moveType NPCMoveType

The movement type (walk, jog, sprint, or drive).

moveSpeed float

The speed to move at (-1 for default speed).

stopRange float

The distance within which the NPC stops moving.

Returns

bool

true if the movement command was successful; false otherwise.

MoveToPlayer(Player, NPCMoveType, float, float, TimeSpan, bool)

Instructs this NPC to continuously follow player.

public virtual bool MoveToPlayer(Player player, NPCMoveType moveType, float moveSpeed = -1, float stopRange = 0.2, TimeSpan posCheckUpdateDelay = default, bool autoRestart = false)

Parameters

player Player

The player to follow.

moveType NPCMoveType

The movement type.

moveSpeed float

The speed to move at (-1 for default speed).

stopRange float

The distance within which the NPC stops following.

posCheckUpdateDelay TimeSpan

How often the NPC recalculates the target's position.

autoRestart bool

If true, the NPC restarts following after reaching the player.

Returns

bool

true if the command was successful; otherwise false.

OnDestroyComponent()

This method is invoked before this component is destroyed and removed from its entity.

protected override void OnDestroyComponent()

PausePath()

Pauses path-based movement temporarily.

public virtual void PausePath()

PausePlayback(bool)

Pauses or resumes the current playback.

public virtual void PausePlayback(bool paused = true)

Parameters

paused bool

PausePlayingNode()

Pauses node-based movement.

public virtual void PausePlayingNode()

PlayNode(int, NPCMoveType, float, float, bool)

Starts node-based movement for this NPC.

public virtual bool PlayNode(int nodeId, NPCMoveType moveType = NPCMoveType.Auto, float moveSpeed = -1, float radius = 0, bool setAngle = true)

Parameters

nodeId int
moveType NPCMoveType
moveSpeed float
radius float
setAngle bool

Returns

bool

PutInVehicle(IVehicle, byte)

Teleports this NPC directly into a vehicle seat.

public virtual bool PutInVehicle(IVehicle vehicle, byte seat)

Parameters

vehicle IVehicle
seat byte

Returns

bool

RemoveFromVehicle()

Removes this NPC from its current vehicle.

public virtual bool RemoveFromVehicle()

Returns

bool

ResetAnimation()

Resets the foot-sync animation for this NPC.

public virtual void ResetAnimation()

ResetSurfingData()

Resets the surfing data for this NPC.

public virtual void ResetSurfingData()

Respawn()

Respawns this NPC, keeping its current state.

public virtual void Respawn()

ResumePath()

Resumes previously paused path-based movement.

public virtual void ResumePath()

ResumePlayingNode()

Resumes previously paused node-based movement.

public virtual void ResumePlayingNode()

SetAnimation(int, float, bool, bool, bool, bool, int)

Sets the foot-sync animation parameters for this NPC.

public virtual void SetAnimation(int animationId, float delta, bool loop, bool lockX, bool lockY, bool freeze, int time)

Parameters

animationId int
delta float
loop bool
lockX bool
lockY bool
freeze bool
time int

SetKeys(ushort, ushort, ushort)

Sets the NPC's movement keys.

public virtual void SetKeys(ushort upAndDown, ushort leftAndRight, ushort keys)

Parameters

upAndDown ushort
leftAndRight ushort
keys ushort

SetPosition(Vector3, bool)

Sets the position of this NPC.

public virtual void SetPosition(Vector3 position, bool immediateUpdate)

Parameters

position Vector3

The Vector3 position to set.

immediateUpdate bool

A value indicating whether to broadcast a sync to streamed-in players immediately instead of waiting for the next tick.

SetRotation(Quaternion, bool)

Sets the rotation of this NPC. See SetPosition(Vector3, bool) for the immediate-update flag.

public virtual void SetRotation(Quaternion rotation, bool immediateUpdate)

Parameters

rotation Quaternion

The rotation to set.

immediateUpdate bool

A value indicating whether to broadcast a sync to streamed-in players immediately instead of waiting for the next tick.

SetVelocity(Vector3, bool)

Sets the velocity of this NPC.

public virtual void SetVelocity(Vector3 velocity, bool update = false)

Parameters

velocity Vector3

The velocity to set.

update bool

A value indicating whether to update immediately.

SetWeaponAccuracy(byte, float)

Sets the accuracy of this NPC for the specified weapon.

public virtual void SetWeaponAccuracy(byte weapon, float accuracy)

Parameters

weapon byte
accuracy float

SetWeaponClipSize(byte, int)

Sets the clip size for the specified weapon.

public virtual void SetWeaponClipSize(byte weapon, int size)

Parameters

weapon byte
size int

SetWeaponReloadTime(byte, int)

Sets the reload time (in milliseconds) for the specified weapon.

public virtual void SetWeaponReloadTime(byte weapon, int time)

Parameters

weapon byte
time int

SetWeaponShootTime(byte, int)

Sets the shoot time (in milliseconds) for the specified weapon.

public virtual void SetWeaponShootTime(byte weapon, int time)

Parameters

weapon byte
time int

SetWeaponSkillLevel(PlayerWeaponSkill, int)

Sets the weapon skill level for the specified weapon skill.

public virtual void SetWeaponSkillLevel(PlayerWeaponSkill weaponSkill, int level)

Parameters

weaponSkill PlayerWeaponSkill
level int

Shoot(int, PlayerBulletHitType, byte, Vector3, Vector3, bool, EntityCheckType)

Triggers a weapon shot from this NPC.

public virtual void Shoot(int hitId, PlayerBulletHitType hitType, byte weapon, Vector3 endPoint, Vector3 offset, bool isHit, EntityCheckType betweenCheckFlags)

Parameters

hitId int
hitType PlayerBulletHitType
weapon byte
endPoint Vector3
offset Vector3
isHit bool
betweenCheckFlags EntityCheckType

Spawn()

Spawns this NPC at its currently configured position and rotation.

public virtual void Spawn()

StartPlayback(int, bool, Vector3, Quaternion)

Starts playing a pre-loaded recording by its record ID.

public virtual bool StartPlayback(int recordId, bool autoUnload = true, Vector3 point = default, Quaternion rotation = default)

Parameters

recordId int

The record ID returned by LoadRecord(string).

autoUnload bool

If true, the record is unloaded when playback ends.

point Vector3

The starting position for playback (zero vector for current position).

rotation Quaternion

The starting rotation for playback.

Returns

bool

StartPlayback(string, bool, Vector3, Quaternion)

Starts playing a pre-recorded movement by file name.

public virtual bool StartPlayback(string recordName, bool autoUnload = true, Vector3 point = default, Quaternion rotation = default)

Parameters

recordName string

The path to the record file (relative to scriptfiles).

autoUnload bool

If true, the record is unloaded when playback ends.

point Vector3

The starting position for playback (zero vector for current position).

rotation Quaternion

The starting rotation for playback.

Returns

bool

StopAim()

Stops this NPC from aiming.

public virtual void StopAim()

StopMeleeAttack()

Stops the current melee attack.

public virtual void StopMeleeAttack()

StopMoving()

Stops any active movement command for this NPC.

public virtual void StopMoving()

StopPath()

Stops path-based movement entirely.

public virtual void StopPath()

StopPlayback()

Stops the current playback.

public virtual void StopPlayback()

StopPlayingNode()

Stops node-based movement.

public virtual void StopPlayingNode()

ToString()

public override string ToString()

Returns

string

UpdateNodePoint(ushort)

Updates the current node point to the specified point ID.

public virtual bool UpdateNodePoint(ushort pointId)

Parameters

pointId ushort

Returns

bool

Operators

implicit operator INPC(Npc?)

Performs an implicit conversion from Npc to INPC.

public static implicit operator INPC(Npc? npc)

Parameters

npc Npc

Returns

INPC