Class Npc
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
npcsINPCComponentnpcINPC
Properties
Ammo
Gets or sets the ammunition for the current weapon.
public virtual int Ammo { get; set; }
Property Value
AmmoInClip
Gets or sets the ammo count in the current weapon's clip.
public virtual int AmmoInClip { get; set; }
Property Value
Armour
Gets or sets the armor of this NPC.
public virtual float Armour { get; set; }
Property Value
CurrentPathId
Gets the ID of the path this NPC is currently following, or -1 if none.
public virtual int CurrentPathId { get; }
Property Value
CurrentPathPointIndex
Gets the index of the current waypoint within the active path.
public virtual int CurrentPathPointIndex { get; }
Property Value
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
EnteringVehicleSeat
Gets the seat index the NPC is targeting while entering a vehicle.
public virtual int EnteringVehicleSeat { get; }
Property Value
FightingStyle
Gets or sets the NPC's fighting style.
public virtual PlayerFightingStyle FightingStyle { get; set; }
Property Value
Health
Gets or sets the health of this NPC.
public virtual float Health { get; set; }
Property Value
Interior
Gets or sets the interior ID this NPC is in (server-side only).
public virtual int Interior { get; set; }
Property Value
IsAiming
Gets a value indicating whether this NPC is currently aiming.
public virtual bool IsAiming { get; }
Property Value
IsDead
Gets a value indicating whether this NPC has been killed and not yet respawned.
public virtual bool IsDead { get; }
Property Value
IsInfiniteAmmoEnabled
Gets a value indicating whether infinite ammo is enabled for this NPC.
public virtual bool IsInfiniteAmmoEnabled { get; }
Property Value
IsInvulnerable
Gets or sets a value indicating whether this NPC is invulnerable.
public virtual bool IsInvulnerable { get; set; }
Property Value
IsMeleeAttacking
Gets a value indicating whether this NPC is currently performing a melee attack.
public virtual bool IsMeleeAttacking { get; }
Property Value
IsMoving
Gets a value indicating whether this NPC is currently executing any movement command.
public virtual bool IsMoving { get; }
Property Value
IsMovingByPath
Gets a value indicating whether this NPC is currently moving along a path.
public virtual bool IsMovingByPath { get; }
Property Value
IsOmpEntityDestroyed
Gets a value indicating whether the open.mp entity counterpart has been destroyed.
protected bool IsOmpEntityDestroyed { get; }
Property Value
IsPathPaused
Gets a value indicating whether path-based movement is currently paused.
public virtual bool IsPathPaused { get; }
Property Value
IsPlaybackPaused
Gets a value indicating whether playback is currently paused.
public virtual bool IsPlaybackPaused { get; }
Property Value
IsPlayingNode
Gets a value indicating whether this NPC is currently following a node path.
public virtual bool IsPlayingNode { get; }
Property Value
IsPlayingNodePaused
Gets a value indicating whether node-based movement is currently paused.
public virtual bool IsPlayingNodePaused { get; }
Property Value
IsPlayingPlayback
Gets a value indicating whether this NPC is currently playing a recording.
public virtual bool IsPlayingPlayback { get; }
Property Value
IsReloadEnabled
Gets a value indicating whether weapon reloading is enabled for this NPC.
public virtual bool IsReloadEnabled { get; }
Property Value
IsReloading
Gets a value indicating whether this NPC is currently reloading.
public virtual bool IsReloading { get; }
Property Value
IsShooting
Gets a value indicating whether this NPC is currently shooting.
public virtual bool IsShooting { get; }
Property Value
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
Player
Gets the underlying IPlayer handle that this NPC drives.
public virtual IPlayer Player { get; }
Property Value
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
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
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
PositionMovingTo
Gets the world position this NPC is currently moving to.
public virtual Vector3 PositionMovingTo { get; }
Property Value
Rotation
Gets or sets the NPC's rotation as a quaternion.
public virtual Quaternion Rotation { get; set; }
Property Value
Skin
Sets the NPC's skin model ID.
public virtual int Skin { set; }
Property Value
SpecialAction
Gets or sets the NPC's special action.
public virtual PlayerSpecialAction SpecialAction { get; set; }
Property Value
SurfingData
Gets or sets the surfing data for this NPC.
public virtual PlayerSurfingData SurfingData { get; set; }
Property Value
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
VehicleGearState
Gets or sets the gear state for this NPC's vehicle.
public virtual int VehicleGearState { get; set; }
Property Value
VehicleHealth
Gets or sets the health of this NPC's current vehicle.
public virtual float VehicleHealth { get; set; }
Property Value
VehicleHydraThrusters
Gets or sets the hydra thruster direction for this NPC's vehicle.
public virtual int VehicleHydraThrusters { get; set; }
Property Value
VehicleSeat
Gets the seat index this NPC occupies in the current vehicle.
public virtual int VehicleSeat { get; }
Property Value
VehicleTrainSpeed
Gets or sets the train speed for this NPC's vehicle.
public virtual float VehicleTrainSpeed { get; set; }
Property Value
Velocity
Gets the velocity of this NPC as a Vector3.
public virtual Vector3 Velocity { get; }
Property Value
VirtualWorld
Gets or sets the virtual world this NPC is in.
public virtual int VirtualWorld { get; set; }
Property Value
Weapon
Gets or sets the current weapon ID.
public virtual byte Weapon { get; set; }
Property Value
WeaponState
Gets or sets the NPC's current weapon state.
public virtual PlayerWeaponState WeaponState { get; set; }
Property Value
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
pointVector3shootboolshootDelayintsetAnglebooloffsetFromVector3betweenCheckFlagsEntityCheckType
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
playerPlayershootboolshootDelayintsetAnglebooloffsetVector3offsetFromVector3betweenCheckFlagsEntityCheckType
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
librarystringThe animation library.
namestringThe animation name.
fDeltafloatThe speed to play the animation.
loopboolA value indicating whether the animation should loop.
lockXboolA value indicating whether to lock the NPC's x-coordinate during the animation.
lockYboolA value indicating whether to lock the NPC's y-coordinate during the animation.
freezeboolA value indicating whether to freeze the NPC at the end of the animation.
timeTimeSpanThe 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
Returns
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
enablebool
EnableReloading(bool)
Enables or disables weapon reloading for this NPC.
public virtual void EnableReloading(bool toggle)
Parameters
togglebool
EnterVehicle(IVehicle, byte, NPCMoveType)
Instructs this NPC to enter a vehicle.
public virtual void EnterVehicle(IVehicle vehicle, byte seatId, NPCMoveType moveType)
Parameters
vehicleIVehicleseatIdbytemoveTypeNPCMoveType
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
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
GetWeaponAccuracy(byte)
Gets the accuracy of this NPC for the specified weapon.
public virtual float GetWeaponAccuracy(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponActualClipSize(byte)
Gets the actual clip size accounting for skill level and infinite ammo.
public virtual int GetWeaponActualClipSize(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponActualReloadTime(byte)
Gets the actual reload time accounting for skill level and dual wield.
public virtual int GetWeaponActualReloadTime(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponClipSize(byte)
Gets the clip size for the specified weapon.
public virtual int GetWeaponClipSize(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponReloadTime(byte)
Gets the reload time (in milliseconds) for the specified weapon.
public virtual int GetWeaponReloadTime(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponShootTime(byte)
Gets the shoot time (in milliseconds) for the specified weapon.
public virtual int GetWeaponShootTime(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponSkillLevel(PlayerWeaponSkill)
Gets the weapon skill level for the specified weapon skill.
public virtual int GetWeaponSkillLevel(PlayerWeaponSkill weaponSkill)
Parameters
weaponSkillPlayerWeaponSkill
Returns
IsAimingAtPlayer(Player)
Gets a value indicating whether this NPC is currently aiming at the specified player.
public virtual bool IsAimingAtPlayer(Player player)
Parameters
playerPlayer
Returns
IsMovingToPlayer(Player)
Gets a value indicating whether this NPC is currently moving towards the specified player.
public virtual bool IsMovingToPlayer(Player player)
Parameters
playerPlayer
Returns
IsStreamedIn(Player)
Determines whether this NPC is streamed in for the specified player.
public virtual bool IsStreamedIn(Player player)
Parameters
playerPlayerThe player to check.
Returns
Kill(Player?, byte)
Simulates this NPC's death.
public virtual void Kill(Player? killer, byte weapon)
Parameters
killerPlayerThe player who killed the NPC, or null for no killer.
weaponbyteThe 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
timeintDuration of the attack in milliseconds.
secondaryMeleeAttackboolIf 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
pathIdintmoveTypeNPCMoveTypemoveSpeedfloatreversebool
Returns
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
positionVector3The position to move to.
moveTypeNPCMoveTypeThe movement type (walk, jog, sprint, or drive).
moveSpeedfloatThe speed to move at (-1 for default speed).
stopRangefloatThe distance within which the NPC stops moving.
Returns
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
playerPlayerThe player to follow.
moveTypeNPCMoveTypeThe movement type.
moveSpeedfloatThe speed to move at (-1 for default speed).
stopRangefloatThe distance within which the NPC stops following.
posCheckUpdateDelayTimeSpanHow often the NPC recalculates the target's position.
autoRestartboolIf true, the NPC restarts following after reaching the player.
Returns
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
pausedbool
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
nodeIdintmoveTypeNPCMoveTypemoveSpeedfloatradiusfloatsetAnglebool
Returns
PutInVehicle(IVehicle, byte)
Teleports this NPC directly into a vehicle seat.
public virtual bool PutInVehicle(IVehicle vehicle, byte seat)
Parameters
Returns
RemoveFromVehicle()
Removes this NPC from its current vehicle.
public virtual bool RemoveFromVehicle()
Returns
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
SetKeys(ushort, ushort, ushort)
Sets the NPC's movement keys.
public virtual void SetKeys(ushort upAndDown, ushort leftAndRight, ushort keys)
Parameters
SetPosition(Vector3, bool)
Sets the position of this NPC.
public virtual void SetPosition(Vector3 position, bool immediateUpdate)
Parameters
positionVector3The Vector3 position to set.
immediateUpdateboolA 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
rotationQuaternionThe rotation to set.
immediateUpdateboolA 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
SetWeaponAccuracy(byte, float)
Sets the accuracy of this NPC for the specified weapon.
public virtual void SetWeaponAccuracy(byte weapon, float accuracy)
Parameters
SetWeaponClipSize(byte, int)
Sets the clip size for the specified weapon.
public virtual void SetWeaponClipSize(byte weapon, int size)
Parameters
SetWeaponReloadTime(byte, int)
Sets the reload time (in milliseconds) for the specified weapon.
public virtual void SetWeaponReloadTime(byte weapon, int time)
Parameters
SetWeaponShootTime(byte, int)
Sets the shoot time (in milliseconds) for the specified weapon.
public virtual void SetWeaponShootTime(byte weapon, int time)
Parameters
SetWeaponSkillLevel(PlayerWeaponSkill, int)
Sets the weapon skill level for the specified weapon skill.
public virtual void SetWeaponSkillLevel(PlayerWeaponSkill weaponSkill, int level)
Parameters
weaponSkillPlayerWeaponSkilllevelint
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
hitIdinthitTypePlayerBulletHitTypeweaponbyteendPointVector3offsetVector3isHitboolbetweenCheckFlagsEntityCheckType
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
recordIdintThe record ID returned by LoadRecord(string).
autoUnloadboolIf true, the record is unloaded when playback ends.
pointVector3The starting position for playback (zero vector for current position).
rotationQuaternionThe starting rotation for playback.
Returns
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
recordNamestringThe path to the record file (relative to scriptfiles).
autoUnloadboolIf true, the record is unloaded when playback ends.
pointVector3The starting position for playback (zero vector for current position).
rotationQuaternionThe starting rotation for playback.
Returns
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
UpdateNodePoint(ushort)
Updates the current node point to the specified point ID.
public virtual bool UpdateNodePoint(ushort pointId)
Parameters
pointIdushort
Returns
Operators
implicit operator INPC(Npc?)
public static implicit operator INPC(Npc? npc)
Parameters
npcNpc