Struct INPC
This type represents a pointer to an unmanaged open.mp INPC interface (a server-controlled bot built on top of an IPlayer).
[OpenMpApi(new Type[] { typeof(IExtensible), typeof(IIDProvider) })]
public readonly struct INPC : IEquatable<INPC>, INPC.IManagedInterface, IExtensible.IManagedInterface, IIDProvider.IManagedInterface, IUnmanagedInterface
- Implements
- Inherited Members
Constructors
INPC(nint)
Initializes a new instance of the INPC struct.
public INPC(nint handle)
Parameters
handlenintA pointer to the unmanaged interface.
Properties
Handle
Gets the handle to the unmanaged interface instance.
public nint Handle { get; }
Property Value
HasValue
Gets a value indicating whether the pointer has a value.
public bool HasValue { get; }
Property Value
Methods
AddExtension<T>(T)
Adds the specified managed extension to this extensible.
public void AddExtension<T>(T extension) where T : Extension
Parameters
extensionTAn instance of the extension to add. The extension will be disposed if the extension could not be added to this extensible.
Type Parameters
TThe type of the managed extension.
Remarks
A managed extension can only be added to one extensible.
Exceptions
- ArgumentException
Throw when an instance of the extension type was already added to this extensible.
AimAt(Vector3, bool, int, bool, Vector3, EntityCheckType)
Instructs the NPC to aim at a world position.
public void AimAt(Vector3 point, bool shoot, int shootDelay, bool setAngle, Vector3 offsetFrom, EntityCheckType betweenCheckFlags)
Parameters
pointVector3shootboolshootDelayintsetAnglebooloffsetFromVector3betweenCheckFlagsEntityCheckType
AimAtPlayer(IPlayer, bool, int, bool, Vector3, Vector3, EntityCheckType)
Instructs the NPC to aim at a specific player.
public void AimAtPlayer(IPlayer atPlayer, bool shoot, int shootDelay, bool setAngle, Vector3 offset, Vector3 offsetFrom, EntityCheckType betweenCheckFlags)
Parameters
atPlayerIPlayershootboolshootDelayintsetAnglebooloffsetVector3offsetFromVector3betweenCheckFlagsEntityCheckType
ApplyAnimation(AnimationData)
Applies an animation. animationData bundles lib + name + flags + duration.
public void ApplyAnimation(AnimationData animationData)
Parameters
animationDataAnimationData
ChangeNode(int, ushort)
Changes the active node and seeks to a specific target point.
public ushort ChangeNode(int nodeId, ushort targetPointId)
Parameters
Returns
ClearAnimations()
Clears any applied animation.
public void ClearAnimations()
EnableInfiniteAmmo(bool)
Enables or disables infinite ammo for the NPC.
public void EnableInfiniteAmmo(bool enable)
Parameters
enablebool
EnableReloading(bool)
Enables or disables weapon reloading for the NPC.
public void EnableReloading(bool toggle)
Parameters
togglebool
EnterVehicle(IVehicle, byte, NPCMoveType)
Instructs the NPC to enter a vehicle.
public void EnterVehicle(IVehicle vehicle, byte seatId, NPCMoveType moveType)
Parameters
vehicleIVehicleseatIdbytemoveTypeNPCMoveType
Equals(INPC)
public bool Equals(INPC other)
Parameters
otherINPC
Returns
Equals(object?)
public override bool Equals(object? other)
Parameters
otherobject
Returns
ExitVehicle()
Instructs the NPC to exit the current vehicle.
public void ExitVehicle()
GetAmmo()
Gets ammo for the current weapon.
public int GetAmmo()
Returns
GetAmmoInClip()
Gets the ammo count in the current weapon's clip.
public int GetAmmoInClip()
Returns
GetAnimation(out int, out float, out bool, out bool, out bool, out bool, out int)
Gets the current foot-sync animation parameters for the NPC.
public void GetAnimation(out int animationId, out float delta, out bool loop, out bool lockX, out bool lockY, out bool freeze, out int time)
Parameters
GetArmour()
Gets the NPC's armour.
public float GetArmour()
Returns
GetCurrentPathId()
Gets the ID of the path the NPC is currently following, or -1 if none.
public int GetCurrentPathId()
Returns
GetCurrentPathPointIndex()
Gets the index of the current waypoint within the active path.
public int GetCurrentPathPointIndex()
Returns
GetEnteringVehicle()
Gets the vehicle the NPC is in the process of entering, or a handle with no value if not entering one.
public IVehicle GetEnteringVehicle()
Returns
GetEnteringVehicleSeat()
Gets the seat index the NPC is targeting while entering a vehicle.
public int GetEnteringVehicleSeat()
Returns
GetExtension(UID)
Gets the extension with the specified id.
public IExtension GetExtension(UID id)
Parameters
idUIDThe identifier of the extension type.
Returns
- IExtension
The extension or null if the extension could not be found.
GetExtension<T>()
Gets the specified managed extension from this extensible.
public T GetExtension<T>() where T : Extension
Returns
- T
An instance of the extension with type
T.
Type Parameters
TThe type of the managed extension.
Exceptions
- ArgumentException
Thrown if the extension could not be found.
GetFightingStyle()
Gets the NPC's current fighting style.
public PlayerFightingStyle GetFightingStyle()
Returns
GetHashCode()
public override int GetHashCode()
Returns
GetHealth()
Gets the NPC's health.
public float GetHealth()
Returns
GetID()
Gets the identifier of this unit.
public int GetID()
Returns
- int
The identifier of the unit.
GetInterior()
Gets the interior id this NPC is recorded in (server-side bookkeeping only).
public uint GetInterior()
Returns
GetKeys(out ushort, out ushort, out ushort)
Gets the NPC's current movement keys.
public void GetKeys(out ushort upAndDown, out ushort leftAndRight, out ushort keys)
Parameters
GetPlayer()
Gets the underlying IPlayer instance for this NPC.
public IPlayer GetPlayer()
Returns
GetPlayerAimingAt()
Gets the player the NPC is currently aiming at, or a handle with no value if not aiming at any player.
public IPlayer GetPlayerAimingAt()
Returns
GetPlayerMovingTo()
Gets the player the NPC is currently moving towards, or a handle with no value if not following a player.
public IPlayer GetPlayerMovingTo()
Returns
GetPosition()
Gets the NPC's world position.
public Vector3 GetPosition()
Returns
GetPositionMovingTo()
Gets the world position the NPC is currently moving to.
public Vector3 GetPositionMovingTo()
Returns
GetRotation()
Gets the NPC's rotation as a quaternion.
public GTAQuat GetRotation()
Returns
GetSpecialAction()
Gets the current special action for the NPC.
public PlayerSpecialAction GetSpecialAction()
Returns
GetSurfingData()
Gets the current surfing data for the NPC.
public PlayerSurfingData GetSurfingData()
Returns
GetVehicle()
Gets the vehicle this NPC is currently in, or a handle with no value if not in a vehicle.
public IVehicle GetVehicle()
Returns
GetVehicleGearState()
Gets the gear state for the NPC's vehicle.
public int GetVehicleGearState()
Returns
GetVehicleHealth()
Gets the health of the NPC's current vehicle.
public float GetVehicleHealth()
Returns
GetVehicleHydraThrusters()
Gets the hydra thruster direction for the NPC's vehicle.
public int GetVehicleHydraThrusters()
Returns
GetVehicleSeat()
Gets the seat index this NPC occupies in the current vehicle.
public int GetVehicleSeat()
Returns
GetVehicleTrainSpeed()
Gets the train speed for the NPC's vehicle.
public float GetVehicleTrainSpeed()
Returns
GetVelocity()
Gets the current velocity vector.
public Vector3 GetVelocity()
Returns
GetVirtualWorld()
Gets the virtual world this NPC is in.
public int GetVirtualWorld()
Returns
GetWeapon()
Gets the current weapon id.
public byte GetWeapon()
Returns
GetWeaponAccuracy(byte)
Gets the accuracy of the NPC for the specified weapon.
public float GetWeaponAccuracy(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponActualClipSize(byte)
Gets the actual clip size accounting for skill level and infinite ammo.
public int GetWeaponActualClipSize(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponActualReloadTime(byte)
Gets the actual reload time accounting for skill level and dual wield.
public int GetWeaponActualReloadTime(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponClipSize(byte)
Gets the clip size for the specified weapon.
public int GetWeaponClipSize(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponReloadTime(byte)
Gets the reload time (in milliseconds) for the specified weapon.
public int GetWeaponReloadTime(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponShootTime(byte)
Gets the shoot time (in milliseconds) for the specified weapon.
public int GetWeaponShootTime(byte weapon)
Parameters
weaponbyte
Returns
GetWeaponSkillLevel(PlayerWeaponSkill)
Gets the weapon skill level for the specified weapon skill.
public int GetWeaponSkillLevel(PlayerWeaponSkill weaponSkill)
Parameters
weaponSkillPlayerWeaponSkill
Returns
GetWeaponState()
Gets the NPC's current weapon state.
public PlayerWeaponState GetWeaponState()
Returns
IsAiming()
Gets a value indicating whether the NPC is currently aiming.
public bool IsAiming()
Returns
IsAimingAtPlayer(IPlayer)
Gets a value indicating whether the NPC is currently aiming at the specified player.
public bool IsAimingAtPlayer(IPlayer player)
Parameters
playerIPlayer
Returns
IsDead()
True if the NPC has been killed and not yet respawned.
public bool IsDead()
Returns
IsInfiniteAmmoEnabled()
Gets a value indicating whether infinite ammo is enabled for the NPC.
public bool IsInfiniteAmmoEnabled()
Returns
IsInvulnerable()
True iff the NPC is invulnerable.
public bool IsInvulnerable()
Returns
IsMeleeAttacking()
Gets a value indicating whether the NPC is currently performing a melee attack.
public bool IsMeleeAttacking()
Returns
IsMoving()
True if the NPC is currently moving (path or direct).
public bool IsMoving()
Returns
IsMovingByPath()
Gets a value indicating whether the NPC is currently moving along a path.
public bool IsMovingByPath()
Returns
IsMovingToPlayer(IPlayer)
Gets a value indicating whether the NPC is currently moving towards the specified player.
public bool IsMovingToPlayer(IPlayer player)
Parameters
playerIPlayer
Returns
IsPathPaused()
Gets a value indicating whether the NPC's path movement is currently paused.
public bool IsPathPaused()
Returns
IsPlaybackPaused()
Gets a value indicating whether playback is currently paused.
public bool IsPlaybackPaused()
Returns
IsPlayingNode()
Gets a value indicating whether the NPC is currently following a node path.
public bool IsPlayingNode()
Returns
IsPlayingNodePaused()
Gets a value indicating whether node-based movement is currently paused.
public bool IsPlayingNodePaused()
Returns
IsPlayingPlayback()
Gets a value indicating whether the NPC is currently playing a recording.
public bool IsPlayingPlayback()
Returns
IsReloadEnabled()
Gets a value indicating whether weapon reloading is enabled for the NPC.
public bool IsReloadEnabled()
Returns
IsReloading()
Gets a value indicating whether the NPC is currently reloading its weapon.
public bool IsReloading()
Returns
IsShooting()
Gets a value indicating whether the NPC is currently shooting.
public bool IsShooting()
Returns
IsStreamedInForPlayer(IPlayer)
Checks whether this NPC is streamed in for the given player.
public bool IsStreamedInForPlayer(IPlayer other)
Parameters
otherIPlayer
Returns
IsVehicleSirenUsed()
Gets a value indicating whether the NPC's vehicle siren is currently active.
public bool IsVehicleSirenUsed()
Returns
Kill(IPlayer, byte)
Simulates NPC death, optionally with a killer and weapon.
public void Kill(IPlayer killer, byte weapon)
Parameters
MeleeAttack(int, bool)
Starts a melee attack for the specified duration.
public void MeleeAttack(int time, bool secondaryMeleeAttack)
Parameters
timeintDuration of the attack in milliseconds.
secondaryMeleeAttackboolIf true, performs the secondary melee attack.
Move(Vector3, NPCMoveType, float, float)
Tells the NPC to walk/jog/sprint/drive to position.
public bool Move(Vector3 position, NPCMoveType moveType, float moveSpeed, float stopRange)
Parameters
positionVector3moveTypeNPCMoveTypemoveSpeedfloatstopRangefloat
Returns
MoveByPath(int, NPCMoveType, float, bool)
Instructs the NPC to move along a previously created path.
public bool MoveByPath(int pathId, NPCMoveType moveType, float moveSpeed, bool reverse)
Parameters
pathIdintmoveTypeNPCMoveTypemoveSpeedfloatreversebool
Returns
MoveToPlayer(IPlayer, NPCMoveType, float, float, Milliseconds, bool)
Tells the NPC to continuously follow targetPlayer using the specified movement type.
public bool MoveToPlayer(IPlayer targetPlayer, NPCMoveType moveType, float moveSpeed, float stopRange, Milliseconds posCheckUpdateDelay, bool autoRestart)
Parameters
targetPlayerIPlayerThe player to follow.
moveTypeNPCMoveTypeThe movement type (walk, jog, sprint, etc.).
moveSpeedfloatThe movement speed (-1 for automatic).
stopRangefloatThe radius within which the NPC stops following.
posCheckUpdateDelayMillisecondsHow often (in milliseconds) the NPC recalculates the target's position.
autoRestartboolIf true, the NPC will restart following after reaching the player.
Returns
PausePath()
Pauses path-based movement temporarily.
public void PausePath()
PausePlayback(bool)
Pauses or resumes the current playback.
public void PausePlayback(bool paused)
Parameters
pausedbool
PausePlayingNode()
Pauses node-based movement.
public void PausePlayingNode()
PlayNode(int, NPCMoveType, float, float, bool)
Starts node-based movement for the NPC.
public bool PlayNode(int nodeId, NPCMoveType moveType, float moveSpeed, float radius, bool setAngle)
Parameters
nodeIdintmoveTypeNPCMoveTypemoveSpeedfloatradiusfloatsetAnglebool
Returns
PutInVehicle(IVehicle, byte)
Teleports the NPC directly into a vehicle seat.
public bool PutInVehicle(IVehicle vehicle, byte seat)
Parameters
Returns
QueryExtension<T>()
Gets the specified unmanaged extension from this extensible.
public T QueryExtension<T>() where T : unmanaged, IExtension.IManagedInterface
Returns
- T
The unmanaged extension or null if the extension could not be found.
Type Parameters
TThe type of the unmanaged extension.
RemoveExtension(IExtension)
Removes the specified extension from this extensible.
public void RemoveExtension(IExtension extension)
Parameters
extensionIExtensionThe extension to remove.
Exceptions
- ArgumentException
Thrown if the extension could not be found.
RemoveExtension(UID)
Removes the extension with the specified id from this extensible.
public void RemoveExtension(UID id)
Parameters
idUIDThe identifier of the extension.
Exceptions
- ArgumentException
Thrown if the extension could not be found.
RemoveExtension<T>(T)
Removes the specified managed extension from this extensible.
public void RemoveExtension<T>(T extension) where T : Extension
Parameters
extensionTThe managed extension to remove.
Type Parameters
TThe type of the managed extension.
Exceptions
- ArgumentException
Thrown if the extension could not be found.
RemoveFromVehicle()
Removes the NPC from its current vehicle.
public bool RemoveFromVehicle()
Returns
ResetAnimation()
Resets the foot-sync animation for the NPC.
public void ResetAnimation()
ResetSurfingData()
Resets the NPC's surfing data.
public void ResetSurfingData()
Respawn()
Respawns the NPC keeping its current state.
public void Respawn()
ResumePath()
Resumes previously paused path-based movement.
public void ResumePath()
ResumePlayingNode()
Resumes previously paused node-based movement.
public void ResumePlayingNode()
SetAmmo(int)
Sets ammo for the current weapon.
public void SetAmmo(int ammo)
Parameters
ammoint
SetAmmoInClip(int)
Sets the ammo count in the current weapon's clip.
public void SetAmmoInClip(int ammo)
Parameters
ammoint
SetAnimation(int, float, bool, bool, bool, bool, int)
Sets the foot-sync animation for the NPC.
public void SetAnimation(int animationId, float delta, bool loop, bool lockX, bool lockY, bool freeze, int time)
Parameters
SetArmour(float)
Sets the NPC's armour.
public void SetArmour(float armour)
Parameters
armourfloat
SetFightingStyle(PlayerFightingStyle)
Sets the NPC's fighting style.
public void SetFightingStyle(PlayerFightingStyle style)
Parameters
stylePlayerFightingStyle
SetHealth(float)
Sets the NPC's health.
public void SetHealth(float health)
Parameters
healthfloat
SetInterior(uint)
Sets the interior id (server-side bookkeeping only — does not relocate the NPC).
public void SetInterior(uint interior)
Parameters
interioruint
SetInvulnerable(bool)
Sets invulnerability.
public void SetInvulnerable(bool toggle)
Parameters
togglebool
SetKeys(ushort, ushort, ushort)
Sets the NPC's movement keys.
public void SetKeys(ushort upAndDown, ushort leftAndRight, ushort keys)
Parameters
SetPosition(Vector3, bool)
Sets the NPC's position. immediateUpdate=true broadcasts a sync
to streamed-in players right away instead of waiting for the next tick.
public void SetPosition(Vector3 position, bool immediateUpdate)
Parameters
SetRotation(GTAQuat, bool)
Sets the NPC's rotation. See SetPosition(Vector3, bool) for the immediate-update flag.
public void SetRotation(GTAQuat rotation, bool immediateUpdate)
Parameters
SetSkin(int)
Sets the NPC's skin model id.
public void SetSkin(int model)
Parameters
modelint
SetSpecialAction(PlayerSpecialAction)
Sets the special action for the NPC.
public void SetSpecialAction(PlayerSpecialAction action)
Parameters
actionPlayerSpecialAction
SetSurfingData(PlayerSurfingData)
Sets the surfing data for the NPC.
public void SetSurfingData(PlayerSurfingData data)
Parameters
dataPlayerSurfingData
SetVehicleGearState(int)
Sets the gear state for the NPC's vehicle.
public void SetVehicleGearState(int gear)
Parameters
gearint
SetVehicleHealth(float)
Sets the health of the NPC's current vehicle.
public void SetVehicleHealth(float health)
Parameters
healthfloat
SetVehicleHydraThrusters(int)
Sets the hydra thruster direction for the NPC's vehicle.
public void SetVehicleHydraThrusters(int direction)
Parameters
directionint
SetVehicleTrainSpeed(float)
Sets the train speed for the NPC's vehicle.
public void SetVehicleTrainSpeed(float speed)
Parameters
speedfloat
SetVelocity(Vector3, bool)
Sets the velocity vector. update=true forces a sync this tick.
public void SetVelocity(Vector3 velocity, bool update)
Parameters
SetVirtualWorld(int)
Sets the virtual world this NPC is in.
public void SetVirtualWorld(int vw)
Parameters
vwint
SetWeapon(byte)
Sets the current weapon id.
public void SetWeapon(byte weapon)
Parameters
weaponbyte
SetWeaponAccuracy(byte, float)
Sets the accuracy of the NPC for the specified weapon.
public void SetWeaponAccuracy(byte weapon, float accuracy)
Parameters
SetWeaponClipSize(byte, int)
Sets the clip size for the specified weapon.
public void SetWeaponClipSize(byte weapon, int size)
Parameters
SetWeaponReloadTime(byte, int)
Sets the reload time (in milliseconds) for the specified weapon.
public void SetWeaponReloadTime(byte weapon, int time)
Parameters
SetWeaponShootTime(byte, int)
Sets the shoot time (in milliseconds) for the specified weapon.
public void SetWeaponShootTime(byte weapon, int time)
Parameters
SetWeaponSkillLevel(PlayerWeaponSkill, int)
Sets the weapon skill level for the specified weapon skill.
public void SetWeaponSkillLevel(PlayerWeaponSkill weaponSkill, int level)
Parameters
weaponSkillPlayerWeaponSkilllevelint
SetWeaponState(PlayerWeaponState)
Sets the NPC's weapon state.
public void SetWeaponState(PlayerWeaponState state)
Parameters
statePlayerWeaponState
Shoot(int, PlayerBulletHitType, byte, Vector3, Vector3, bool, EntityCheckType)
Triggers a weapon shot from the NPC.
public void Shoot(int hitId, PlayerBulletHitType hitType, byte weapon, Vector3 endPoint, Vector3 offset, bool isHit, EntityCheckType betweenCheckFlags)
Parameters
hitIdinthitTypePlayerBulletHitTypeweaponbyteendPointVector3offsetVector3isHitboolbetweenCheckFlagsEntityCheckType
Spawn()
Spawns the NPC at its currently configured position/rotation.
public void Spawn()
StartPlaybackById(int, bool, Vector3, GTAQuat)
Starts playing a pre-loaded recording by its record ID.
public bool StartPlaybackById(int recordId, bool autoUnload, Vector3 point, GTAQuat rotation)
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).
rotationGTAQuatThe starting rotation for playback.
Returns
StartPlaybackByName(string, bool, Vector3, GTAQuat)
Starts playing a pre-recorded movement by file name.
public bool StartPlaybackByName(string recordName, bool autoUnload, Vector3 point, GTAQuat rotation)
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).
rotationGTAQuatThe starting rotation for playback.
Returns
StopAim()
Stops the NPC from aiming.
public void StopAim()
StopMeleeAttack()
Stops the current melee attack.
public void StopMeleeAttack()
StopMove()
Stops any active movement.
public void StopMove()
StopPath()
Stops path-based movement entirely.
public void StopPath()
StopPlayback()
Stops the current playback.
public void StopPlayback()
StopPlayingNode()
Stops node-based movement.
public void StopPlayingNode()
StreamedForPlayers()
Gets the set of players this NPC is currently streamed in for.
public FlatPtrHashSet<IPlayer> StreamedForPlayers()
Returns
TryGetExtension<T>()
Tries to get the specified managed extension from this extensible.
public T? TryGetExtension<T>() where T : Extension
Returns
- T
An instance of the extension with type
Tor null if no extension with the specified type could be found.
Type Parameters
TThe type of the managed extension.
TryQueryExtension<T>(out T)
Tries to get the specified unmanaged extension from this extensible.
public bool TryQueryExtension<T>(out T extension) where T : unmanaged, IExtension.IManagedInterface
Parameters
extensionTThe extension if found, otherwise null.
Returns
Type Parameters
TThe type of the unmanaged extension.
UpdateNodePoint(ushort)
Updates the current node point to the specified point ID.
public bool UpdateNodePoint(ushort pointId)
Parameters
pointIdushort
Returns
UseVehicleSiren(bool)
Enables or disables the siren on the NPC's vehicle.
public void UseVehicleSiren(bool use)
Parameters
usebool
Operators
operator ==(INPC, object?)
Determines whether the specified values are equal.
public static bool operator ==(INPC lhs, object? rhs)
Parameters
lhsINPCThe value on the left side of the operator.
rhsobjectThe value on the right side of the operator.
Returns
- bool
trueif the values are equal; otherwise,false.
explicit operator INPC(IExtensible)
Casts the IExtensible to a INPC.
public static explicit operator INPC(IExtensible value)
Parameters
valueIExtensibleThe IExtensible to cast.
Returns
explicit operator INPC(IIDProvider)
Casts the IIDProvider to a INPC.
public static explicit operator INPC(IIDProvider value)
Parameters
valueIIDProviderThe IIDProvider to cast.
Returns
explicit operator IExtensible(INPC)
Casts the INPC to a IExtensible.
public static explicit operator IExtensible(INPC value)
Parameters
Returns
- IExtensible
The converted IExtensible.
explicit operator IIDProvider(INPC)
Casts the INPC to a IIDProvider.
public static explicit operator IIDProvider(INPC value)
Parameters
Returns
- IIDProvider
The converted IIDProvider.
operator !=(INPC, object?)
Determines whether the specified values are not equal.
public static bool operator !=(INPC lhs, object? rhs)
Parameters
lhsINPCThe value on the left side of the operator.
rhsobjectThe value on the right side of the operator.
Returns
- bool
trueif the values are not equal; otherwise,false.